Forums Forums White Hat SEO PPC Dumb Question about GA4 Ecommerce Tracking: Dynamic Content

  • PPC

    Dumb Question about GA4 Ecommerce Tracking: Dynamic Content

    Posted by cryptobro42069 on October 23, 2023 at 1:54 pm

    Hi all,

    I have a really dumb question here. Up until now, I’ve been using the GA tag to track ecommerce data and I simply migrated the existing code when GA4 came out. I’ve since added the data layer and tried to start tracking purchases.

    So here’s my dumb question. The vast majority of samples I’ve seen from Google and people on YouTube include absolute values, such as ‘Stan and Friends Tee’ for the product name and ‘7.77’ for the value. That’s all well and good, but what if you want to dynamically populate the field based on the value across multiple pages? It wouldn’t work if you sell hats AND t-shirts because it would spit out t-shirts in the reporting when you’re trying to tell Google that you sold a hat and you want to record it with a unique SKU. It would have to be dynamic, right?

    Example code:

    dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
    dataLayer.push({
    event: “purchase”,
    ecommerce: {
    transaction_id: {{transactionId}},
    value: {{itemValue}},
    tax: {{itemTax}},
    shipping: {{itemShipping}},
    currency: “USD”,
    items: [
    {
    item_id: {{itemSku}},
    item_name: {{itemName}},
    index: 0,
    price: {{itemPrice}},
    quantity: {{itemQuantity}}
    }]
    }
    });

    You get the gist. So, why do I always see absolute values in these fields in these examples when they should be dynamic and populated based on the element’s value? Is there a best practice for this?

    Appreciate anyone’s help here!

    cryptobro42069 replied 6 months, 3 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • Ok_Disaster_8183

    Guest
    October 23, 2023 at 4:31 pm

    You are right, they should be dynamic and your cart system should fill out the item and their attributes dynamically.

    I think so much of what you see online is just clickbait/google fodder that they don’t bother with the details. The article is good enough to get them a click. Or, the cynic in me thinks they purposefully make the article inaccurate/obscure so that you will sign up for whatever service they are hawking.

    Also, devs are good at reading the docs, which would explain this anyway. So a dev may not be looking at those same articles.

Log in to reply.