E-Commerce Tracking with Google Analytics with Interspire

If you are running an Interspire based Ecommerce application and you want your websites e-commerce transactions should also be tracked by Google Analytics .

Interspire has introduced this new feature with their existing code as well (from interspire 6.x). You can track all your Ecom transaction with very little modification in Google analytics module of interspire. Below are the steps you need to follow to enable it.

Step 1: Enable E-Commerce transaction . For more details you can read my previous article Ecommerce Tracking for your website with Google
Step 2: Make sure you are using new Google Analytics code (in which ga.sync=true)
Step 3: Open module.googleanalytics.php located in /modules/analytics/googleanalytics/ and make a backup of this becuase we will modify this as per below instruction

a. Find this

$(document).ready(function() {
if(typeof(pageTracker) != 'undefined') {
pageTracker._addTrans(

And replace it with

_gaq.push(['_addTrans',

b. Find this:

pageTracker._addItem(

Replace it with

_gaq.push(['_addItem',

c. Find this

pageTracker._trackTrans();
}
});

And reply this with

_gaq.push(['_trackTrans']);

d. Lastly, make sure you change the closing brackets for each of steps 1 and 2 above. Find the closing parenthesis:

);

And add a closing square bracket inside like this:

]);

Step 4:Check your final code. So the complete code should look like

$conversionCode = "
<script type="text/javascript">
_gaq.push(['_addTrans',
'".$order['orderid']."', // order ID
'',
'".number_format($this->GetTotalAmount(), 2, '.', '')."', // order total
'".number_format($this->GetTaxCost(), 2, '.', '')."', // tax
'".number_format($this->GetShippingCost(), 2, '.', '')."', // shipping
'".$billingAddress['ordbillsuburb']."', // suburb
'".$billingAddress['ordbillstate']."', // state
'".$billingAddress['ordbillcountry']."' // country
]);
";
while($product = $GLOBALS['ISC_CLASS_DB']->Fetch($productResult)) {
$productId = $product['ordprodid'];
if($product['ordprodvariationid'] > 0) {
$productId .= '-'.$product['ordprodvariationid'];
}
$prodCode = $product['ordprodsku'];
if (empty($prodCode)) {
$prodCode = $product['ordprodid'];
}

$conversionCode .= "
_gaq.push(['_addItem',
'".$order['orderid']."', // order ID
'".addslashes($prodCode)."', // SKU
'".addslashes($product['ordprodname'])."', // product name
'',
'".number_format($product['price_inc_tax'], 2, '.', '')."', // product price
'".$product['ordprodqty']."' // order quantity
]);
";
}
$conversionCode .= "
_gaq.push(['_trackTrans']);
</script>";

Step 5: Don’t forget to check templates/templatename/ordre.phtml that will insert actual code for ecommerce tracking

<!-- Include the conversion tracking code for all analytics packages -->
%%GLOBAL_ConversionCode%%

<!-- Google Code for Sale Conversion Page -->

Step 6. You have all set. Now make an order into interspire and check your finishorder.php file. In the view source of that file you can check for below source code.

<!-- Start conversion code for analytics_googleanalytics -->
<script type="text/javascript">
_gaq.push(['_addTrans',
'3', // order ID
'',
'17.99', // order total
'1.61', // tax
'4.00', // shipping
'New york', // city or sububrb
'New South Wales', // state or provence
'USA' // country
]);

_gaq.push(['_addItem',
'3', // order ID
'2732238', // SKU
'Product Name', // product name
'Cat Name',//Cat
'17.99', // product price
'1' // order quantity
]);

_gaq.push(['_trackTrans']);
</script>
<!-- End conversion code for analytics_googleanalytics -->

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...