-
-
Save aspencer/b57097b6696725cbb3dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
This code is in the HEAD of the completed page | |
--> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-123123123-11']); | |
_gaq.push(['_trackPageview']); | |
rp_app.track.add_tracker(false, 'gaq', 'customer'); | |
_gaq.push(['rollup._setAccount', 'UA-999999999-1']); | |
_gaq.push(['rollup._trackPageview']); | |
rp_app.track.add_tracker('rollup', 'gaq', 'rp'); | |
var virtual_page_type = 'checkout/completed'; | |
_gaq.push(['virtual._setAccount', 'UA-999999999-2']); | |
_gaq.push(['virtual._trackPageview', virtual_page_type]); | |
rp_app.track.add_tracker('virtual', 'gaq', 'rp'); | |
//]]> | |
</script> | |
<!-- | |
This code is in the BODY of the order completed page | |
--> | |
<script type="text/javascript"> | |
rp_app.track.transaction = { | |
order_num: '7047561', | |
affiliation: '', | |
revenue: '115.06', | |
shipping: '10.43', | |
tax: '0.00', | |
city: 'CHANDLER', | |
region: 'Arizona', | |
country: 'United States', | |
items: [] | |
}; | |
rp_app.track.transaction.items.push({ | |
name: 'PUMP', | |
sku: '25110-2G500', | |
category: 'Custom Category', | |
price: '104.63', | |
quantity: '1' | |
}); | |
rp_app.track.track_transaction('all'); | |
</script> | |
<script type="text/javascript"> | |
/* <![CDATA[ */ | |
var google_conversion_id = 999999; | |
var google_conversion_language = "en_US"; | |
var google_conversion_format = "3"; | |
var google_conversion_color = "ffffff"; | |
var google_conversion_label = "FOOBAR"; | |
var google_conversion_value = '115.06'; | |
/* ]]> */ | |
</script> | |
<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js"> | |
</script> | |
<noscript> | |
<img height="1" width="1" border="0" src="https://www.googleadservices.com/pagead/conversion/FOO/?value=115.06&label=BAR&guid=ON&script=0"/> | |
</noscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Code here only semi-complete. Snipped for relevance | |
// | |
rp_app.track.track_transaction = function(name) { | |
'use strict'; | |
var trackers, tracker, i, j; | |
trackers = this.get_trackers(name); | |
for(i = 0, j = trackers.length; i < j; i++) { | |
tracker = trackers[i]; | |
tracker.track_transaction(); | |
} | |
}; | |
rp_app.Tracker = function(tracker_name, tracker_type, owner) { | |
'use strict'; | |
this.name = tracker_name; | |
this.type = tracker_type; | |
this.owner = owner; | |
}; | |
rp_app.Tracker.prototype.get_tracker_prefix = function() { | |
'use strict'; | |
return (this.name === 'default') ? '' : this.name+'.'; | |
}; | |
rp_app.Tracker.prototype.track_transaction = function() { | |
'use strict'; | |
if(rp_app.track.transaction) { | |
switch(this.type) { | |
case 'ua': | |
this.ua_transaction(); | |
break; | |
case 'gaq': | |
/* falls through */ | |
default: | |
this.gaq_transaction(); | |
} | |
} | |
}; | |
/* Transactions | |
.*-----------------------------------------*/ | |
rp_app.Tracker.prototype.gaq_transaction = function() { | |
'use strict'; | |
var tracker_prefix, transaction, item, i, j; | |
/* Set up the Tracker Prefix | |
.*-----------------------------------------*/ | |
tracker_prefix = this.get_tracker_prefix(); | |
transaction = rp_app.track.transaction; | |
if(!transaction) { return; } | |
/* Build Transaction | |
.*-----------------------------------------*/ | |
_gaq.push([tracker_prefix+'_addTrans', | |
transaction.order_num, // order ID - required | |
transaction.affiliation, // affiliation or store name | |
transaction.revenue, // total - required | |
transaction.tax, // tax | |
transaction.shipping, // shipping | |
transaction.city, // city | |
transaction.region, // state or province | |
transaction.country // country | |
]); | |
/* Loop through items and add them to the transaction | |
.*-----------------------------------------*/ | |
for(i = 0, j = transaction.items.length; i < j; i++) { | |
item = transaction.items[i]; | |
_gaq.push([tracker_prefix+'_addItem', | |
transaction.order_num, // order ID - required | |
item.sku, // SKU/code - required | |
item.name, // product name | |
item.category, // category or variation | |
item.price, // unit price - required | |
item.quantity // quantity - required | |
]); | |
} | |
/* Submit Transaction to GA Servers | |
.*-----------------------------------------*/ | |
_gaq.push([tracker_prefix+'_trackTrans']); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment