Last active
March 1, 2016 21:32
-
-
Save jacopotarantino/67897a3a9cee777650b8 to your computer and use it in GitHub Desktop.
ES6 analytics.js mock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global => { | |
'use strict' | |
// if analytics is already defined, we probably don't need this. | |
if (global.analytics) { return } | |
class Analytics { | |
/** | |
* Creates a new instance of the analytics service. | |
*/ | |
constructor () {} | |
/** | |
* Iterates over available trackers on the page and translates the tracking event for each one. | |
*/ | |
track (event_name, properties) { | |
if (global._gaq) { | |
let args = Object.keys(properties).map(key => `${ key }=${ properties[key] }`) | |
global._gaq.push(['_trackEvent', event_name, ...args]) | |
} | |
if (global.ga) { | |
// handle new GA logic... | |
} | |
} | |
} | |
global.analytics = new Analytics() | |
})(window) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment