Jump to content

Google Analytics Ecommerce Tracking Code


bigpedro
 Share

Recommended Posts

Hi All

 

I wonder if anybody has ever managed to track conversions of Adwords Clicks through Cube Cart V5 and Google Analytics?

 

Obviously when you enter your UA google analytics code in general settings Cubecart adds the google analytics code to every page and you can track all visitors etc.

 

However there is another side to this.  To track conversions of google adwords customers there is another piece of code required.  This should (I think) sit on the skins/templates/content.receipt.php file.

 

If you look at this file at the very bottom there is already some code here:  See Below

 

 

{if isset($ANALYTICS)}
  <!-- Google Analytics for e-commerce -->
  <script type="text/javascript">
  {literal}
  pageTracker._addTrans('{$GA_SUM.cart_order_id}','','{$GA_SUM.total}','{$GA_SUM.total_tax}','{$GA_SUM.shipping}',"{$GA_SUM.town}","{$GA_SUM.state}","{$GA_SUM.country_iso}");
  {/literal}
{foreach from=$GA_ITEMS item=item}
  {literal}
  pageTracker._addItem('{$GA_SUM.cart_order_id}','{$item.product_code}',"{$item.name}",'','{$item.price}','{$item.quantity}');
  {/literal}
{/foreach}
  {literal}
  pageTracker._trackTrans();
  {/literal}
  </script>
  {/if}
 
However - this piece of code is not tracking our conversions at all.  I have spoken with Google and they have confirmed that this code is incorrect.  

Has anybody got this working?  I have looked through the forums and nobody seems to be discussing it.  This either means that you all have it working or nobody is bothered!!

Any help would be greatly appreciated.

 
Link to comment
Share on other sites

"I have spoken with Google and they have confirmed that this code is incorrect."

 

Did they mention just what about it is incorrect? On the one hand, the {literal}, {foreach}, etc tags necessary for Smarty to do its thing on this template could be thought of as what is wrong.

 

On the other hand, and I'm sure the Google people could figure this out, that the statements are obsolete. If this is the case, then know that CC520 provides a lot more information to be tracked.

 

Also know that, in my opinion, the situation exists in CC514 and CC515 (and maybe a few earlier versions) that there is a bug, in that the file content.receipt.php uses an object variable named pagetracker, which existed in CC508, but the variable in use in CC514/CC515 is _gaq. So I'm not sure if sales were ever recorded between version CC509 and CC515.

 

Your SIG says you will be upgrading to CC514 shortly. I would also recommend downloading CC520 just to get at the newest GA code to replace what is there in CC514.

 

As for dealing with AdWords, until Devellion officially adds that to the code, I think we can try to figure out how to implement it over at www,cubecartforums.org.

Link to comment
Share on other sites

Thanks for your reply bsmither.  It appears that indeed it was a bug and the code in content.receipt.php was not correct.  I beleive that this will be addressed in the next release.  I have just implemented the code as instructed by cubecart support, hopefully this will work - but we can't see for 24 hours while we wait for google to show conversionns!

 

If anybody else has this problem.  Basically at the bottom of content.receipt.php replace the existing Analytics code with this:

 

<!-- Google Analytics for e-commerce -->
<script type="text/javascript">
{literal}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{/literal}{$GA_SUM.google_id}{literal}']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'{/literal}{$GA_SUM.cart_order_id}{literal}', // order ID - required
'{/literal}{$GA_SUM.store_name}{literal}', // affiliation or store name
'{/literal}{$GA_SUM.total}{literal}', // total - required
'{/literal}{$GA_SUM.total_tax}{literal}', // tax
'{/literal}{$GA_SUM.shipping}{literal}', // shipping
'{/literal}{$GA_SUM.town}{literal}', // city
'{/literal}{$GA_SUM.state}{literal}', // state or province
'{/literal}{$GA_SUM.country_iso}{literal}' // country
]);
{/literal}

// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
{foreach from=$GA_ITEMS item=item}
{literal}
_gaq.push(['_addItem',
'{/literal}{$GA_SUM.cart_order_id}{literal}', // order ID - required
'{/literal}{$item.product_code}{literal}', // SKU/code - required
'{/literal}{$item.name}{literal}', // product name
'', // category or variation
'{/literal}{$item.price}{literal}', // unit price - required
'{/literal}{$item.quantity}{literal}' // quantity - required
]);
{/literal}
{/foreach}
{literal}
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
</script>
 

In addition in classes/cubecart.class.php at around line 1119 make sure you have this:

 

// Analytics
$vars['ga_sum'] = $order;
$vars['ga_sum']['country_iso'] = getCountryFormat($order['country'], 'numcode', 'iso');
$vars['ga_sum']['google_id'] = $GLOBALS['config']->get('config', 'google_analytics');
$vars['ga_sum']['store_name'] = $GLOBALS['config']->get('config', 'store_name');
$GLOBALS['smarty']->assign('GA_SUM', $vars['ga_sum']);
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...