Skip to content

Instantly share code, notes, and snippets.

@leonkorteweg
Last active September 7, 2018 20:08
Show Gist options
  • Save leonkorteweg/216f630061cb1544c81b8516815bf44f to your computer and use it in GitHub Desktop.
Save leonkorteweg/216f630061cb1544c81b8516815bf44f to your computer and use it in GitHub Desktop.
Google Tag Manager Variable: Click classes incl. parent elements
/**
* Click classes incl. parent elements
*
* @return {string} containing all classnames of the click element and two parent elements
* @description: Use the following code in a custom JavaScript macro variable in Google Tag Manager
*/
function() {
classNames = "";
el = {{Click Element}};
for( var i = 0; i < 2; i++ ) {
classNames += el.className + " ";
el = el.parentElement;
}
return classNames;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment