Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robwilliams/304503 to your computer and use it in GitHub Desktop.
Save robwilliams/304503 to your computer and use it in GitHub Desktop.
// revenue tracking
$(function(){
if($('.receipt_order_id')) {
var order_id = $('.receipt_order_id').text();
var total = $('.receipt_total').text().replace(/[^0-9]/, '');
var tax = $('.receipt_tax').text().replace(/[^0-9]/, '');
var shipping = $('.receipt_shipping').text().replace(/[^0-9]/, '');
var town = $('.receipt_town').text();
var county = $('.receipt_county').text();
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
var pageTracker = _gat._getTracker("YOURKEY");
pageTracker._setDomainName("none");
pageTracker._initData();
pageTracker._addTrans(
order_id, // Order ID
'', // Affiliation
total, // Total
tax, // Tax
shipping, // Shipping
town, // City
county, // State
"UK" // Country
);
$('.receipt_line').each(function(index){
strip_pattern = /\s/;
reference = $('.receipt_reference', this).text().replace(strip_pattern, '');
name = $('.receipt_name', this).text().replace(strip_pattern, '');
price = $('.receipt_price', this).text().replace(/[^0-9]/, '');
quantity = $('.receipt_quantity', this).text().replace(/[^0-9]/, '');
pageTracker._addItem(
order_id, // Order ID
reference, // SKU
name, // Product Name
"ink", // Category
price, // Price
quantity // Quantity
);
});
pageTracker._trackTrans();
pageTracker._trackPageview('/checkout/receipt.html');
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment