Last active
September 7, 2018 20:08
-
-
Save leonkorteweg/216f630061cb1544c81b8516815bf44f to your computer and use it in GitHub Desktop.
Google Tag Manager Variable: Click classes incl. parent elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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