Skip to content
This repository was archived by the owner on Nov 27, 2019. It is now read-only.

Commit a7cc8d5

Browse files
Gracefully fail on window.dataLayer name conflict
1 parent c65cea7 commit a7cc8d5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ var GTM = module.exports = integration('Google Tag Manager')
3030
*/
3131

3232
GTM.prototype.initialize = function() {
33+
// If window.dataLayer already exists and isn't an array, fail gracefully.
34+
if (window.dataLayer && !Array.isArray(window.dataLater)) {
35+
console.error('window.dataLayer already exists - not running Segment<>GTM destination')
36+
return;
37+
}
38+
3339
push({ 'gtm.start': Number(new Date()), event: 'gtm.js' });
3440

3541
if (this.options.environment.length) {

0 commit comments

Comments
 (0)