Skip to content

Instantly share code, notes, and snippets.

@maltehelmhold
Last active April 15, 2019 07:29
Show Gist options
  • Save maltehelmhold/004ae38ff5881f641e5ed72183624557 to your computer and use it in GitHub Desktop.
Save maltehelmhold/004ae38ff5881f641e5ed72183624557 to your computer and use it in GitHub Desktop.
Datalayer Push für GTM Kurs
# so pusht du ein event bei Button Klick
<a href="#" name="button1" onclick="dataLayer.push({'event': 'button1-click'});" >Button 1</a>
# so pusht du ein event + statische daten + dynamische Daten mit onclick:
<a href="#" name="button1" onclick="dataLayer.push({'event': 'button1-click', 'farbe': 'rot',
'inneresHTMLdesButtons': this.innerHTML });" >Text des Buttons ist das innere HTML</a>
<script>
dataLayer.push({
'event': 'maltesButton',
'maltesButtonText': document.getElementById('maltesButton').innerHTML
})
</script>
<script>
var x = document.getElementsByClassName("maltesButton");
var i;
for (i = 0; i < x.length; i++) {
x[i].onclick = function() {
dataLayer.push({
'event': 'maltesButton',
'maltesButtonText': this.innerHTML
});
};
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment