Skip to content

Instantly share code, notes, and snippets.

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 paulmkoch/bac15329f7225663bba7 to your computer and use it in GitHub Desktop.
Save paulmkoch/bac15329f7225663bba7 to your computer and use it in GitHub Desktop.
Event Category, Action, or Label of Existing Data Attribute
// replace the attribute with the appropriate data attribute
// if the attribute is divided with something other than commas, change tracking.split
// change the number to 0, 1, or 2, depending on whether you want the category, action, or label
function() {
var tracking = {{element}}.getAttribute('data-track-event');
tracking = tracking.split(',');
if (typeof tracking === 'object') {
return tracking[0];
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment