adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
723 stars 737 forks source link

Tracking events intended for GTM datalayer are being intercepted #2736

Closed kelly-howard-rh closed 2 months ago

kelly-howard-rh commented 2 months ago

Bug Report

Current Behavior Tracking events sent to GTM datalayer are not being recorded. Many errors appear in the browser console: core.wcm.components.commons.datalayer.acdl.lc-bf921af342fd2c40139671dbf0920a1f-lc.min.js:54 The following item cannot be handled by the data layer because it does not have a valid format: {"0":"set","1":"url_passthrough","2":false}

The error is coming from the Adobe datalayer script. These events are intended to be pushed to the GTM dataLayer variable. They are being intercepted by the Adobe datalayer.

Expected behavior/code Events should be pushed to the GTM datalayer and not invoke Adobe code.

Environment

Possible Solution We believe this is due to the new variable dataLayer being declared at the global level. It is overwriting the GTM dataLayer variable which existed before. var dataLayer = window[dataLayerName] = window[dataLayerName] || []; https://github.com/adobe/aem-core-wcm-components/pull/2724/commits/27fda047ff40ca7f7be8889320b428bf5adc3e4c

Code that was calling dataLayer.push() was previously hitting the GTM dataLayer and is now being sent to the Adobe datalayer. Possible solution would be to change the name of this variable to something like adobeDataLayer.

Additional context / Screenshots image

kelly-howard-rh commented 2 months ago

@vladbailescu If you could take a look. Thank you!

vladbailescu commented 2 months ago

@kelly-howard-rh , you're right, the code at https://github.com/adobe/aem-core-wcm-components/commit/27fda047ff40ca7f7be8889320b428bf5adc3e4c#diff-e289a30c0e7d5fd4e564b69136581640602ef9a99e21a9065f7522660a5488b3R31 does create a global (page/document) scope object named dataLayer

kelly-howard-rh commented 2 months ago

Thank you @vladbailescu ! Do you know what the timing is for this getting put into an AEM release?

vladbailescu commented 2 months ago

Current plan is to include this in upcoming Core Components release (ETA: end of April) and include it in AEM 2024.5 release (ETA: end of May)

kelly-howard-rh commented 2 months ago

Thank you @vladbailescu for the quick attention to this issue!