Add pluggable analytics framework

This commit is contained in:
Issac Gerges 2015-09-02 12:08:31 -05:00
parent 0cda79352f
commit 92a6b765a2
2 changed files with 33 additions and 8 deletions

View File

@ -1,8 +1,18 @@
/**
* Google Analytics
*/
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-319188-14', 'jit.si');
ga('send', 'pageview');
(function (ctx) {
function Analytics() {
/**
* Google Analytics
*/
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-319188-14', 'jit.si');
ga('send', 'pageview');
}
Analytics.prototype.sendEvent = function (action, data) {
ga('send', 'event', 'jit.si', action);
};
ctx.Analytics = Analytics;
}(window));

View File

@ -0,0 +1,15 @@
function NoopAnalytics() {}
NoopAnalytics.prototype.sendEvent = function () {};
function AnalyticsAdapter() {
var AnalyticsImpl = window.Analytics || NoopAnalytics;
this.analytics = new AnalyticsImpl();
}
AnalyticsAdapter.prototype.sendEvent = function (action, data) {
try {
this.analytics.sendEvent.apply(this.analytics, arguments);
} catch (ignored) {}
};
module.exports = new AnalyticsAdapter();