Jump to content

Google Analytics and E-commerce


datex

Recommended Posts

I recently upgraded to WHMCS 4.5.2 -and needed to reimplement Google Analytics tracking e-commerce conversions - But I have not had any success with it. I tried the method described in WHMCS Documentation.

 

Now I have placed the following code in header.tpl - just before </head>

 

<script type="text/javascript">  var _gaq = _gaq || [];  _gaq.push(['_setAccount', 'UA-17503xxxx-1']);  _gaq.push(['_trackPageview']);  (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);  })();</script>

 

And the following at the end of complete.tpl - for the orderform I use

 

{php}
$orderid = $this->get_template_vars('orderid');
$userid = $_SESSION["uid"];
// get client data
$result = select_query("tblclients","city, state, country",array("id"=>$userid));
$data = mysql_fetch_array($result);
$city = $data["city"];
$state = $data["state"];
$country = $data["country"];
$this->assign('city',$city);
$this->assign('state',$state);
$this->assign('country',$country);
// get package name
$result = select_query("tblhosting","packageid",array("orderid"=>$orderid));
$data = mysql_fetch_array($result);
$packageid = $data["packageid"];
$result = select_query("tblproducts","name, type",array("id"=>$packageid));
$data = mysql_fetch_array($result);
$name = $data["name"];
$type = $data["type"];
$this->assign('name',$name);
$this->assign('type',$type);
$this->assign('packageid',$packageid);
{/php}
<script type="text/javascript">  var _gaq = _gaq || [];  _gaq.push(['_setAccount', 'UA-17503xxxx-1']);  _gaq.push(['_trackPageview']);  _gaq.push(['_addTrans', "{$orderid}", "", "{$amount}", "0", "0", "{$city}", "{$state}", "{$country}" ]); 
_gaq.push(['_addItem', "{$orderid}", "{$packageid}", "{$name}", "{$type}", "{$amount}","1"  ]); 
_gaq.push(['_trackTrans']); 
(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);  })();</script>

 

Any idea what I'm doing wrong??

 

Should I not be able to see the e-commerce tracking code in the source when I checkout?

Link to comment
Share on other sites

  • 3 weeks later...

to add Google Analytics use this code to footer :

<script type="text/javascript">
{literal}
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-XXXXX-1']);
 _gaq.push(['_trackPageview']);

 (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>

Link to comment
Share on other sites

  • 2 weeks later...
to add Google Analytics use this code to footer :

<script type="text/javascript">
{literal}
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-XXXXX-1']);
 _gaq.push(['_trackPageview']);

 (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>

 

Google Analytics is working fine but the conversions are not since 4.5.2 upgrade.

 

Using the code suggested here: http://docs.whmcs.com/Google_Analytics_Integration

conversions were previously showing but not accurately - approx. 50% accurate!

 

This really needs resolving, would greatly appreciate it if someone could either confirm that conversion code is working as per the link or that we need to add new code and provide the code for us please.

 

In anticipation of help, thank you!

Link to comment
Share on other sites

The conversion code from http://docs.whmcs.com/Google_Analytics_Integration has never been accurate. It only tracks the total transaction amount and 1 product. You can open a ticket but they do not provide support.

 

We have developed our own version which has more options and does work: http://www.whmcs.com/members/communityaddons.php?action=viewmod&id=293 and http://forum.whmcs.com/showthread.php?p=194163. If it stops working for any reason you can contact us as we do provide support on this one.

Link to comment
Share on other sites

why doesn't someone open a ticket? and then share the results with the rest of us?

 

or... Why don't you open a ticket and share the results with us :lol:

 

Agree with @getup's comment above, this regularly gets ignored and has never been addressed by Matt. Cannot understand why, as everyone must want to track their conversions and Google for all their many faults must be one of the most common ways of doing that.

 

@getup looking at your addon now - thanks for the link.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated