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

Conversation

Peripheral1994
Copy link
Contributor

@Peripheral1994 Peripheral1994 commented May 25, 2018

I'm updating the body of this PR to do some testing, don't mind me - Carlos

lib/index.js Outdated
@@ -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.

@f2prateek
Copy link

I wonder if GTM allows us to use something other than dataLayer - that would allow us to keep the integration running even if there is a conflict.

@Peripheral1994
Copy link
Contributor Author

I believe that we should simply allow the data layer's name to be passed in as a flag here for the &l args instead and default to dataLayer. Adding to the ticket so we can evaluate the best way to support this.

.tag('no-env', '<script src="//www.googletagmanager.com/gtm.js?id={{ containerId }}&l=dataLayer">')
.tag('with-env', '<script src="//www.googletagmanager.com/gtm.js?id={{ containerId }}&l=dataLayer&gtm_preview={{ environment }}">');

@Peripheral1994
Copy link
Contributor Author

We SHOULD still keep this no-op if the chosen data layer name is taken.

@SegmentDestinationsBot
Copy link
Contributor

Hi @Peripheral1994, as part of the monorepo migration, this issue has been moved to new issue. Our engineers have been notified and will prioritize and work on it ASAP. Thank you!

For more information, see README.md.

@SegmentDestinationsBot SegmentDestinationsBot added the migrated The issue has been migrated label Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
migrated The issue has been migrated test Ignore me
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants