datex Posted August 15, 2010 Share Posted August 15, 2010 Hi I have tried implementing the Google Analytics code as described here: http://wiki.whmcs.com/Google_Analytics_Integration It tracks stats and I'm able to set up goals - but should I not be able to use the ecommerce part in Google Analytics? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted August 15, 2010 Share Posted August 15, 2010 (edited) Heres the exact code I have at the end of complete.tpl: {php} $orderid = $this->get_template_vars('orderid'); $userid = $_SESSION["uid"]; $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); $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', 'XX-XXXXXXXX-X']); _gaq.push(['_setDomainName', 'MYDOMAINNAME.COM']); _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']); {literal} (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> EDIT: attached a screenshot of our GA ecommerce overview showing that it is working. Edited August 15, 2010 by laszlof 0 Quote Link to comment Share on other sites More sharing options...
datex Posted August 16, 2010 Author Share Posted August 16, 2010 I have tried implementing the above code in complete.tpl <link rel="stylesheet" type="text/css" href="templates/orderforms/cart/style.css" /><p align="center" class="cartheading">{$LANG.orderconfirmation}</p> <p>{$LANG.orderreceived}</p> <div class="cartbox"> <p align="center"><strong>{$LANG.ordernumberis} {$ordernumber}</strong></p> </div> <p>{$LANG.orderfinalinstructions}</p> {if $invoiceid && !$ispaid} <div class="errorbox">{$LANG.ordercompletebutnotpaid}</div> <p align="center"><a href="viewinvoice.php?id={$invoiceid}" target="_blank">{$LANG.invoicenumber}{$invoiceid}</a></p> {/if} {if $ispaid} <!-- Enter any HTML code which needs to be displayed once a user has completed the checkout of their order here - for example conversion tracking and affiliate tracking scripts --> {/if} <p align="center"><a href="clientarea.php">{$LANG.ordergotoclientarea}</a></p> {php} $orderid = $this->get_template_vars('orderid'); $userid = $_SESSION["uid"]; $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); $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-XXXXXXXX-X']); _gaq.push(['_setDomainName', MyOwnDomainName.eu]); _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']); {literal} (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> The only code I am able to find at the source for: https://www.myowndomain.eu/service/cart.php?a=complete is the below from the footer - should I not be able to se more? <scripttype="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X]); _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> 0 Quote Link to comment Share on other sites More sharing options...
datex Posted August 17, 2010 Author Share Posted August 17, 2010 It is really strange - it doesn't work. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted August 17, 2010 Share Posted August 17, 2010 Are you sure you're editing the correct complete.tpl that goes with your selected orderform template? 0 Quote Link to comment Share on other sites More sharing options...
datex Posted August 17, 2010 Author Share Posted August 17, 2010 Are you sure you're editing the correct complete.tpl that goes with your selected orderform template? I was thinking about the same. In the backend I have checked "Cart" - and I'm editing \templates\orderforms\cart\complete.tpl But should I not be able to see some of the code in the page when I'm checking out? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted August 17, 2010 Share Posted August 17, 2010 Did you clear your template cache? (the template_c directory) 0 Quote Link to comment Share on other sites More sharing options...
datex Posted August 17, 2010 Author Share Posted August 17, 2010 Did you clear your template cache? (the template_c directory) To be sure I just cleared the cache again - But I'm not able to see any code when checking out. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.