(function(shopify) {shopify.extend('WebPixel::Render', function(api) { var analytics=api.analytics,browser=api.browser,init=api.init; //Google Tag Manager (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-W6JMR9F'); //End Google Tag Manager // Define dataLayer and the gtag function. window.dataLayer = window.dataLayer || []; //Listrak Analytics – Javascript Framework var biJsHost = (("https:" == document.location.protocol) ? "https://" : "http://"); (function (d, s, id, tid, vid) { var js, ljs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = biJsHost + "cdn.listrakbi.com/scripts/script.js?m=" + tid + "&v=" + vid; ljs.parentNode.insertBefore(js, ljs); })(document, 'script', 'ltkSDK', 'Pz3VsyOi96zI', '1'); //Listrak Analytics – Javascript Framework analytics.subscribe("checkout_completed", event => { console.log("checkout_completed started"); //Listrak (function(d) { if (document.addEventListener) document.addEventListener('ltkAsyncListener', d); else {e = document.documentElement; e.ltkAsyncProperty = 0; e.attachEvent('onpropertychange', function (e) { if (e.propertyName == 'ltkAsyncProperty'){d();}});}})(function() { _ltk_util.ready(function(){ /********** Begin Custom Code **********/ /** Handle ORDER **/ _ltk.Order.SetCustomer(event.data.checkout.email, event.data.checkout.billingAddress.firstName, event.data.checkout.billingAddress.lastName); _ltk.Order.OrderNumber = event.data.checkout.order.id; _ltk.Order.ItemTotal = event.data.checkout.subtotalPrice.amount; _ltk.Order.ShippingTotal = event.data.checkout.shippingLine.price.amount; _ltk.Order.TaxTotal = event.data.checkout.totalTax.amount; _ltk.Order.HandlingTotal = '0.00'; _ltk.Order.OrderTotal = event.data.checkout.totalPrice.amount; _ltk.Order.Currency = event.data.checkout.currencyCode; for(var item of event.data.checkout.lineItems){ _ltk.Order.AddItem(_ltk.Shopify.GetSkuProperty( item.variant.product.id , item.variant.sku ), item.quantity, item.variant.price.amount); } _ltk.Order.Submit(); /** Handle Checkout Subscription **/ if (event.data.checkout.buyerAcceptsEmailMarketing) { _ltk.Subscriber.List = 'Checkout'; _ltk.Subscriber.Email = event.data.checkout.email; _ltk.Subscriber.Profile.Add('ltkSource', 'On'); _ltk.Subscriber.Profile.Add('first_name', event.data.checkout.billingAddress.firstName); _ltk.Subscriber.Profile.Add('last_name', event.data.checkout.billingAddress.lastName); _ltk.Subscriber.Profile.Add('city', event.data.checkout.billingAddress.city); _ltk.Subscriber.Profile.Add('zip', event.data.checkout.billingAddress.zip); _ltk.Subscriber.Profile.Add('state', event.data.checkout.billingAddress.province); _ltk.Subscriber.Profile.Add('country', event.data.checkout.billingAddress.country); _ltk.Subscriber.Profile.Add('phone', event.data.checkout.billingAddress.phone); _ltk.Subscriber.Submit(); } /********** End Custom Code **********/ })}); //END Listrak //GTM var orderItems = []; var newOrderItems = []; var orderqty=0; for(var gitem of event.data.checkout.lineItems){ var orderItem = { 'id': gitem.variant.product.id, 'quantity': gitem.quantity }; orderItems.push(orderItem); var newOrderItem = { "name": gitem.title, "id": gitem.variant.sku, "productId": gitem.variant.product.id, "price": gitem.variant.price.amount, "brand": gitem.variant.product.vendor, "category": gitem.variant.product.vendor, "variant": "", "shopifyId": gitem.variant.product.id, "quantity": gitem.quantity }; orderqty += parseInt(gitem.quantity); newOrderItems.push(newOrderItem); } window.dataLayer.push({ 'event': 'purchase', 'CustomerId': event.data.checkout.order.customer.id, 'customerEmail': event.data.checkout.email, 'customerName' : event.data.checkout.billingAddress.firstName, 'CustomerFirstName': event.data.checkout.billingAddress.firstName, 'CustomerLastName' : event.data.checkout.billingAddress.lastName, 'CustomerPhone' : event.data.checkout.billingAddress.phone, 'CustomerAddress1': event.data.checkout.billingAddress.address1, 'CustomerAddress2' : event.data.checkout.billingAddress.address2, 'CustomerCity': event.data.checkout.billingAddress.city, 'CustomerProvince': event.data.checkout.billingAddress.province, 'CustomerZip': event.data.checkout.billingAddress.zip, 'CustomerCountryCode': event.data.checkout.billingAddress.countryCode, 'transactionId': event.data.checkout.order.id, 'transactionAffiliation': 'Global-e', 'transactionTotal': event.data.checkout.totalPrice.amount, 'transactionCurrency' : event.data.checkout.currencyCode, 'transactionTax': event.data.checkout.totalTax.amount, 'transactionShipping': event.data.checkout.shippingLine.price.amount, 'transactionProducts': orderItems, 'ecommerce': { 'currencyCode': event.data.checkout.currencyCode, 'purchase': { 'actionField': { 'id': event.data.checkout.order.id, 'revenue': event.data.checkout.totalPrice.amount, 'tax': event.data.checkout.totalTax.amount, 'shipping': event.data.checkout.shippingLine.price.amount, 'affiliation': "Global-e", 'discountAmount': 0, 'action': "purchase" }, 'products': newOrderItems, 'orderqty': orderqty } } }) }); });})(self.webPixelsManager.createShopifyExtend('29458585', 'custom'));