function startMouseflow() { window._mfq = window._mfq || []; (function() { var mf = document.createElement("script"); mf.type = "text/javascript"; mf.defer = true; mf.src = "//cdn.mouseflow.com/projects/YOUR_WEBSITE_ID.js"; document.getElementsByTagName("head")[0].appendChild(mf); })(); } const website_url = 'YOUR_WEBSITE_URL'; if (document.location.pathname.indexOf('/checkouts/') > -1 && document.location.pathname.indexOf('/thank_you/') == -1) { window.mouseflowHref = 'https://' + website_url + '/checkout'; startMouseflow(); analytics.subscribe("checkout_started", (event) => { const checkout = event.data.checkout; const allDiscountCodes = checkout.discountApplications.map((discount) => { if (discount.type === 'DISCOUNT_CODE') { window._mfq.push(['setVariable', 'discount_code', discount.title]); } }); }); analytics.subscribe('checkout_contact_info_submitted', (event) => { window._mfq.push(['tag', 'contact_info_submitted']); }); analytics.subscribe("payment_info_submitted", (event) => { window._mfq.push(['tag', 'payment_info_submitted']); }); analytics.subscribe('checkout_shipping_info_submitted', (event) => { window._mfq.push(['tag', 'shipping_info_submitted']); const checkout_info = event.data.checkout; const shippingLine = checkout_info.shippingLine; const ship_price = shippingLine.price.amount; window._mfq.push(['setVariable', 'shipping_total', ship_price]); }); analytics.subscribe("checkout_completed", (event) => { window._mfq.push(['tag', 'checkout_completed']); window._mfq.push(['setVariable', 'final_purchase_total', event.data?.checkout?.totalPrice?.amount]); const currency = event.data.checkout.currencyCode; window._mfq.push(['setVariable', 'currency', currency]); const paymentTransactions = event.data.checkout.transactions.map((transaction) => { window._mfq.push(['setVariable', 'payment_provider', transaction.gateway]); }); const cid = event.data.checkout.order.id; window._mfq.push(['setVariable', 'order_id', cid]); }); }if (document.location.pathname.indexOf('thank_you') > -1) { window.mouseflowHref = 'https://' + website_url + '/thank_you'; startMouseflow(); }if(document.location.pathname.indexOf('/orders/') > -1){ window.mouseflowHref = 'https://' + website_url + '/order_status'; startMouseflow(); }