From fb53feb062ecc6ee056824612bbd9bc2790d7312 Mon Sep 17 00:00:00 2001 From: Ryan Shaw Date: Mon, 9 Sep 2019 00:01:29 -0600 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20block=20anything=20else=20to=20?= =?UTF-8?q?send=20google=20analytics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from profiling, it looks like when we call trackEvent, google analytics Executes synchronously in the middle of all our other javascript and Blocks it for a few ms while it does its thing see: https://cl.ly/a94a028037d2 This will make it so it waits until we are done before letting GA run Change-Id: Iff7275c1428c7ebcec04ccc1d4d46f56131c9b79 Reviewed-on: https://gerrit.instructure.com/208616 Tested-by: Jenkins Reviewed-by: Clay Diffrient QA-Review: Ryan Shaw Product-Review: Ryan Shaw --- public/javascripts/jquery.google-analytics.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/javascripts/jquery.google-analytics.js b/public/javascripts/jquery.google-analytics.js index aea8f59850f..b132eac6b40 100644 --- a/public/javascripts/jquery.google-analytics.js +++ b/public/javascripts/jquery.google-analytics.js @@ -31,7 +31,11 @@ import $ from 'jquery' * see: https://developers.google.com/analytics/devguides/collection/analyticsjs/events */ export function trackEvent(category, action, label, value) { - if (window.ga) window.ga('send', 'event', category, action, label, value) + if (window.ga) { + (window.requestIdleCallback || window.setTimeout)(() => { // don't ever block anything else going on + window.ga('send', 'event', category, action, label, value) + }) + } } // we put it on the jQuery object just for backwards compatibility,