Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 = [], 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