Google Analytics
From WHMCS Documentation
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:
{literal} <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")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-70000-3"); pageTracker._trackPageview(); } catch(err) {}</script> {literal}
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} {literal} <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>{/literal}