gtag Purchase Event ignored on Google Analytics
Asked Answered
C

4

8

I'm succesfully tracking some events with gtag.js on Google Analytics, with the exception of "purchase" event. Using GTM/GA chrome plugin I've checked that all events are tracked correctly, "purchase" included. The problem is that "purchase" is not tracked on Google Analytics: all the others are tracked ("begin_checkout", "add_to_cart" ...).

gtag("event", "purchase", {
  affiliation: "Google online store",
  coupon: "SUMMER_DISCOUNT",
  currency: "USD",
  shipping: 5.55,
  tax: 3.33,
  transaction_id: "T_1",
  value: 28.86,
  items: [
    {
      id: "P12345",
      name: "Android Warhol T-Shirt",
      coupon: "P12345_coupon",
      list_name: "Search Results",
      brand: "Google",
      category: "Apparel/T-Shirts",
      variant: "Black",
      list_position: 3,
      quantity: 1,
      price: 9.99
    },
    {
      id: "P12346",
      name: "Flame challenge TShirt",
      coupon: "P12346_coupon",
      list_name: "Search Results",
      brand: "MyBrand",
      category: "Apparel/T-Shirts",
      variant: "Red",
      list_position: 5,
      quantity: 1,
      price: 9.99
    }
  ]
});

The conversion/e-commerce graph is flat as you can see. What am I missing? enter image description here

Update I've created a GAnalytics test account and the purchase event is tracked. On the screenshot's account, maybe, some configuration is missing: could be?

Crossover answered 2/11, 2020 at 15:16 Comment(0)
S
3

I had the exact same problem. Some things I noticed that could explain ut.

  1. Date Range: Maybe you missed the fact that the date range in your Analytics report is set for 26 Oct - 1 Nov, while your events were triggered on 2 Nov?

  2. Wrong Value Field: If the calculation of the value field is wrong (does not equal total of all items plus shipping field plus tax field) Google might ignore the event.

  3. Processing Time: Even when the "Real-Time" view shows the events, they are not always included in other reports until some time later.

Solvency answered 30/12, 2020 at 15:11 Comment(1)
Sometimes, I send events where the total of all items is not equal to the value with tax and shipping because there is a coupon code applied (the coupon field is just a string so there is no way for Google to validate the total). Nevertheless, the events are valid since I see them in Google Analytics.Mayworm
T
2

Interestingly I'm seeing something similar on my tests and I'm using some sample code off google:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-Y"></script>
<script nonce="djRFUUKP+SLF1k4qkKFqiLTO4Qo=">
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments); }
    gtag('js', new Date());
    gtag('config', 'UA-XXXXXX-Y');
    </script>

    <script nonce="djRFUUKP+SLF1k4qkKFqiLTO4Qo=">
    gtag('event', 'purchase', {
    "transaction_id": "24.031608523954162_C",
    "affiliation": "Google online store_C",
    "value": 0.01,
    "currency": "GBP",
    "tax": 1.24,
    "shipping": 0,
    "items": [
    {
      "id": "P12345C",
      "name": "Android Warhol T-Shirt",
      "list_name": "Search Results",
      "brand": "Google",
      "category": "Apparel/T-Shirts",
      "variant": "Black",
      "list_position": 1,
      "quantity": 2,
      "price": '0.01'
    },
    {
      "id": "P67890C",
      "name": "Flame challenge TShirt",
      "list_name": "Search Results",
      "brand": "MyBrand",
      "category": "Apparel/T-Shirts",
      "variant": "Red",
      "list_position": 2,
      "quantity": 1,
      "price": '3.0'
    }
    ]
    });
    </script>

We use nonce because we are using CSP and believe all CSP urls are set correctly in the CSP.

Any insight would be a great help as to why this would not be logging this transaction data.

Tubercular answered 12/11, 2020 at 17:8 Comment(2)
Note that the value parameter of your purchase event is smaller than the total of all the items. From my experience google might decide to ignore the event because of that.Solvency
Note that if you specify the coupon field, the total can be smaller that the total of all items. It's not the case in your code snippet though, but the price is a string, it should be an integer (price: 3 instead of price: '3.0').Mayworm
M
1

Just found that:

"transaction_id": "-1",

will also be hard ignored by GA4, even in debug_mode. So if you're testing, developing or debugging it will get picked up if you insert "TEST" (or anything else for that matter) before it.


gtag("event", "purchase", { debug_mode: true,
    transaction_id: "TEST-1",
...
Mediterranean answered 20/12, 2022 at 14:17 Comment(0)
S
-2

For Item Data:, id should be the transaction ID. See here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#item

Snowmobile answered 28/1, 2022 at 11:18 Comment(1)
The link you provided is the documentation for analytics.js and not gtag.js. In the gtag documentation, the id is described as The product ID or SKU: developers.google.com/analytics/devguides/collection/gtagjs/…Mayworm

© 2022 - 2024 — McMap. All rights reserved.