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 December 10, 2019 02:31)

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) |(identity)GlobalAdministrator%}

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

Hi,

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.

    <script>
window.dataLayer = window.dataLayer || []
dataLayer.push({
   '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
   }]
});
</script>
0 votesVote for this answer Mark as a Correct answer

Les Girvan answered on September 4, 2018 16:28 (last edited on September 4, 2018 17:32)

Hi Trevor,

Thanks for that advice on the e-com tracking, I am testing this currently for a client. Have added the code as you have advised, and have the 'GoogleAnalyticsObject' added to my master page.

On testing a transaction, GA registered a transaction, but none of the values passed through.

We are using v11.0.18, but assume this would not have any issues with version as its the GA script?

Can you advise anyway I can check via Kentico if this is loading/posting?

Many thanks Les

UPDATE Follow up to this, and I have found using the Macro Debuging, the problem I was having was down to the customer being a 'Guest' and not 'CurrentCustomer'

As such I am looking to find a solution for the WHERE value for a guest customer, will update post when I find an answer to this.

1 votesVote for this answer Mark as a Correct answer

Kevin Osburn answered on September 11, 2018 11:48

Hi Everyone,

Has anyone found a solution that includes both 'Guest' and 'CurrentCustomer'?

I followed this guide to setup for 'Purchases':

https://docs.kentico.com/k11/e-commerce-features/customizing-and-developing-your-store/integrating-google-analytics-enhanced-ecommerce?_ga=2.29703423.1326880586.1536597558-875025575.1535867110#IntegratingGoogleAnalyticsEnhancedEcommerce-Purchases

But, does anyone have advice on how to setup the rest in GTM?

Many thanks!

Kevin

0 votesVote for this answer Mark as a Correct answer

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