Skip to content

Instantly share code, notes, and snippets.

@sahava
Created February 26, 2019 08:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sahava/8e1b1e475247a09f3e9500b77130d6ce to your computer and use it in GitHub Desktop.
Save sahava/8e1b1e475247a09f3e9500b77130d6ce 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.
(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