AdWords
2.5K members online now
2.5K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Edit Ecommerce tracking code

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi Everyone,

 

How could be edit ecommerce tracking code.  I have no idea regarding this kindly suggest me or provide editable code. Thanks in advance.  

 

-------------------------------------SAMPLE CODE------------------------------

 

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-********-1']);   //   GOOGLE ANALYTICS ID
_gaq.push(['_trackPageview']);

_gaq.push(['_addTrans',
'1234', // order ID - required
'Womens Apparel', // affiliation or store name
'28.28', // total - required                

 

// But how could we edit these string values provide some example for me reagrding these fields eg tax, shipping, city


'1.29', // tax
'15.00', // shipping
'San Jose', // city
'California', // state or province
'USA' // country
]);
_gaq.push(['_addItem',
'1234', // order ID - necessary to associate item with transaction
'DD44', // SKU/code - required
'T-Shirt', // product name
'Olive Medium', // category or variation
'11.99', // unit price - required
'1' // item quantity - required
]);
_gaq.push(['_trackTrans']);

(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);
})();

Marked as Best Answer.
Solution
Accepted by topic author Anil Guleria
September 2015

Re: Edit Ecommerce tracking code

Top Contributor Alumni
# 2
Top Contributor Alumni

Hi Anil

<?php
// Transaction Data
$trans
= array('id'=>'1234','affiliation'=>'Acme Clothing',
               
'revenue'=>'11.99','shipping'=>'5','tax'=>'1.29');

// List of Items Purchased.
$items
= array(
  array
('sku'=>'SDFSDF','name'=>'Shoes','category'=>'Footwear','price'=>'100','quantity'=>'1'),
  array
('sku'=>'123DSW','name'=>'Sandles','category'=>'Footwear','price'=>'87','quantity'=>'1'),
  array
('sku'=>'UHDF93','name'=>'Socks','category'=>'Footwear','price'=>'5.99','quantity'=>'2')
);
?>

You will need to work with PHP or any other server side scripting like example above and then pass the data to GA code like

<?php
// Function to return the JavaScript representation of a TransactionData object.
function getTransactionJs(&$trans){
 
return<<<HTML
ga
('ecommerce:addTransaction',{
 
'id':'{$trans['id']}',
 
'affiliation':'{$trans['affiliation']}',
 
'revenue':'{$trans['revenue']}',
 
'shipping':'{$trans['shipping']}',
 
'tax':'{$trans['tax']}'
});
HTML
;
}

// Function to return the JavaScript representation of an ItemData object.
function getItemJs(&$transId,&$item){
 
return<<<HTML
ga
('ecommerce:addItem',{
 
'id':'$transId',
 
'name':'{$item['name']}',
 
'sku':'{$item['sku']}',
 
'category':'{$item['category']}',
 
'price':'{$item['price']}',
 
'quantity':'{$item['quantity']}'
});
HTML
;
}
?>

The example I have given above is for Universal analytics but logic will be same for asynchronous code as well. If you are not a coder then you can either get a coders help to write this code or if you are using a shopping cart software like magento , Oscommerce, etc most of shopping carts have some module/plugin which actually takes care of this automatically without you writing any code.

Hope this helps

 

 

 

Regards, Nik
LinkedIn  |   @nikhilparachure | My Blog