Don’t block anything else to send google analytics

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 <cdiffrient@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2019-09-09 00:01:29 -06:00
parent 88b3e9ab47
commit fb53feb062
1 changed files with 5 additions and 1 deletions

View File

@ -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,