Skip to content

Instantly share code, notes, and snippets.

@justusbluemer
Created November 27, 2018 12:55
Show Gist options
  • Save justusbluemer/91629adc9ceca3323e983b7043b042eb to your computer and use it in GitHub Desktop.
Save justusbluemer/91629adc9ceca3323e983b7043b042eb to your computer and use it in GitHub Desktop.
Link tracking example without data- attributes
<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