Skip to content

Instantly share code, notes, and snippets.

View CartHookSupport's full-sized avatar

CartHook Support CartHookSupport

View GitHub Profile
@CartHookSupport
CartHookSupport / gist:2df575fe66dfc5283f1e056ed1a4b988
Last active July 30, 2019 23:23
How to Specify the Variant Sold on an Upsell/Downsell Page
(function () {
if ( typeof window.CustomEvent === "function" ) return false;
function CustomEvent ( event, params ) {
params = params || {
bubbles: false, cancelable: false, detail: null };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
window.CustomEvent = CustomEvent;
{{ event.Items.0.Name }}Quantity: {{ event.Items.0.Quantity }}
{{ event.Items.0.ImageURL }}
<script src="https://api.c.carthook.com/api/v1/integrations/shopify/fetch.js?shop=SOMESTORE.myshopify.com" type="text/javascript"></script>
<script src="https://api.c.carthook.com/api/v1/integrations/shopify/clear_cart.js?shop=SOMESTORE.myshopify.com" type="text/javascript"></script>
CH.event(function (event, data) {
if (event === 'INITIATED_PAGE') {
$('#buyer_accepts_marketing').prop('checked', false);
}
});
var GTMid = 'GTM-XXXXX'; // Your GTM id here
var orderId = window.chData.order.carthook_order_id;
var lastChargedLineItems = window.chData.order.last_charged_line_items;
window.dataLayer = window.dataLayer || [];
var transactionProducts = [];
var taxPrice = 0;
var subtotalPrice = 0;
for (var i = 0; i < lastChargedLineItems.length; i++) {
var item = lastChargedLineItems[i];
transactionProducts.push({
// 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:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
// Start of Littledata script
! function(e) {
var t = {};
function n(r) {
if (t[r]) return t[r].exports;
var o = t[r] = {
i: r,
l: !1,
exports: {}