//var log=""; var shopHost = 'chesca1424'; var shopUrl = 'https://chescadirect.co.uk'; var adwordsConfigAccount = 'AW-409145326'; var adwordsSendToAccount = 'AW-409145326'; var mcAccount = '352539822'; var analyticsAccount = 'null'; var addToCartLabel = 'Jb9hCKe0lfkBEO6fjMMB'; var facebookPixel = '899154257527247'; var googleCurrency = 'GBP'; var facebookCurrency = 'GBP'; var adscale_currency = 'GBP'; var ratesGoogle={"FJD":0.3519,"MXN":0.04643,"STD":4.0E-5,"LVL":1.30615,"SCR":0.05837,"CDF":2.9E-4,"BBD":0.3926,"GTQ":0.10148,"CLP":8.2E-4,"HNL":0.0321,"UGX":2.0E-4,"ZAR":0.04145,"TND":0.25282,"SLE":0.03489,"CUC":0.79008,"BSD":0.79267,"SLL":4.0E-5,"SDG":0.00131,"IQD":6.1E-4,"CUP":0.02981,"GMD":0.01163,"TWD":0.02502,"RSD":0.00732,"DOP":0.0135,"KMF":0.00174,"MYR":0.16649,"FKP":0.9995,"XOF":0.00131,"GEL":0.2981,"BTC":49042.59257,"UYU":0.02025,"MAD":0.07872,"CVE":0.00778,"TOP":0.33295,"AZN":0.46367,"OMR":2.05236,"PGK":0.20785,"KES":0.00549,"SEK":0.07626,"BTN":0.00956,"UAH":0.02077,"GNF":9.0E-5,"ERN":0.05267,"MZN":0.01244,"SVC":0.0906,"ARS":9.4E-4,"QAR":0.21701,"IRR":2.0E-5,"CNY":0.10978,"THB":0.02215,"UZS":6.0E-5,"XPF":0.00717,"MRU":0.0198,"BDT":0.00722,"LYD":0.16413,"BMD":0.79008,"KWD":2.56682,"PHP":0.0141,"RUB":0.00862,"PYG":1.1E-4,"ISK":0.00572,"JMD":0.00508,"COP":2.0E-4,"MKD":0.01392,"USD":0.79008,"DIN":0.00732,"DZD":0.00586,"PAB":0.79267,"GGP":0.9995,"SGD":0.5875,"ETB":0.01404,"JEP":0.9995,"KGS":0.00884,"SOS":0.00138,"VEF":0.0,"VUV":0.00656,"LAK":4.0E-5,"BND":0.58876,"ZMK":9.0E-5,"TZA":3.1E-4,"XAF":0.00131,"LRD":0.00411,"XAG":18.29983,"CHF":0.8935,"HRK":0.11238,"ALL":0.00825,"DJF":0.00445,"VES":0.02193,"ZMW":0.03362,"TZS":3.1E-4,"VND":3.0E-5,"XAU":1645.99375,"TRL":0.02517,"AUD":0.51631,"ILS":0.22155,"GHS":0.06242,"GYD":0.00379,"KPW":8.8E-4,"BOB":0.11471,"KHR":1.9E-4,"MDL":0.04461,"IDR":5.0E-5,"KYD":0.95119,"AMD":0.00196,"BWP":0.05755,"SHP":0.62321,"TRY":0.02517,"LBP":1.0E-5,"TJS":0.07239,"JOD":1.11429,"AED":0.2151,"HKD":0.10092,"RWF":6.1E-4,"EUR":0.85728,"LSL":0.04136,"DKK":0.11489,"ZWD":0.00245,"CAD":0.58173,"BGN":0.43767,"MMK":3.8E-4,"MUR":0.01725,"NOK":0.07481,"SYP":6.0E-5,"IMP":0.9995,"ZWL":0.00245,"ROL":0.17235,"GIP":0.9995,"RON":0.17235,"LKR":0.00257,"NGN":5.0E-4,"CRC":0.00155,"CZK":0.03378,"PKR":0.00284,"XCD":0.29235,"ANG":0.43983,"HTG":0.00598,"BHD":2.10296,"KZT":0.00175,"SRD":0.02232,"SZL":0.04136,"LTL":0.26757,"SAR":0.21067,"TTD":0.11681,"YER":0.00316,"MVR":0.05129,"AFN":0.01095,"INR":0.00954,"AWG":0.43832,"KRW":5.9E-4,"NPR":0.00598,"JPY":0.00526,"MNT":2.3E-4,"AOA":9.5E-4,"PLN":0.19834,"GBP":1.0,"SBD":0.09321,"BYN":0.24222,"HUF":0.00217,"BYR":4.0E-5,"BIF":2.8E-4,"MWK":4.7E-4,"MGA":1.8E-4,"XDR":1.052,"BZD":0.39326,"BAM":0.43849,"EGP":0.02561,"MOP":0.09831,"NAD":0.04136,"NIO":0.02154,"PEN":0.20964,"NIS":0.22155,"NZD":0.48242,"WST":0.29016,"TMT":0.22509,"CLF":22.54529,"BRL":0.15946}; var ratesFacebook={"FJD":0.3519,"MXN":0.04643,"STD":4.0E-5,"LVL":1.30615,"SCR":0.05837,"CDF":2.9E-4,"BBD":0.3926,"GTQ":0.10148,"CLP":8.2E-4,"HNL":0.0321,"UGX":2.0E-4,"ZAR":0.04145,"TND":0.25282,"SLE":0.03489,"CUC":0.79008,"BSD":0.79267,"SLL":4.0E-5,"SDG":0.00131,"IQD":6.1E-4,"CUP":0.02981,"GMD":0.01163,"TWD":0.02502,"RSD":0.00732,"DOP":0.0135,"KMF":0.00174,"MYR":0.16649,"FKP":0.9995,"XOF":0.00131,"GEL":0.2981,"BTC":49042.59257,"UYU":0.02025,"MAD":0.07872,"CVE":0.00778,"TOP":0.33295,"AZN":0.46367,"OMR":2.05236,"PGK":0.20785,"KES":0.00549,"SEK":0.07626,"BTN":0.00956,"UAH":0.02077,"GNF":9.0E-5,"ERN":0.05267,"MZN":0.01244,"SVC":0.0906,"ARS":9.4E-4,"QAR":0.21701,"IRR":2.0E-5,"CNY":0.10978,"THB":0.02215,"UZS":6.0E-5,"XPF":0.00717,"MRU":0.0198,"BDT":0.00722,"LYD":0.16413,"BMD":0.79008,"KWD":2.56682,"PHP":0.0141,"RUB":0.00862,"PYG":1.1E-4,"ISK":0.00572,"JMD":0.00508,"COP":2.0E-4,"MKD":0.01392,"USD":0.79008,"DIN":0.00732,"DZD":0.00586,"PAB":0.79267,"GGP":0.9995,"SGD":0.5875,"ETB":0.01404,"JEP":0.9995,"KGS":0.00884,"SOS":0.00138,"VEF":0.0,"VUV":0.00656,"LAK":4.0E-5,"BND":0.58876,"ZMK":9.0E-5,"TZA":3.1E-4,"XAF":0.00131,"LRD":0.00411,"XAG":18.29983,"CHF":0.8935,"HRK":0.11238,"ALL":0.00825,"DJF":0.00445,"VES":0.02193,"ZMW":0.03362,"TZS":3.1E-4,"VND":3.0E-5,"XAU":1645.99375,"TRL":0.02517,"AUD":0.51631,"ILS":0.22155,"GHS":0.06242,"GYD":0.00379,"KPW":8.8E-4,"BOB":0.11471,"KHR":1.9E-4,"MDL":0.04461,"IDR":5.0E-5,"KYD":0.95119,"AMD":0.00196,"BWP":0.05755,"SHP":0.62321,"TRY":0.02517,"LBP":1.0E-5,"TJS":0.07239,"JOD":1.11429,"AED":0.2151,"HKD":0.10092,"RWF":6.1E-4,"EUR":0.85728,"LSL":0.04136,"DKK":0.11489,"ZWD":0.00245,"CAD":0.58173,"BGN":0.43767,"MMK":3.8E-4,"MUR":0.01725,"NOK":0.07481,"SYP":6.0E-5,"IMP":0.9995,"ZWL":0.00245,"ROL":0.17235,"GIP":0.9995,"RON":0.17235,"LKR":0.00257,"NGN":5.0E-4,"CRC":0.00155,"CZK":0.03378,"PKR":0.00284,"XCD":0.29235,"ANG":0.43983,"HTG":0.00598,"BHD":2.10296,"KZT":0.00175,"SRD":0.02232,"SZL":0.04136,"LTL":0.26757,"SAR":0.21067,"TTD":0.11681,"YER":0.00316,"MVR":0.05129,"AFN":0.01095,"INR":0.00954,"AWG":0.43832,"KRW":5.9E-4,"NPR":0.00598,"JPY":0.00526,"MNT":2.3E-4,"AOA":9.5E-4,"PLN":0.19834,"GBP":1.0,"SBD":0.09321,"BYN":0.24222,"HUF":0.00217,"BYR":4.0E-5,"BIF":2.8E-4,"MWK":4.7E-4,"MGA":1.8E-4,"XDR":1.052,"BZD":0.39326,"BAM":0.43849,"EGP":0.02561,"MOP":0.09831,"NAD":0.04136,"NIO":0.02154,"PEN":0.20964,"NIS":0.22155,"NZD":0.48242,"WST":0.29016,"TMT":0.22509,"CLF":22.54529,"BRL":0.15946}; var capi=true; async function getOrderNameFromConfirmation(){ var oName = null; if(typeof(document.getElementById('Intrnl_CO_Container')) != 'undefined'){ var confSrc = document.getElementById('Intrnl_CO_Container').src; if(null != confSrc){ var res = null; try{ let result = ''; try{ var url = "https://ecommerce-events.adscale.com/ecommerce/" + shopHost + "/getOrderNameFromConfirmation"; result = await makeAjaxRequest("POST", url, confSrc); } catch(e){ var url = "/apps/adscale/ecommerce/" + shopHost + "/getOrderNameFromConfirmation"; result = await makeAjaxRequest("POST", url, confSrc); } if(typeof(result)=='string'){ res = JSON.parse(result); } else if(typeof(result)=='object'){ res = result; } } catch(e){ // console.log(e); } } } return res; } async function getOrderByName(orderName) { console.log('getOrderByName ' + orderName); var res = false; try { let result = ''; try{ var url = "https://ecommerce-events.adscale.com/ecommerce/" + shopHost + "/getOrderByName/" + orderName; result = await makeAjaxRequest("POST", url); } catch(e){ var url = "/apps/adscale/ecommerce/" + shopHost + "/getOrderByName/" + orderName; result = await makeAjaxRequest("POST", url); } if(typeof(result)=='string'){ res = JSON.parse(result); } else if(typeof(result)=='object'){ res = result; } } catch (e) { //console.log(e); } return res; } function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function getAdscaleSuffix (){ let suffix = localStorage.getItem('adscale_token_suffix'); if(suffix == null){ suffix = 0; } else{ suffix = Number(suffix)+1; if(suffix > 999){ suffix = 0; } } localStorage.setItem('adscale_token_suffix', suffix); return suffix; } function createGuid(){ let suffix = getAdscaleSuffix(); return (makeid(8) + "-" + makeid(4) + "-" + makeid(4) + "-" + makeid(4) + "-" + makeid(12) + '-' + suffix).toLowerCase(); } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i var item_price_google = getValueForGoogle(item_price, adscale_currency); if(!isNullOrEmpty(addToCartLabel)) { gtag('event', 'conversion', { 'send_to': adwordsSendToAccount + '/' + addToCartLabel, 'aw_merchant_id': mcAccount, 'source': 'adscale', 'value': 0.0, 'id': '' + cart.items[0].product_id, 'currency': googleCurrency, 'event_callback': function (data) { //var image = new Image(1,1); //image.src = 'https://ecommerce-events.adscale.com/WriteShopifyLog?shop=' + shopHost + '&log=ADD_TO_CART_OK='+data; } }); gtag('event', 'add_to_cart', { 'send_to': adwordsSendToAccount, 'aw_merchant_id': mcAccount, 'source': 'adscale', 'items': [ { 'value': item_price_google, 'id': '' + cart.items[0].product_id, 'currency': googleCurrency, 'google_business_vertical': 'retail' } ] }); } let eventId = createGuid(); if(!isNullOrEmpty(facebookPixel)){ var item_price_facebook = getValueForFacebook(item_price, adscale_currency); fbq('trackSingle', facebookPixel, 'AddToCart', { content_name: '' + cart.items[0].title, content_ids: ['' + cart.items[0].product_id], content_type: 'product', value: item_price_facebook, currency: facebookCurrency },{eventID: eventId}); } capiEvent(eventId, 'AddToCart', cart.items[0].product_id, item_price_facebook, facebookCurrency); adscaleEventATC(cart.items[0].product_id); } console.log('--- adscale script init start --- '); if(!isNullOrEmpty(facebookPixel)){ try{ !function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window,document,'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', facebookPixel); fbq('trackSingle', facebookPixel, 'PageView'); //var image = new Image(1,1); //image.src = 'https://ecommerce-events.adscale.com/WriteShopifyLog?shop=' + shopHost + '&log=FACEBOOK_CALLED'; }catch(e){ //var image = new Image(1,1); //image.src = 'https://ecommerce-events.adscale.com/WriteShopifyLog?shop=' + shopHost + '&log=FACEBOOK_ERROR'; } } window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} if (typeof(jQuery) != 'undefined' && typeof(jQuery.getScript) != 'undefined') { adscaleEventVisit(); jQuery.getScript("https://www.googletagmanager.com/gtag/js?id=" + adwordsConfigAccount); if(!isNullOrEmpty(analyticsAccount)){ jQuery.getScript("https://www.googletagmanager.com/gtag/js?id=" + analyticsAccount); } } else { adscaleLoadScript("https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js", function() { adscaleEventVisit(); jQuery.getScript("https://www.googletagmanager.com/gtag/js?id=" + adwordsConfigAccount); if(!isNullOrEmpty(analyticsAccount)){ jQuery.getScript("https://www.googletagmanager.com/gtag/js?id=" + analyticsAccount); } }); } gtag('js', new Date()); gtag('config', adwordsConfigAccount); if(!isNullOrEmpty(analyticsAccount)){ gtag('config', analyticsAccount); } console.log('--- adscale script init end --- '); gtag('event', 'page_view',{'send_to': adwordsSendToAccount}); var adscale_product_id = null; if(__st&&__st.rtyp&&__st.rtyp=='product'&&__st.rid){ adscale_product_id = ''+__st.rid; } else if(document.getElementsByClassName("product-recommendations")&&document.getElementsByClassName("product-recommendations").length==1){ adscale_product_id = document.getElementsByClassName("product-recommendations")[0].getAttribute("data-product-id"); } if (typeof(adscale_product_id) != 'undefined') { if (!isNullOrEmpty(adscale_product_id)) { let eventId = createGuid(); if(!isNullOrEmpty(facebookPixel)){ fbq('trackSingle', facebookPixel, 'ViewContent', { 'content_ids': [adscale_product_id], 'content_type': 'product' },{eventID: eventId}); } gtag('event','view_item', { 'send_to': adwordsSendToAccount, 'source':'adscale', 'items': [ { 'id': adscale_product_id, 'google_business_vertical': 'retail' } ] }); capiEvent(eventId, 'ViewContent', adscale_product_id); adscaleEventViewContent(adscale_product_id); } } if(localStorage.getItem('cart_value')==null){ localStorage.setItem('cart_value', 0); } try{ if (typeof(jQuery) != 'undefined' && typeof(jQuery.getScript) != 'undefined') { writeAddToCartConversion(); } else{ adscaleLoadScript("https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js", function() { writeAddToCartConversion(); }); } } catch(e){ //log+="error: " + e + "_NL_"; } //var image = new Image(1,1); //image.src = 'https://ecommerce-events.adscale.com/WriteShopifyLog?shop=' + shopHost + '&log='+log; function writeAddToCartConversion(){ jQuery.getJSON('/cart.js', {initiator:"adscale"}, function(cart) { let cartToken = localStorage.getItem('adscale_cart_token'); if(cartToken==null || cartToken != cart.token){ localStorage.setItem('adscale_cart_token', cart.token); } if(localStorage.getItem('cart_value')cart.total_price){ //registerRemoveFromCartConversion(); localStorage.setItem('cart_value', cart.total_price); } }); } try{ setAdScaleToken(); } catch(e){} async function capiEvent(eventId, eventName, product_id, product_price, currency){ console.log('capiEvent ' + eventName + ': ' + product_id); let res = false; try{ let cartToken = localStorage.getItem('adscale_cart_token'); let adscale_token = localStorage.getItem('adscale_token_' + cartToken); if(isNullOrEmpty(adscale_token)){ setAdScaleToken(); cartToken = localStorage.getItem('adscale_cart_token'); adscale_token = localStorage.getItem('adscale_token_' + cartToken); } var _data = { event_id: eventId, event_name: eventName, product_id: product_id, product_price: product_price, currency: currency, adscale_token: adscale_token, url:window.location.href }; let result = ''; try{ var url = "https://ecommerce-events.adscale.com/ecommerce/" + shopHost + "/capi"; result = await makeAjaxRequest("POST", url, _data); } catch(e){ var url = "/apps/adscale/ecommerce/" + shopHost + "/capi"; result = await makeAjaxRequest("POST", url, _data); } if(typeof(result)=='string'){ res = JSON.parse(result).result; } else if(typeof(result)=='object'){ res = result.result; } } catch(e){ //console.log(e); } return res; } function adscaleEventVisit(){ try{ var pageData = { page: location.href }; adscaleEvent('adscale_visit', pageData); } catch(e){} } function adscaleEventViewContent(product_id){ try{ var viewData = { product_id: product_id }; adscaleEvent('adscale_view_content', viewData); } catch(e){} } function adscaleEventATC(product_id){ try{ var atcData = { product_id: product_id }; adscaleEvent('adscale_addToCart', atcData); } catch(e){} } async function adscaleEvent(type, additionalData){ let _today = new Date(); let today = _today.toISOString().substring(0, 10); if (type == 'adscale_visit') { let lastVisit = localStorage.getItem(type); if (null != lastVisit && lastVisit == today) { return; } } console.log('adscaleEvent: ' + type); let res = false; try{ let uid = null; try{ uid = getPopupUid(); } catch(e){} var _data = { type: type, cart: localStorage.getItem('adscale_cart_token'), uid: uid }; if(!isNullOrEmpty(additionalData)) { for (let [key, value] of Object.entries(additionalData)) { _data[key] = value; } } let result = ''; try{ var url = "https://ecommerce-events.adscale.com/ecommerce/" + shopHost + "/event"; result = await makeAjaxRequest("POST", url, _data); } catch(e){ var url = "/apps/adscale/ecommerce/" + shopHost + "/event"; result = await makeAjaxRequest("POST", url, _data); } if(typeof(result)=='string'){ res = JSON.parse(result).result; } else if(typeof(result)=='object'){ res = result.result; } } catch(e){ //console.log(e); } return res; } function makeAjaxRequest(method, url, jsonData) { try{ if(typeof jsonData == 'object'){ jsonData = JSON.stringify(jsonData); } } catch(e){} return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest(); xhr.open(method, url, true); xhr.onload = function () { if (this.status >= 200 && this.status < 300) { resolve(xhr.response); } else { reject({ status: this.status, statusText: xhr.statusText }); } }; xhr.onerror = function () { reject({ status: this.status, statusText: xhr.statusText }); }; xhr.setRequestHeader("Access-Control-Allow-Origin", '*'); xhr.setRequestHeader("Access-Control-Allow-Credentials", true); if(!isNullOrEmpty(jsonData)){ xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(jsonData); } else{ xhr.send(); } }); } //popup function loadPopupsScript() { if(!isSameDomain()){ return; } var script = document.createElement("script"); script.src = 'https://ascl.pro/js/pp.js?s=chesca1424.shopify.com'; document.body.appendChild(script); } function isSameDomain(){ if(!isNullOrEmpty(shopUrl)){ // console.log('shopUrl: ' + shopUrl); // console.log('document.location.host=' + document.location.host); let url = shopUrl.replace('https://', '').replace('http://', '').replace('www.', ''); if(url.endsWith("/")){ url = url.substring(0, url.length - 1); } let host = document.location.host.replace('www.', ''); if(url == host){ return true; } return false; } } function getPopupUid(){ let uid = null; let popup = localStorage.getItem('ascl-ppp-config'); if(null == popup){ popup = getCookie('ascl-ppp-config'); } if(null != popup){ let popJson = JSON.parse(popup); if(null != popJson){ uid = popJson.uId; } } return uid; } loadPopupsScript();