We are pretty positive we have come up with a solution that will work with x-cart v4.5.x (we are on v4.5.5)
For using Adwords Conversions:
First create your Conversion in Adwords Conversion Tracking. Make it a purchase/sale and set the conversion value to "Each conversion has a different value. If there's no value, use 1" and make sure to track All Conversions.
We have signed up to use Google Tag Manager since it is very easy to have all of your analytics in one program.
We also use "Google Tag Assistant" extension in google chrome, so we can verify all of our code is working.
Sign up for Google Tag Manager, and create a Tag for Adwords Conversion Tracking (see attached photo).
Then create a Macro that will allow you to track the total price (see second attached photo).
In order for the macro (and your google tag manager) to work, we implemented the following code.
In the "/common_files/customer/home.tpl" file directly after the opening <body> tag:
Code:
{foreach from=$orders item="order"}
<script>
{literal}
dataLayer = [{
'transactionTotal': {/literal}{$order.order.total}{literal}
}];{/literal}
</script>
{/foreach}
This is our personal code for google tag manager, use your own code by going to Admin->Install GTM in the Google Tag Manager website
This code goes directly below the above Macro code in "/common_files/customer/home.tpl"
Code:
<!-- Google Tag Manager -->
<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-GVNVT"
height="0" width="0" style="display:none;visibility:hidden">
</iframe>
</noscript>
{literal}
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-GVNVT');
</script>
<!-- End Google Tag Manager -->
{/literal}
If you'd like to use google analytics, this is the code in our "/common_files/modules/Google_Analytics/ga_code_async.tpl" file that is working for us. You can also simply use the Google Analytics tag in Google Tag Manager (recommended):
Code:
<script type="text/javascript">
(function(i,s,o,g,r,a,m){ldelim}i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ldelim}
(i[r].q=i[r].q||[]).push(arguments){rdelim},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
{rdelim})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{$config.Google_Analytics.ganalytics_code}'); // Analytics Property ID
ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview');
{if
$config.Google_Analytics.ganalytics_e_commerce_analysis eq "Y"
and $main eq "order_message"
and $orders
} // we removed from the above if statement $ga_track_commerce eq "Y"
// Ecommerce Tracking for order_message page
ga('require', 'ecommerce'); // Load the ecommerce plug-in. ga('require', 'ecommerce', 'ecommerce.js');
{foreach from=$orders item="order"}
ga('ecommerce:addTransaction', {ldelim}
'id': '{$order.order.orderid}', // Transaction ID. Required
'revenue': '{$order.order.total}', // Grand Total
{if $order.order.shipping_cost gt 0}'shipping': '{$order.order.shipping_cost}'{else}'shipping': '0'{/if}, // Shipping
{if $order.order.tax gt 0}'tax': '{$order.order.tax}',{/if} // Tax
'affiliation': '{$partner|default:'SilverHorse Racing'}' // Affiliation or store name
{rdelim});
{foreach from=$order.products item="product"}
ga('ecommerce:addItem', {ldelim}
'id': '{$order.order.orderid}', // Transaction 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. Required.
'sku': '{$product.productcode|wm_remove|escape:javascript}', // SKU/code.
'category': '{$product.category|default:'Unknown category'}', // Category or variation.
'price': '{$product.price}', // Unit price.
'quantity': '{$product.amount}' // Quantity.
{rdelim});
{/foreach}
{/foreach}
ga('ecommerce:send'); //submits transaction to the Analytics servers
{/if}
</script>
{if $active_modules.Google_Checkout ne ""}
<script src="{if $current_location eq $http_location}http{else}https{/if}://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>
{/if}