Tracking Ecommerce Transactions using Google Tag Manager

Darren Walsh asked on April 17, 2018 10:07

Hi,

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.

Thanks

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
  LEFT JOIN COM_SKU on COM_SKU.SKUID = COM_OrderItem.OrderItemSKUID
) Temp WHERE ##WHERE## ORDER BY ##ORDERBY##

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) { %}
  ga('ecommerce:send');
  });
</script>
{% } #%}

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

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