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

Commit

Permalink
Gracefully fail on window.dataLayer name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Peripheral1994 authored May 25, 2018
1 parent c65cea7 commit a7cc8d5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a7cc8d5

Please sign in to comment.