To console.log every argument pushed to Google Tag Manager, use
window.dataLayer = window.dataLayer || [];
// Save the original push method
const originalPush = window.dataLayer.push;
// Monkey patch push
window.dataLayer.push = function() {
// Log each argument individually
for (let i = 0; i < arguments.length; i++) {
console.log('dataLayer.push argument: ', arguments[i]);
// or console.log('dataLayer.push argument:', JSON.stringify(arguments[i]));
}
// Call original push with the same arguments
return originalPush.apply(window.dataLayer, arguments);
};NOTE: The window.dataLayer.push() method is commonly used with Google Tag Manager to send data.