Skip to content

Commit

Permalink
Merge pull request #1585 from thostetler/fix-analytics-finally
Browse files Browse the repository at this point in the history
fix google analytics for good
  • Loading branch information
thostetler authored Aug 31, 2018
2 parents 226481a + 110e27d commit 628ddd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/discovery.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
15 changes: 9 additions & 6 deletions src/js/components/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 628ddd7

Please sign in to comment.