crmpicco
crmpicco

Reputation: 17181

eCommerce tracking code not firing in Google Analytics 4 implementation

I am currently migration to Google Analytics 4 and have placed the following code on my page. I should point out that one property is a "rollup" property and the other is for the section of the application, so there are intentionally two properties (and two measurement IDs on this page).

<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Y3R4ABCHDJ"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-Y3R4ABCHDJ', { 'groups': 'crmpiccogroup', 'debug_mode': true });
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-NWLRFCBJK"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-NWLRFCBJK', { 'groups': 'crmpiccogroup', 'debug_mode': true });
</script>
</head>

The code above works, but when I add the following code further down the page the code does not fire and no eCommerce transaction is recorded. The code looks correct based on the documentation, so I am struggling to see what is missing here.

<script>
    gtag("event", "purchase", {
        transaction_id: 'txn_AzqeWaTpEiLcj3b55',
        value: '160.00',
        tax: '0.00',
        currency: "AUD",
        items: [
        {
           item_name: 'Castore Jacket',
           affiliation: 'New on existing account',
           price: '160.00',
           quantity: 1
        }]
    });
</script>

Upvotes: 0

Views: 328

Answers (1)

BNazaruk
BNazaruk

Reputation: 8111

You're missing item_ids. Read the documentation carefully, it lists mandatory fields: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#purchase

Also, when testing, check your Network tab for Collect events, or install adswerve datalayer explorer extension. The extension will show actual events in the console. Mind you that GA4 introduces event batching, so your purchase event may take a few seconds to dispatch after the page is loaded.

Upvotes: 0

Related Questions