0

I'm encountering a discrepancy between user/session activity and transaction count in Google Analytics (GA) for a Magento 2.4.4p4 Enterprise Edition project. The culprit seems to be frequent GTM session regeneration triggered by the GTM tags script for the datalayer.

Here's a breakdown of the situation:

  1. GTM Tag Implementation:
  • Installed GTM tags with the script placed in the source code (app/design).
  • Observed a significant discrepancy between user/session and transaction data in GA.
  1. Troubleshooting Steps:

    Script Initialization Location:
    
  • Initially placed the GTM tags script in the source code (app/design).

  • Attempted to move the script initialization from app/design to app/code through default.xml to potentially avoid conflicts.

  • Unfortunately, the session regeneration issue persisted.

    GTM Code Review and Fixes:
    
  • Inspected the GTM code for potential issues like undefined IDs or wishlist functionality.

  • Implemented fixes within the code to address these identified problems (e.g., defining missing IDs, resolving wishlist issues).

    Fresh Magento Installation Test:
    
  • Installed a clean Magento 2.4.4p4 EE instance locally.

  • Replicated the GTM tag implementation on the fresh installation.

  • Observed that the session regeneration problem still occurs, suggesting a potential issue within Magento core itself.

  1. Code Snippet:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
  1. Requirement and Observation:
  • GTM requires the script at the head of every page for proper loading.
  • Script presence leads to session regeneration on every page change.
  • Script absence prevents datalayer push to GTM.

Question:

I don't fully grasp how this script interacts with Magento's session regeneration mechanism. However, it appears to be the only factor I can manipulate.

To further investigate:

  • I replicated the issue on a fresh Magento 2.4.4p4 EE installation.
  • This suggests a potential Magento or GTM script-related issue, but I'm unsure of the root cause.

Request:

I'd greatly appreciate any insights or solutions to resolve this session regeneration problem and ensure accurate data collection in GA.

1
  • Hi, this issue has been fixed, apparently it is caused by the GTM tags from google side Commented Jul 1 at 3:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.