Skip to content

Instantly share code, notes, and snippets.

@morales2k
Last active December 20, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morales2k/6193580 to your computer and use it in GitHub Desktop.
Save morales2k/6193580 to your computer and use it in GitHub Desktop.
Google Analytics function for custom events for analytics.js Use it anyway you want, from simply adding onclick attribute to an element other than <a> to track a click event. Easily customizable to make it track other stuff besides event hitType, or click action for that matter. See analytics.js documentation https://developers.google.com/analyt…
/*!
* Tracking function to be used with the new analytics.js (i,s,o,g,r,a,m) snippet
* @param el string Identifier for the tracking click event
* @author Jorge L. Morales (EffectiX.Net)
* @return void
*/
function gaTrack(el){
ga('send',
{
'hitType': 'event',
'eventCategory':el,
'eventAction':'click',
'eventLabel':el
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment