Last active
November 6, 2020 03:54
-
-
Save chavesm/81217b968f57943f99217fcc53570ea3 to your computer and use it in GitHub Desktop.
Set the data-vars-ga-label to the document.URL for dynamic custom event link label
This file contains 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
<?php | |
/** | |
* Add to Child Theme's functions.php. | |
*/ | |
add_action( 'wp_footer', function () { | |
if (is_page ('2')) { | |
?> | |
<script> | |
// Dynamic Label Snippet | |
let dl941392 = document.querySelector("#dynamic-label"); // or document.querySelector("a"); | |
if ( dl941392 ) { | |
dl941392.setAttribute("data-vars-ga-label", document.URL); | |
} | |
</script> | |
<?php | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live demo on CodePen: https://codepen.io/marklchaves/pen/dyMVZbV?editors=1011