Learn business growth with Google Analytics 4 Forums Google Analytics 4 Understanding the Functionality of the ecommerce Property in GTM Events

  • Understanding the Functionality of the ecommerce Property in GTM Events

    Posted by George on 3 September 2022 at 11:07 am

    So, we’ve got these two tracking methods right now in GA4—gtag and GTM’s dataLayer.

    gtag doesn’t need the ecommerce attribute to work, but GTM’s dataLayer does.
    Take a look at what I mean:

    gtag("event", "add_payment_info", {
      items: [
        {
          // item's properties
        }
      ]
    });
    
    dataLayer.push({
      event: "add_payment_info",
      ecommerce: {
        items: [
          {
            // item's properties
          }
        ]
      }
    });
    
    

    Are they really that different?

    Yeah, I know gtag calls dataLayer.push in the background. But, why does GTM need that ecommerce property? Is it just how it’s designed or is there a technical reason behind it?

    Li replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Mason

    Member
    12 December 2022 at 8:45 pm

    Actually, you’re right. The main difference between gtag.js and dataLayer has to do with flexibility and reusability. Using DataLayer is preferred because it’s a more flexible option, especially if you’re not only using Google Analytics, but also tools like Facebook Pixel or other third-party pixels.

    All these tools share similar Ecommerce features like view_item, add_to_cart, purchase, etc. When you use DataLayer, you only need to populate the ‘items’ once, and you can reuse it for other pixels as needed.

    Whereas with gtag.js, it’s more restricted – it will only apply the function to Google Analytics and Google Ads. So if you need to implement say, Facebook Pixel in the future, you’ll have to start all over from scratch.

    Using Data Layer makes things much simpler, especially for websites with a complex tracking setup. Not only does it prevent redundancy, but it will make your life a lot easier in the long run. It’s all about planning and reducing future workload!

  • Li

    Member
    18 February 2023 at 12:13 pm

    While both gtag and GTM’s dataLayer are used for tracking purposes in Google Analytics, they do have certain differences. Particularly, the ecommerce property in dataLayer is needed due primarily to how Google Tag Manager (GTM) is designed. GTM uses the dataLayer object as a virtual layer for storing and managing variables that are used to send specific information to Google Analytics and other systems. The ecommerce property is specially designed for ecommerce data, acting as an attribute for all ecommerce related actions, making it easier to deal with this kind of data. Moreover, providing structured data like the ecommerce attribute in dataLayer can be beneficial in ensuring your tracking code is flexible, maintainable, and scalable.

Log in to reply.