2015-12-20 05:32:57 +01:00
|
|
|
//
|
|
|
|
// Google Analytics
|
|
|
|
//
|
|
|
|
var GoogleAnalytics = (function(w,d) {
|
|
|
|
|
|
|
|
var app, _private;
|
|
|
|
|
|
|
|
_private = {
|
|
|
|
//
|
|
|
|
// Custom Events
|
|
|
|
// https://developers.google.com/analytics/devguides/collection/analyticsjs/events
|
|
|
|
//
|
|
|
|
gaEvents: function() {
|
|
|
|
// jQuery('.js-tracking-').on('click', function() {
|
|
|
|
// ga('send', 'event', [eventCategory], [eventAction], [eventLabel]);
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Track Responsive Breakpoints
|
|
|
|
//
|
|
|
|
// stolen & adapted from
|
|
|
|
// http://philipwalton.com/articles/measuring-your-sites-responsive-breakpoint-usage/
|
|
|
|
//
|
|
|
|
gaBreakpoints: function() {
|
|
|
|
// Do nothing in browsers that don't support `window.matchMedia`.
|
|
|
|
if (!window.matchMedia) return;
|
|
|
|
|
|
|
|
// Prevent rapid breakpoint changes for all firing at once.
|
|
|
|
var timeout;
|
|
|
|
|
|
|
|
var breakpoints = {
|
2015-12-21 14:48:45 +01:00
|
|
|
xs: '(max-width: 34.999em)',
|
|
|
|
sm: '(min-width: 35em) and (max-width: 44.999)',
|
|
|
|
md: '(min-width: 45em) and (max-width: 74.999)',
|
|
|
|
lg: '(min-width: 75em)'
|
2015-12-20 05:32:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(breakpoints).forEach(function(breakpoint) {
|
|
|
|
var mql = window.matchMedia(breakpoints[breakpoint]);
|
|
|
|
|
|
|
|
// Set the initial breakpoint on page load.
|
|
|
|
if (mql.matches) {
|
|
|
|
ga('set', 'dimension1', breakpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the breakpoint as the matched media changes
|
|
|
|
mql.addListener(function() {
|
|
|
|
if (mql.matches) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(function() {
|
|
|
|
ga('set', 'dimension1', breakpoint);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Track Viewport
|
|
|
|
//
|
|
|
|
gaViewport: function() {
|
|
|
|
var width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
|
|
|
|
var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
|
|
|
|
var dimensions = width + 'x' + height;
|
|
|
|
|
|
|
|
ga('set', 'dimension2', dimensions);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Track Pixel Density
|
|
|
|
//
|
|
|
|
gaPixelDensity: function() {
|
|
|
|
// Heads up!
|
|
|
|
// window.devicePixelRatio doesn't work correctly in IE but whatever
|
|
|
|
var pixeldensity = window.devicePixelRatio;
|
|
|
|
|
|
|
|
ga('set', 'dimension3', pixeldensity);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
app = {
|
|
|
|
init: function() {
|
|
|
|
_private.gaEvents();
|
|
|
|
_private.gaBreakpoints();
|
|
|
|
_private.gaViewport();
|
|
|
|
_private.gaPixelDensity();
|
2015-12-21 14:08:20 +01:00
|
|
|
},
|
|
|
|
gaEventEarlyAccessSuccess: function() {
|
2015-12-22 16:50:35 +01:00
|
|
|
ga('send', 'event', 'signup', 'early_access_form', 'success');
|
2015-12-21 14:08:20 +01:00
|
|
|
},
|
|
|
|
gaEventEarlyAccessError: function() {
|
2015-12-22 16:50:35 +01:00
|
|
|
ga('send', 'event', 'signup', 'early_access_form', 'error');
|
2015-12-20 05:32:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
|
|
|
})(window, document);
|