Tracking Ecommerce Transactions using Google Tag Manager

Darren Walsh asked on April 17, 2018 10:07


Can somebody please show me how to send Kentico 8 e-commerce data to Google Analytics via Google Tag Manager?

What are the various macros to use for transactionId, transactionTotal, sku, product name, product price, product quantity etc.?

How to I implement them? Where do they go?

I'm new to Kentico, Any help would be greatly appreciated.


Recent Answers

Trevor Fayas answered on April 17, 2018 14:38 (last edited on April 17, 2018 14:40)

Here's the quick way:

On the "Thank you for your order page" Add...

1: A Repeater with Custom Query

2: Query of:

Select ##TOPN## ##COLUMNS## from
  Select * from COM_OrderItem
  LEFT JOIN COM_Order on COM_Order.OrderID = COM_OrderItem.OrderItemOrderID

3: Where condition (hit the black arrow to go to macro editing mode) of:

OrderID = '{% Convert.ToInt(ECommerceContext.CurrentCustomer.Orders.OrderBy("OrderDate Desc").Where("DATEDIFF(minute, OrderDate, GETDATE()) < 15").FirstItem.OrderID, -1) #%}'

4: Transformation of type Text/XML of

{% if(DataItemIndex == 0) { %}
<script type="text/javascript">
  ga('require', 'ecommerce');
  $(document).ready(function() {
  ga('ecommerce:addTransaction', {
    'id': '{% OrderInvoiceNumber %}',                     // Transaction ID. Required.
    'affiliation': 'Anatrace',   // Affiliation or store name.
    'revenue': '{% OrderTotalPrice %}',               // Grand Total.
    'shipping': '{% OrderTotalShipping %}',                  // Shipping.
    'tax': '{% OrderTotalTax %}'                     // Tax.
  {% } #%}
  ga('ecommerce:addItem', {
    'id': '{% OrderInvoiceNumber %}',                     // Transaction ID. Required.
    'name': '{% !String.IsNullOrWhiteSpace(SKUShortDescription) ? SKUShortDescription.Replace("'","\\'") : OrderItemSKUName.Replace("'","\\'") #%}',    // Product name. Required.
    'sku': '{% OrderItemSKUName.Replace("'","\\'") #%}',                 // SKU/code.
    'category': 'Chemicals',         // Category or variation.
    'price': '{% OrderItemUnitPrice %}',                 // Unit price.
    'quantity': '{% OrderItemUnitCount %}'                   // Quantity.
  {% if(DataItemIndex == DataItemCount-1) { %}
{% } #%}

6: Make sure the Google Analytics API is loaded and any supporting javascript is there.

This will need to be done in design mode.

Note that the ideal solution would be to use Event Hooks, but this will limit to only that customer's latest order, and i believe in the ecommerce api it will ignore or simply update orders if you send it with the same identification.

0 votesVote for this answer Mark as a Correct answer

Darren Walsh answered on May 15, 2018 08:20


Thanks for the response and sorry for the delay.

We use Google Tag Manager on our site, so we use the Tag Manager code rather than Analytics code for tracking. Does this matter?

Really what I'm looking for is to populate the data layer below with Kentico values rather than the dummy values below. Could somebody tell me what to use to dynamically create these values? Using Kentico 8.

Many thanks.

window.dataLayer = window.dataLayer || []
   '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': 'Socks',
       'category': 'Apparel',
       'price': 9.99,
       'quantity': 2
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.