Skip to content

Instantly share code, notes, and snippets.

@ethangardner
Last active July 1, 2018 15:08
Show Gist options
  • Save ethangardner/7879053f84162abee851 to your computer and use it in GitHub Desktop.
Save ethangardner/7879053f84162abee851 to your computer and use it in GitHub Desktop.
var track = {
google: {
event: function(args) {
if (typeof ga === "function") {
if (args.constructor !== [].constructor) {
new Error('This function takes an array as the argument. You passed a ' + typeof args);
}
else if( args.length < 2 || args.length > 5 ) {
new Error('This function needs an array of 2 to 5 items. You passed ' + args.length);
}
else {
args.unshift('event');
args.unshift('send');
ga.apply(this, args);
}
}
}
}
};
// track.google.event(['Video', 'play', 'Fall Campaign']);
// will call ga('send', 'event', 'Video', 'play', 'Fall Campaign');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment