Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Last active March 1, 2016 21:32
Show Gist options
  • Save jacopotarantino/67897a3a9cee777650b8 to your computer and use it in GitHub Desktop.
Save jacopotarantino/67897a3a9cee777650b8 to your computer and use it in GitHub Desktop.
ES6 analytics.js mock.
(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