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

Gracefully fail on window.dataLayer name conflict #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return;
}

push({ 'gtm.start': Number(new Date()), event: 'gtm.js' });

if (this.options.environment.length) {
Expand Down