DataLayer for TagManager is not tracked in Google analytics

3k views Asked by At

I am able to dynamically construct the datalayer for tagmanager. But it is not tracked in Google Analytics.

From the documentation provide by google, we need not use datalayer.push[] as it is rendered before the tagmanager codes. My code for this is:

<script>
dataLayer = [{
"transactionId": "4NOV2013_4830a18f-15fd-4cc5-a035-0e513d3f73bb",
"transactionAffiliation":"Registration",
"transactionTotal": 0,
"transactionProducts": [{
"sku": "Lead",
"name":"Lead",
"price": 0,
"quantity": 1
}]
    }];

</script>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-DEMO"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-DEMO');</script>
<!-- End Google Tag Manager -->
2

There are 2 answers

6
MrSponge On

You are missing several syntaxes for e-commerce to work in Universal Analytics. Have you read the documentation on https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce?

What you have now is basically only the transaction saved within GTM, so there are several ways to go about doing the actual transaction. You could set up rules within GTM to fire the transaction if it sees a specific event within the dataLayer, which looks like what you have tried? If so, then you need to create a rule to fire the transaction once it sees this data.

Or, you could just send the whole transaction within the checkout page where the dataLayer itself is placed.

For this to work, and what I am seeing is missing, is the call for the ecommerce javascript library.

ga('require', 'ecommerce', 'ecommerce.js');

Also, your not sending the transaction itself using ga('ecommerce:send');.

Some key components from the documentation from Google is, when using the ecommerce.js library:

To load the ecommerce plugin, use the following command:

ga('require', 'ecommerce', 'ecommerce.js');

This command must occur after you create your tracker object and before you use any of the ecommerce specific functionality.

ga('ecommerce:addTransaction', {
  'id': '1234',                     // Transaction ID. Required.
  'affiliation': 'Acme Clothing',   // Affiliation or store name.
  'revenue': '11.99',               // Grand Total.
  'shipping': '5',                  // Shipping.
  'tax': '1.29'                     // Tax.
});

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

ga('ecommerce:send');

UPDATE: After a comment from questioner, I'd like to add this to my answer. What needs to be done is to set up the transaction itself to be tracked within GTM. To do this, follow theese steps:

  1. Create a new tag and name it, for example, "Track transaction".
  2. Select "Universal Analytics" as tag type
  3. Select "Transaction" as track type
  4. Add a new rule and name it, for example, "Conversion page"
  5. Enter URL contains "thank-you-page" and add another field
  6. Enter event equals gtm.dom

Save and publish and see if this solves your issue.

0
Petr Havlik On

Sridhar, it seems that you are listing all required parameters, so this should work once the e-commerce tag is setup correctly. Make sure you add a new tag for e-commerce transactions:

  • Tag Type: Google/Universal Analytics
  • Track Type: Transaction

Full official documentation from Google Tag Manager team.

Also make sure you use correct version of GTM container snippet. I can see you have replaced one of the container IDs with GTM-DEMO, but the other one is still visible (html?id=GTM-KMSLVD).

Double check the container is working correctly, then use Preview/Debug feature to see if the tags fires together with GA Debug in Chrome (see the attached picture). If there is anything wrong (like argument type), GA Debug will list all the error messages in the browser console.

enter image description here