Google e-commerce tracking modification for Tradingeye and UK2.net ecommerce package
November 16th, 2008
his modification is for Tradingeye accessible e-commerce system and the latest UK2.net E-commerce package to help you track visitor movement through checkout pages. To get better understanding and the benefit of this feature, please refer to these 2 article as below:

1. Google Ecommerce Tracking Code
Now, please follow these steps
Step 1: Enabling E-Commerce Reporting in the Profile
The first step of tracking e-commerce transactions is to enable e-commerce reporting for your website’s profile. To enable e-commerce reporting, please follow these steps:
Log in to your account.
Click Edit next to the profile you’d like to enable.
On the Profile Settings page, click edit next to Main Website Profile Information.
Change the E-Commerce Website radio button from No to Yes.
Step 2: Receipt Page Format
Tradingeye and UK2.net payment process is slightly different from others. Once customer completed their transaction, he will be taken to an acknowlegdement (thank-you) page rather than a receipt page. He then has to click on the link “view your receipt” to see his receipt. Thus, we need to modifify these following files:
/modules/ecom/templates/main/orderProcessed.tpl.htm
/modules/ecom/classes/main/receipt.php
Lets get the ball rolling!
2.1: Place this code below at the bottom of the file orderProcessed.tpl.htm
<pre lang=”html”><!– BEGIN TPL_GOOGLE_ECOMMERCE_TRACKING_BLOCK –>
<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”><!–
var pageTracker = _gat._getTracker(“UA-4440573-2″);
pageTracker._initData();
pageTracker._addTrans(
“{TPL_VAR_ORDER_ID}”, // order ID – required
“{TP_VAR_STORE_NAME}”, // affiliation or store name
“{TPL_VAR_TOTAL}”, // total – required
“{TPL_VAR_TAX_TOTAL}”, // tax
“{TPL_VAR_SHIPPING_COST}”, // shipping
“{TPL_VAR_CITY}”, // city
“{TPL_VAR_COUNTY}”, // state or province
“{TPL_VAR_COUNTRY}” // country
);
// add items might be called for every item in the shopping cart
<! BEGIN TPL_GOOGLE_ADDITEM_BLK –>
pageTracker._addItem(
“{TPL_VAR_ORDER_ID}”, // order ID – required
“{TPL_VAR_SKU_CODE}”, // SKU/code
“{TPL_VAR_PRODUCT_TITLE}”, // product name
“{TPL_VAR_CATEGORY}”, // category or variation
“{TPL_VAR_PRODUCT_PRICE}”, // unit price – required
“{TPL_VAR_QUANTITY}” // quantity – required
);
<!– END TPL_GOOGLE_ADDITEM_BLK –>
pageTracker._trackTrans(); //submits order info in hidden form after page load
// –></script>
<!– END TPL_GOOGLE_ECOMMERCE_TRACKING_BLOCK –></pre>
You need to replace this “UA-xxxxxx-xx” to your own Google Tracking ID
2.2: Modify the receipt.php class.
Under the method (function) m_orderProcessed()
At Line 47, Look for:
<pre lang=”php”>
#DECLARE BLOCKS $this->ObTpl->set_block(“TPL_ORDER_FILE”,”TPL_ORDERSTATUS_BLK”,”orderstatus_blk”);
$this->ObTpl->set_block(“TPL_ORDER_FILE”,”TPL_BACKORDER_BLK”,”backorder_blk”);
<pre>
And add:
<pre lang=”php”>
$this->ObTpl->set_block(“TPL_ORDER_FILE”,”TPL_GOOGLE_ECOMMERCE_TRACKING_BLOCK”,”google_blk”);
$this->ObTpl->set_block(“TPL_GOOGLE_ECOMMERCE_TRACKING_BLOCK”,”TPL_GOOGLE_ADDITEM_BLK”,”item_blk”);
$this->ObTpl->set_var(“google_blk”,”");
$this->ObTpl->set_var(“item_blk”,”");
</pre>
Look for this comment
#FLAG TO INDICATE SEPERATE BACKORDER AND NORMAL ORDER
and replace all the code from there to
<pre lang=”php”>$this->ObTpl->set_var(“TPL_VAR_BACKORDERURL”,$backOrderUrl);</pre>
by the code below:
<pre lang=”php”>#FLAG TO INDICATE SEPERATE BACKORDER AND NORMAL ORDER
$_SESSION['backOrderSeperate']=$this->libFunc->ifSet($_SESSION,’backOrderSeperate’,'0′);
$this->obDb->query = “SELECT count(*) as cnt FROM “.TEMPCART.” WHERE vSessionId=’”.$this->sessionId.”‘”;
$rowCount=$this->obDb->fetchQuery();
if($_SESSION['backOrderSeperate']==1 && $rowCount[0]->cnt>0)
{
$this->ObTpl->parse(“backorder_blk”,”TPL_BACKORDER_BLK”);
}
else
{
#GETTING INVOICE DETAIL AND ADD TO GOOGLE ECOMMERCE API
$this->obDb->query = “SELECT tmOrderDate,vPayMethod,vShipDescription,fShipTotal,”;
$this->obDb->query.= “vFirstName,vLastName,vEmail,vAddress1,vAddress2,vCity,iInvoice,”;
$this->obDb->query.= “vState,vStateName,vCountry,vZip,vCompany,vPhone,vHomepage,”;
$this->obDb->query.= “vAltPhone,fCodCharge,fPromoValue,”;
$this->obDb->query.= “vDiscountCode,fDiscount,iGiftcert_FK,fGiftcertTotal,fMemberPoints,”;
$this->obDb->query.= “fTaxRate,fTaxPrice,tComments,vStatus,iPayStatus,fTotalPrice,iEarnedPoints,iCustomerid_FK”;
$this->obDb->query .= ” FROM “.ORDERS.” WHERE iOrderid_PK=’”.$this->request['mode'].”‘”;
$qryResult = $this->obDb->fetchQuery();
$rCount=$this->obDb->record_count;
if($rCount!=1)
{
$errrorUrl=SITE_URL.”index.php?action=error&mode=order”;
$this->libFunc->m_mosRedirect($this->libFunc->m_safeUrl($errrorUrl));
}
#PARSING VALUE TO TEMPLATE VARIABLE
$this->ObTpl->set_var(“TPL_VAR_ORDER_ID”,$this->libFunc->m_displayContent($qryResult[0]->iInvoice));
$this->ObTpl->set_var(“TP_VAR_STORE_NAME”,SITE_NAME);
$this->ObTpl->set_var(“TPL_VAR_TOTAL”,$qryResult[0]->fTotalPrice);
$this->ObTpl->set_var(“TPL_VAR_TAX_TOTAL”,0);
$this->ObTpl->set_var(“TPL_VAR_SHIPPING_COST”,$qryResult[0]->fShipTotal);
$this->ObTpl->set_var(“TPL_VAR_CITY”,$this->libFunc->m_displayContent($qryResult[0]->vCity));
$this->ObTpl->set_var(“TPL_VAR_COUNTY”,$this->libFunc->m_displayContent($qryResult[0]->vZip));
$this->ObTpl->set_var(“TPL_VAR_COUNTRY”,$this->libFunc->m_displayContent($qryResult[0]->vFirstName));
#GETTING PRODUCTS DETAIL AND ADD TO GOOGLE API
$this->obDb->query = “SELECT iOrderProductid_PK,iProductid_FK,iQty,OP.fPrice,”;
$this->obDb->query.= “fDiscount,OP.vTitle,OP.vSku,OP.iKit,OP.tShortDescription,OP.vSeoTitle, “;
$this->obDb->query.=”OP.iTaxable,OP.iFreeship,vPostageNotes,vDownloadablefile “;
$this->obDb->query .= ” FROM “.ORDERPRODUCTS.” OP INNER JOIN “.PRODUCTS.” P ON OP.iProductid_FK=P.iProdId_PK WHERE iOrderid_FK=’”.$this->request['mode'].”‘”;
$rsOrderProduct=$this->obDb->fetchQuery();
$rsOrderProductCount=$this->obDb->record_count;
if ($rsOrderProductCount >0){
for($i=0;$i< $rsOrderProductCount;$i++){
#PARSING VALUE TO TEMPLATE VARIABLE
$this->ObTpl->set_var(“TPL_VAR_PRODUCT_TITLE”,$this->libFunc->m_displayContent($rsOrderProduct[$i]->vTitle));
$this->ObTpl->set_var(“TPL_VAR_SKU_CODE”,$this->libFunc->m_displayContent($rsOrderProduct[$i]->vSku));
$this->ObTpl->set_var(“TPL_VAR_PRODUCT_PRICE”,number_format($rsOrderProduct[$i]->fPrice,2,’.',”));
$this->ObTpl->set_var(“TPL_VAR_QUANTITY”,$rsOrderProduct[$i]->iQty);
$this->ObTpl->set_var(“TPL_VAR_ORDER_ID”,$this->libFunc->m_displayContent($qryResult[0]->iInvoice));
$this->ObTpl->set_var(“TPL_VAR_CATEGORY”,”"); # INITILISE CATEGORY NAME
#GETTING CATEGORY NAME BASED ON PRODUCT ID
/*
PLEASE NOTE: A PRODUCT COULD BE ASSOCIATED TO MANY DEPARTMENTS OR HOMEPAGE THEREFORE WE WILL GET
THE CATEGORY WHICH THAT PRODUCT WAS INITIALLY CREATED FROM.
*/
$this->obDb->query = ” SELECT fusionId, iOwner_FK, iOwner_FK, vtype, iState, vOwnerType “;
$this->obDb->query .= ” FROM ” .FUSIONS . ” WHERE iSubId_FK = ‘”.$rsOrderProduct[$i]->iProductid_FK .”‘”;
$this->obDb->query .= ” AND vOwnerType =’department’ AND iState =’1′ AND iOwner_FK >0 ORDER BY fusionId”;
$rsFusion=$this->obDb->fetchQuery();
if ($this->obDb->record_count > 0){
#ASSIGN THE FIRST RECORD TO CATEGORY ID
$deptId = $rsFusion[0]->iOwner_FK;
$this->obDb->query = ” SELECT iDeptid_PK, vTitle FROM “. DEPARTMENTS . ” WHERE iDeptid_PK = ‘”. $deptId .”‘”;
$rsDept =$this->obDb->fetchQuery();
$this->ObTpl->set_var(“TPL_VAR_CATEGORY”,$this->libFunc->m_displayContent($rsDept[0]->vTitle));
}#if
#PARSE PRODUCTS DETAIL TO GOOGLE E-COMMERCE API
$this->ObTpl->parse(“item_blk”,”TPL_GOOGLE_ADDITEM_BLK”,true);
}#for loop
}#if $rsOrderProductCount
$this->ObTpl->parse(“google_blk”,”TPL_GOOGLE_ECOMMERCE_TRACKING_BLOCK”);
$this->ObTpl->parse(“orderstatus_blk”,”TPL_ORDERSTATUS_BLK”);
}
$backOrderUrl=$this->libFunc->m_safeUrl(SITE_URL.”ecom/index.php?action=checkout.backorder”);
$this->ObTpl->set_var(“TPL_VAR_BACKORDERURL”,$backOrderUrl);
</pre>
Notice
1. If your shop is using Off-site payment gateway such as Paypal or GoogleCheckout, it is required your customer going back to the merchant site otherwise no record is tracked.
2. The modified m_orderProcessed() method is also availablet to download from the link at bottom of the post.
Enjoy!
You might interested in all Related Posts
Categories: E-commerce, Games, PHP, Tradingeye & UK2 Ecommerce, Viva, Web development | Tags: google analytics, Google Conversion Tracking, google ecommerce tracking code, google-ecommerce-tracking, google-ecommerce-tradingeye-uk2-net, Tradingeye google conversion tracking code, tradingeye-customisation




Hi – you say: At line 60, please replace this code…
and you display all the code to replace, but replace with what?
Thanks
@Asparagus: from line 60, you should replace all the code start from the comment line
#FLAG TO INDICATE …
to the line
$this->ObTpl->set_var(“TPL_VAR_BACKORDERURL”,$backOrderUrl);
Hope that makes sense
Thanks – I didn;t quite understand as line 60 for my file is different; perhaps the Trading Eye file has additional line spacing, but I will give it a go – really appreciate this as Google Ecom Tracking is really useful.
One problem I am having with trading eye system is getting the purchase page setup as a Goal in Analytics, have you managed to resolve this? I am using Regular Expression match but it doesn’t seem to pick up the page as a goal…
I have attached the .zip file at the bottom of the post which contains the code of m_orderProcessed() method .. you can easily replace it for your current m_orderProcessed method.
Refer to your second point: you can try to use “head match” with the Goal Url is http://www.your-domain-name.com/eaction/checkout.status/
lets me know if it works for you
This is all great – thanks alot I will give it a try now. I did the cut and paste and in Google Ecommerce I had a real transation show up BUT there was no internal data when I clicked into it so I am sure I messed up somewhere.
Argh – so frustrating HA HA.
I added the code you gave and it was as I had it… ok here’s what I’ev noticed when I order… It’s picking up a transaction BUT the variables aren;t being populated so it’s sending {VARIABLE} see below what my source code looks like on my receipt page…
// <!–
var pageTracker = _gat._getTracker(“UA-6249322-1″);
pageTracker._initData();
pageTracker._addTrans(
“{TPL_VAR_ORDER_ID}”, // order ID – required
“{TP_VAR_STORE_NAME}”, // affiliation or store name
“{TPL_VAR_TOTAL}”, // total – required
“{TPL_VAR_TAX_TOTAL}”, // tax
“{TPL_VAR_SHIPPING_COST}”, // shipping
“{TPL_VAR_CITY}”, // city
“{TPL_VAR_COUNTY}”, // state or province
“{TPL_VAR_COUNTRY}” // country
);
// add items might be called for every item in the shopping cart
pageTracker._addItem(
“{TPL_VAR_ORDER_ID}”, // order ID – required
“{TPL_VAR_SKU_CODE}”, // SKU/code
“{TPL_VAR_PRODUCT_TITLE}”, // product name
“{TPL_VAR_CATEGORY}”, // category or variation
“{TPL_VAR_PRODUCT_PRICE}”, // unit price – required
“{TPL_VAR_QUANTITY}” // quantity – required
);
pageTracker._trackTrans(); //submits order info in hidden form after page load
// –>
Also noticed, the Thank you page no longer says CLick here to view your invoice – I’m sure that used to be there…
Looks like the javascripts literally writing out the variables and the PHP Block isn’t populating them.
Ok ignore that – looks like the server wasn’t using the latest version of the PHP, I thought it said 1 FILE UPLOADED, it had said 1 FILE NOT UPLOADED.
Ok right looks like we are cooking on gas – much appreciated with all your efforts!
Nice one John
not a problem atall !
Cheers,
Dave
Hi Dave, one thing I’ve noticed… tracking is working by the way, BUT. I have a product which has 2 options small & large, each with a different value.
The small bag (the default product) has a unit price of 75p the large bag is £10.
In the info being sent to Google if a large bag is ordered it is sending the unit price and not the product price – so the product price is the unit price plus the additional cost for the product option.
So as you can see only the base value gets passed to google and all orders so far are being tracked as 75p even if the different option (£10) is being selected.
ah, I made this customisation for a shop selling products without product options so no product’s option price is added. You can modify the code a bit to make it works and I recommend you to take a look at the method to display the basket or review page!
m_reviewCheckout() in \modules\ecom\classes\main\review.php
or m_viewCart in \modules\ecom\classes\main\shop_interface.php
Maybe I am being completely stupid, but if I download the m_order file, what do I do with it? Do I still need to edit the review.php file? When I edit as per the instructions I get a black screen on the webpage?
Help!
HI Robbie, once you download the file.. you just need to overwrite your m_orderProcessed() method with my edited one. You should find the m_orderProcessed() method under review.php file.
Hope it has help
Dave
I’m not really sure what you mean by method?
*confused*
I meant the function m_orderProcessed()
Thanks for posting this modification for the Tradingeye community.
When I first tried to install using just the instructions from this page I ended up with the white screen of death. Then when I copied the code from the file in the download the error seemed to go away.
I’ve only just done this now so cannot see if it’s working until my analytics gets updated.
@Scot: thanks for passing by and hope you find the post useful.
This customisation has been created long time ago so if you found any bug, please do let me know ;D