Craig
Craig

Reputation: 484

How to correctly implement enhanced e-commerce tracking using Tag Manager?

I want to implement Google Analytics with enhanced ecommerce tracking using Tag Manager. I'm getting in a mess though, with either page views being tracked multiple times, or parts of the data not being tracked at all.

Rightly or wrongly, this is where I'm at so far:

A data layer initialized before any other script

<script>
    tagManagerData = [];
</script>

Markup decorated with ecommerce information

<div class="productBox"
     data-ga-product="impression"
     data-product-id="@Model.Product.Id"
     data-product-name="@Model.Product.Title"
     data-product-price="@Model.Product.Price"
     data-product-position="@Model.SequencePosition"
     data-product-url="@Model.Product.RelativeUrl">

Javascript which populates the data layer

$('[data-ga-product="impression"]').each(function () {...});

and finally the Tag Manager script.

I can get everything to track if I have a trigger set up for each "push" (which is how I read the documentation) and Tag Manager script at the top of the page, but then I end up with something like 4 page views tracked per product detail page impression.

If I populate the datalayer and just have the default analytics "all pages" event run, stuff like products details will go over, but then "related product" impressions will not (I think because there ends up several ecommerce properties set in the datalayer?).

I've been working on this for 3 days and I'm getting in a complete mess and incredibly frustrated with the documentation.

Upvotes: 0

Views: 717

Answers (1)

Jakub Kriz
Jakub Kriz

Reputation: 1529

You do not have to track each item as a single product, just add all of them into javascript array in predefined structure and send them in batch mode on pageview.

If you use each function, it will be loaded probably after document ready so if you have track pageview on .* in GTM, it will require some additional server call like event with non interaction flag, or you redefine Track pageview to some event emitted by you page after all data what you want to track are ready.

Summary:

  1. Load all ecommerce data into JavaScript Object (https://developers.google.com/tag-manager/enhanced-ecommerce)
  2. Set dataLayer.push({event:'manualEvent'});
  3. in GTM create firing rule form manualEvent and Allow Enhanced Ecommerce in Tag configuration.

Upvotes: 1

Related Questions