Google Analytics Enhanced E-commerce Tracking/Analytics is not working via GTM
Asked Answered
O

1

6

For my website I already have GA & GTM. Enhanced E-commerce is already enabled. As can see from below image.

enter image description here

I have tried below code as well.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <!-- Google Tag Manager -->
  <script>(function (w, d, s, l, i) {
      w[l] = w[l] || [];
      w[l].push(
          {'gtm.start': new Date().getTime(), event: 'gtm.js'}
      );
      var f = d.getElementsByTagName(s)[0],
          j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
      j.async = true;
      j.src =
          'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
      f.parentNode.insertBefore(j, f);
  })(window, document, 'script', 'dataLayer', 'GTM-XXXXX');</script>
  <!-- End Google Tag Manager -->

  <!-- Google Tag Manager (noscript) -->
<noscript>
  <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
          height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
</head>
<body>
  <script>
window.dataLayer = window.dataLayer || [];


dataLayer.push({
  "event": "addToCart",
  "ecommerce": {
    "currencyCode": "USD",
    "add": {
      "products": [{
        "id": "57b9d",
        "name": "Kiosk T-Shirt",
        "price": "55.00",
        "brand": "Kiosk",
        "category": "T-Shirts",
        "variant": "red",
        "dimension1": "M",
        "quantity": 1
      }]
    }
  }
});

dataLayer.push({
   'event' : 'purchase',
   'transactionId': '1234',
   'transactionAffiliation': 'Acme Clothing',
   'transactionTotal': 38.26,
   'transactionTax': 1.29,
   'transactionShipping': 5,
   'transactionProducts': [{
       'sku': 'DD44',
       'name': 'T-Shirt',
       'category': 'Apparel',
       'price': 11.99,
       'quantity': 1
   },{
       'sku': 'AA1243544',
       'name': 'Hat',
       'category': 'Apparel',
       'price': 9.99,
       'quantity': 2
   }]
});




ga('create', 'UA-XXXXXXX-4');
ga('require', 'ec');
ga('set', 'currencyCode', 'SGD');
ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt - with UA 4',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black',
  'price': '29.20',
  'quantity': 1
});

// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', {
  'id': 'T12345',
  'affiliation': 'Google Store - Online - with UA 4',
  'revenue': '37.39',
  'tax': '2.85',
  'shipping': '5.34',
  'coupon': 'SUMMER2013'    // User added a coupon at checkout.
});

ga('send', 'pageview');     // Send transaction data with initial pageview.

</script>
</body>
</html>

I have followed https://ga-dev-tools.appspot.com/enhanced-ecommerce/

enter image description here

Although doing above things it is still not showing any result.

enter image description here

I want to track two things initially.

  1. Product added to cart
  2. Order purchase

Any help on above one greatly appreciated.

Thanks

[UPDATE]

I have followed below tutorial as well.

  1. https://www.youtube.com/watch?v=xgLGWvhOyHU
  2. https://www.youtube.com/watch?v=3G5wvjC1rHo
  3. https://www.youtube.com/watch?v=OpUtb_Grl2A [I have done GTM settings like this]

https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_purchases -> I tried this already

So my latest test code is now

<script>
var dataLayer = window.dataLayer || [];
dataLayer.push({
  'event' : 'transaction',
  'ecommerce': {
    'purchase': {
      'actionField': {
        'id': 'T12345',                         // Transaction ID. Required for purchases and refunds.
        'affiliation': 'Online Store',
        'revenue': '35.43',                     // Total transaction value (incl. tax and shipping)
        'tax':'4.90',
        'shipping': '5.99',
        'coupon': 'SUMMER_SALE'
      },
      'products': [{                            // List of productFieldObjects.
        'name': 'Triblend Android T-Shirt',     // Name or ID is required.
        'id': '12345',
        'price': '15.25',
        'brand': 'Google',
        'category': 'Apparel',
        'variant': 'Gray',
        'quantity': 1,
        'coupon': ''                            // Optional fields may be omitted or set to empty string.
       },
       {
        'name': 'Donut Friday Scented T-Shirt',
        'id': '67890',
        'price': '33.75',
        'brand': 'Google',
        'category': 'Apparel',
        'variant': 'Black',
        'quantity': 1
       }]
    }
  }
});
</script>

enter image description here

1st issue it is not showing any event over here.

enter image description here

[LATEST UPDATE]

enter image description here

I am able to get events now, but in E-commerce overview still it's blank

Overdye answered 5/6, 2020 at 3:35 Comment(0)
L
3

A few things:

  • You have duplicate tracking even though right now nothing seems to be working, when things do, you'll end up with duplicate events. You either want to use GTM dataLayer.push OR the native ga calls, but you don't want to track purchases with both. My advise is to migrate everything to GTM since it gives you more control (ie you can extend/edit your analytics without having to change your source code each time).

  • The GTM purchase syntax is wrong: see https://developers.google.com/tag-manager/enhanced-ecommerce#purchases for syntax example, although make sure you add the "event" key so you can setup GTM triggers.

  • You're not showing us whether GTM tags are firing: by default GTM will do nothing with your data. For data to be sent to GA you need to configure triggers and tags.

  • Use the Chrome GA debugger plugin: https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en. After install, click on the extension icon to enable it and open up the browser console:

    • if you don't see debug, it means no GA tracking calls (whether native or via GTM) are firing
    • when they are, you will see debug info, including potential errors with explanations as to why data is not being sent
    • if you see the data being sent to GA properly but not appear there it's most likely a GA config error such as filters or sometimes sending data to the wrong property
  • Keep in mind about analytics/cookie blockers you may have installed which prevent tracking.

Laevorotation answered 5/6, 2020 at 6:16 Comment(2)
Hi @Max, Thanks for answer. Let me go through it. Yes our everything is already migrated to GTM. So for analytics we are not using GA (UA--XXX-XX) code. We are using GTM-XXXXX. But for testing purpose I have added thoseOverdye
Hi @Max, I tried all things as you mentioned & I also put update in question as well. It will be good if you can give some guidance on this. ThanksOverdye

© 2022 - 2024 — McMap. All rights reserved.