Add pluggable analytics framework
This commit is contained in:
parent
0cda79352f
commit
92a6b765a2
10
analytics.js
10
analytics.js
|
@ -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));
|
|
@ -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();
|
Loading…
Reference in New Issue