Skip to content

Instantly share code, notes, and snippets.

@zjuul
zjuul / add-missing-datalayer-event.js
Created Sep 14, 2020 — forked from sahava/add-missing-datalayer-event.js
This piece of code adds a default 'event' key-value to each dataLayer.push() that hasn't got one.
View add-missing-datalayer-event.js
(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);