Difference between revisions of "Google Analytics"

From WHMCS Documentation

m (Reverted edits by John (Talk); changed back to last version by Matt)
Line 5: Line 5:
 
1. Begin by inserting the code below into your footer.tpl template file before the </body> tag:
 
1. Begin by inserting the code below into your footer.tpl template file before the </body> tag:
  
  <nowiki>{literal}
+
  <nowiki><script type="text/javascript">
<script type="text/javascript">
 
 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
 
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
 
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
+
{literal} try {
<script type="text/javascript">
+
var pageTracker = _gat._getTracker("UA-xxxxx-x");
try {
 
var pageTracker = _gat._getTracker("UA-70000-3");
 
 
pageTracker._trackPageview();
 
pageTracker._trackPageview();
} catch(err) {}</script>
+
} catch(err) {} {/literal}
{literal}</nowiki>
+
</script></nowiki>
  
 
2. And to complete the integration, add the following code to the complete.tpl template file in your active order form template folder:
 
2. And to complete the integration, add the following code to the complete.tpl template file in your active order form template folder:
Line 46: Line 43:
 
{/php}
 
{/php}
  
{literal}
 
 
<script type="text/javascript">
 
<script type="text/javascript">
 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
Line 55: Line 51:
 
pageTracker._addItem( "{$orderid}", "{$packageid}", "{$name}", "{$type}", "{$amount}","1" );
 
pageTracker._addItem( "{$orderid}", "{$packageid}", "{$name}", "{$type}", "{$amount}","1" );
 
pageTracker._trackTrans();
 
pageTracker._trackTrans();
</script>{/literal}</nowiki>
+
</script></nowiki>

Revision as of 21:22, 4 November 2009

Google Analytics allows you to track how people find your site, how they navigate through it and how they become customers. You can see trends of pageviews, visits, bounce rate, conversion rate, geographical locations and much more.

To integrate google analytics into your WHMCS system, simply follow the 2 steps below:

1. Begin by inserting the code below into your footer.tpl template file before the </body> tag:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
{literal} try {
var pageTracker = _gat._getTracker("UA-xxxxx-x");
pageTracker._trackPageview();
} catch(err) {} {/literal}
</script>

2. And to complete the integration, add the following code to the complete.tpl template file in your active order form template folder:

{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 gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
var pageTracker = _gat._getTracker("UA-XXXXX-X");
pageTracker._trackPageview();
pageTracker._addTrans( "{$orderid}", "", "{$amount}", "0", "0", "{$city}", "{$state}", "{$country}"  );
pageTracker._addItem( "{$orderid}", "{$packageid}", "{$name}", "{$type}", "{$amount}","1" );
pageTracker._trackTrans();
</script>