diff --git a/lib/index.js b/lib/index.js index bab2d2e..4b2c078 100644 --- a/lib/index.js +++ b/lib/index.js @@ -30,6 +30,12 @@ var GTM = module.exports = integration('Google Tag Manager') */ GTM.prototype.initialize = function() { + // If window.dataLayer already exists and isn't an array, fail gracefully. + if (window.dataLayer && !Array.isArray(window.dataLater)) { + this.debug('window.dataLayer already exists - not running Segment<>GTM destination'); + return; + } + push({ 'gtm.start': Number(new Date()), event: 'gtm.js' }); if (this.options.environment.length) {