Skip to content

Instantly share code, notes, and snippets.

@CartHookSupport
Created March 14, 2019 17:11
Show Gist options
  • Save CartHookSupport/a0774a1e34bcffb65c82d48061b17fe8 to your computer and use it in GitHub Desktop.
Save CartHookSupport/a0774a1e34bcffb65c82d48061b17fe8 to your computer and use it in GitHub Desktop.
// Google conversion.js code
// conversion_async.js must be used.
var lastChargedLineItems = window.chData.order.last_charged_line_items;
if (lastChargedLineItems.length > 0) {
$.getScript('https://www.googleadservices.com/pagead/conversion_async.js').then(function () {
var subTotal = 0;
for (var i = 0 ; i < lastChargedLineItems.length; i++) {
subTotal += lastChargedLineItems[i].price * lastChargedLineItems[i].quantity;
}
// Place any additional conversion values in this javascript object:
window.google_trackConversion({
google_conversion_id: YOUR_CONVERSION_ID,
google_conversion_label: "YOUR_CONVERSION_LABEL",
google_conversion_format: "3",
google_conversion_order_id: window.chData.order.carthook_order_id,
google_conversion_value: subTotal
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment