From a7cc8d5a315db982bffca0457e0279e775e1942b Mon Sep 17 00:00:00 2001 From: Peter Richmond Date: Fri, 25 May 2018 13:53:53 -0700 Subject: [PATCH 1/2] Gracefully fail on window.dataLayer name conflict --- lib/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/index.js b/lib/index.js index bab2d2e..802af71 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)) { + console.error('window.dataLayer already exists - not running Segment<>GTM destination') + return; + } + push({ 'gtm.start': Number(new Date()), event: 'gtm.js' }); if (this.options.environment.length) { From f661ed6b282e26330c32c11e5a8933b21e05d52b Mon Sep 17 00:00:00 2001 From: Peter Richmond Date: Fri, 25 May 2018 14:31:36 -0700 Subject: [PATCH 2/2] Change to debug --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 802af71..4b2c078 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,7 +32,7 @@ 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)) { - console.error('window.dataLayer already exists - not running Segment<>GTM destination') + this.debug('window.dataLayer already exists - not running Segment<>GTM destination'); return; }