View Single Post
  #6  
Old 04-08-2022, 12:35 PM
 
keystone keystone is offline
 

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

Default Re: Setting up Data Layer for Ecom tracking in GA4

Here is what I'm up to so far...
Code:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-#########"></script> {literal} <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); {if $config.Google_Analytics.ganalytics_e_commerce_analysis eq "Y" and $ga_track_commerce eq "Y" and $main eq "order_message" and $orders } gtag('event', 'purchase', { {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} }] {/foreach} }); {/if} gtag('config', 'G-#######'); </script> {/literal}
__________________
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