Add pluggable analytics framework
This commit is contained in:
parent
0cda79352f
commit
92a6b765a2
14
analytics.js
14
analytics.js
|
@ -1,8 +1,18 @@
|
||||||
/**
|
(function (ctx) {
|
||||||
|
function Analytics() {
|
||||||
|
/**
|
||||||
* Google Analytics
|
* Google Analytics
|
||||||
*/
|
*/
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(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)
|
(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');
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||||
ga('create', 'UA-319188-14', 'jit.si');
|
ga('create', 'UA-319188-14', 'jit.si');
|
||||||
ga('send', 'pageview');
|
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