View Single Post
  #1  
Old 03-29-2022, 12:03 PM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default Setting up Data Layer for Ecom tracking in GA4

Hi, I've just installed the Google Tracking Manager code on my site and it seems to be connected and reading ok. I'd like to set up the Ecomm tracking. I've been following a tutorial on setting up the Data Layer required. I've kind of hacked together some code using existing Google Analytic code/variables from the built in x-cart module plus the example from the tutorial. Can someone take a look at what I've got to see if I'm even close to having what I need?

Code:
<script> window.dataLayer = window.dataLayer || []; dataLayer.push({ {foreach from=$orders item="order"} 'transactionId' : "{$order.order.orderid}", // order ID - required 'transactionAffiliation' : "{$partner|default:'Main stock'}", // affiliation or store name 'transactionTotal' : "{$order.order.total}", // total - required 'transactionShipping' : "{$order.order.shipping_cost}", // shipping 'transactionTax' : "{$order.order.tax}" // tax 'transactionProducts' : [{ {foreach from=$order.products item="product"} 'transactionId' : "{$order.order.orderid}", // order ID - required 'name' : "{$product.product|wm_remove|escape:javascript}{if $active_modules.Product_Options ne "" and $product.product_options_txt} ({$product.product_options_txt|replace:"\n":", "|wm_remove|escape:javascript}){/if}", // product name 'sku' : "{$product.productcode|wm_remove|escape:javascript}", // SKU/code - required 'category' : "{$product.category|default:'Unknown category'}", // category or variation 'price' : "{$product.price}", // unit price - required 'quantity' : "{$product.amount}" // quantity - required {/foreach} }] }); </script>

the original GA code in x-cart google anyalytics module ecommerce section has some additional lines like below but not sure if I need those (mainly the ldelim and rdelim) or the {literal} tags.
Code:
ga('ecommerce:addTransaction', {ldelim}
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote