Skip to content

Instantly share code, notes, and snippets.

@MaksimAbramchuk
Created June 27, 2017 06:55
Show Gist options
  • Save MaksimAbramchuk/e0de6350c319d1f74bae910a322c1a62 to your computer and use it in GitHub Desktop.
Save MaksimAbramchuk/e0de6350c319d1f74bae910a322c1a62 to your computer and use it in GitHub Desktop.
const ua = require('universal-analytics');
const bluebird = require('bluebird');
const GOOGLE_ANALYTICS_ID = require('../../config').googleAnalytics.uid;
class GoogleAnalytics {
constructor(uid) {
this._uid = uid;
this._visitor = ua(GOOGLE_ANALYTICS_ID, this._uid, { strictCidFormat: false, });
bluebird.promisifyAll(this._visitor);
}
sendEvent(category, action, label) {
if (!this._visitor) return;
this._visitor.eventAsync(category, action, label)
.catch(error => console.error(error));
}
}
module.exports = GoogleAnalytics;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment