diff --git a/src/discovery.config.js b/src/discovery.config.js index afd1137a5..fbecc5d85 100644 --- a/src/discovery.config.js +++ b/src/discovery.config.js @@ -429,14 +429,12 @@ require.config({ callback: function() { - window._GA = '__ga__'; + window.GoogleAnalyticsObject = '__ga__'; require(['discovery.vars', 'google-analytics', 'analytics'], function(config) { - - window[window._GA].q = [ - ['create', config.googleTrackingCode || '', config.googleTrackingOptions || 'auto'] - ]; - window[window._GA].l = Date.now(); + var qa = window[window.GoogleAnalyticsObject]; + qa.l = Date.now(); + qa('create', config.googleTrackingCode || '', config.googleTrackingOptions); }); require([ diff --git a/src/js/components/analytics.js b/src/js/components/analytics.js index 22c9e1071..63cad81d6 100644 --- a/src/js/components/analytics.js +++ b/src/js/components/analytics.js @@ -54,17 +54,20 @@ define([ } }; - window[window._GA] = function () { - var ga = window[window._GA]; - (ga.q = ga.q || []).push(arguments); - if (ga.q.length > 100) { - ga.q = ga.q.slice(0, 50); + var ga = window[window.GoogleAnalyticsObject]; + window[window.GoogleAnalyticsObject] = function () { + try { + ga.q = ga.q || []; + ga.q.push([arguments]); + ga.apply(ga, arguments); + } catch (e) { + console.info('google analytics event not tracked'); } }; var Analytics = function () { adsLogger.apply(null, _.rest(arguments, 3)); - window[window._GA].apply(this, arguments); + window[window.GoogleAnalyticsObject].apply(this, arguments); }; return Analytics;