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 -->
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.
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:
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:
Save and publish and see if this solves your issue.