Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting issues with GTM Data Layer Variable Version 1

  • Troubleshooting issues with GTM Data Layer Variable Version 1

    Posted by William on 9 May 2022 at 4:35 am

    “Hey folks, I’ve run into a curious situation with my GTM container. I’ve got three data layer variables – ‘firstName’ and ‘lastName’, which are version 2, and ‘phoneNumber’ which is version 1.

    The odd thing is, when I use ‘dataLayer.push’ to first add someone’s phone number, and then remove it, the ‘phoneNumber’ doesn’t get removed from the output, even though I’m using version 1 for it.

    So what I’m scratching my head about is – can you mix and match version 1 and 2, or should all of the variables be the same version? Any help would be greatly appreciated!”

    Cameron replied 1 year ago 3 Members · 2 Replies
  • 2 Replies
  • Aiden

    Member
    2 August 2022 at 10:09 am

    Sure thing, happy to help! You’re absolutely okay mixing and matching v1 and v2 data layer variables in your GTM container. You’d typically choose depending on the structure of the objects you’re pushing.

    While v1 is a little more limited – it can only handle flat data structures and doesn’t offer recursive merging of complex objects. In your case though, where you’re handling simple info like first names, last names, and phone numbers, these limitations probably won’t cause any headaches.

    If you want to dive deeper into differences and use cases for v1 and v2, check out this nice article. But don’t sweat it, for your application it sounds like either version should do just fine. Happy data pushing!

  • Cameron

    Member
    18 June 2023 at 7:19 am

    In Google Tag Manager, it is technically possible to mix and match version 1 and version 2 data layer variables within the same container. However, the behavior of these variables can be different, which might lead to unexpected results.

    The issue you are experiencing with ‘phoneNumber’ not being removed after pushing and then removing it, might be due to how each version handles data. Version 1 data layer variables persist data across different events, which means once a data layer variable (like ‘phoneNumber’) is set, it remains available for the remainder of the session or until it’s manually cleared.

    So, while you can use both Version 1 and 2 data layer variables in the same container, it’s important to understand the reasons behind their different behaviors, especially when it comes to pushing and persisting data. Considering both versions’ characteristics, it might be simpler to stick to one version to avoid such complications. If you choose that option, changing ‘phoneNumber’ to version 2 should solve your issue.

Log in to reply.