Created
November 27, 2018 12:55
-
-
Save justusbluemer/91629adc9ceca3323e983b7043b042eb to your computer and use it in GitHub Desktop.
Link tracking example without data- attributes
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
<a href="/example" id="link-123">Anchor text</a> | |
<script> | |
var linkTrackingData = [ | |
{ | |
id: 'link-123', | |
dyn_eventaction: '…', | |
dyn_teasertype: '…', | |
moduletype: '…', | |
elementinfo: '…', | |
elementlinktype: '…', | |
dyn_subteasercontent: '…', | |
dyn_eventlabel: '…', | |
elementtype: '…', | |
dyn_teasercontent: '…', | |
dyn_eventsubtype: '…', | |
}, | |
// … | |
] | |
var elements = document.querySelectorAll('a[id^=link-') | |
elements.forEach(function(link){ | |
link.addEventListener('click', trackClick) | |
}) | |
var trackClick = function(e) { | |
// Iterate linkTrackingData | |
// Find matching object with appropriate tracking data | |
// Send event to tracking tool | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment