Forked from sahava/add-missing-datalayer-event.js
Created
September 14, 2020 09:08
-
-
Save zjuul/05831296f92b4aacddfa7c823e091791 to your computer and use it in GitHub Desktop.
This piece of code adds a default 'event' key-value to each dataLayer.push() that hasn't got one.
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
(function() { | |
var oldPush = window.dataLayer.push; | |
window.dataLayer.push = function() { | |
var states = [].slice.call(arguments, 0); | |
states.forEach(function(s) { | |
if (!s.hasOwnProperty('event')) { | |
s.event = 'default'; | |
} | |
}); | |
return oldPush.apply(window.dataLayer, states); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment