Learn business growth with Google Analytics 4 Forums Google Analytics 4 The Challenge of Capturing Variant Titles in GTM's DataLayer for Shopify Reply To: The Challenge of Capturing Variant Titles in GTM's DataLayer for Shopify

  • Aniket

    Member
    17 November 2022 at 1:47 pm

    It seems like the issue might be arising due to the data layer for ‘add_to_cart’ event not being updated properly when a variant on the product page is changed. Most likely the script which populates the dataLayer for the add_to_cart event is not triggered or does not execute when the variant is changed. The GTM would need to be implemented in a way that it listens for the variant change event as well. Keep in mind, however, that products.selected_variant.title or item.variant.title will only update on page load or when the Liquid object is refreshed.

    Without seeing the full code, it’s challenging to provide concrete solutions. You should aim to ensure variant changes are being listened to and that GTM is informed about these changes. You might want to consider adding a JS event listener or using Shopify’s AJAX API for this purpose to track changes in real-time.

    Another possible issue could be that the ‘add_to_cart’ event script is cached and does not update the variant information when the customer changes it. Make sure the ‘add_to_cart’ event tracking script fetches the latest variant information every time an item is added to the cart.

    If you are using GA4, it is vastly different from Universal Analytics and implements events differently. You may want to look into GA4’s event structure and correctly configure it for expected results.