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,3 +1,5 @@
(function (ctx) {
function Analytics() {
/**
* Google Analytics
*/
@ -6,3 +8,11 @@
})(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();