(()=>{"use strict";const t=(t,e,o)=>{const n=o=>String.prototype.split.call(e,o).filter(Boolean).reduce(((t,e)=>null!=t?t[e]:t),t),i=n(/[,[\]]+?/)||n(/[,[\].]+?/);return void 0===i||i===t?o:i},e=t=>!(!t||"string"!=typeof t)&&(-1!==t.indexOf("cart/add")||-1!==t.indexOf("cart/change")),o=async({limit:t=10,delay:e=100})=>{const n=new Set,i=document.querySelectorAll("script[src*=googletagmanager]");for(const t of i){const e=t.getAttribute("src"),o=new URLSearchParams(e.split("?")[1]).get("id");o&&o.startsWith("G-")&&n.add(o)}const c=Array.from(n);return c.length||1===t?c:(await new Promise((t=>setTimeout(t,e))),o({limit:t-1,delay:e}))},n=async()=>{const t=[],e=(t,e)=>new Promise(((o,n)=>{const i=setTimeout((()=>{n("gtag get timeout")}),200);gtag("get",t,e,(t=>{clearTimeout(i),o(t)}))})),n=await o({limit:10});if(n.length){if(window.gtag)for(const o of n)try{const n=await e(o,"session_id"),i=await e(o,"client_id");n&&i&&t.push({gaClientId:i,gaSessionId:n,shopMeasurementId:o})}catch(t){}if(!t.length)return i({measurementIds:n})}return t};async function i({measurementIds:t,limit:e=10,delay:o=100}){const n=[],c=function(){const t=document.cookie.split(";").find((t=>t.trim().startsWith("_ga=")));if(t){const e=t.split(".");return e.length>2?e[2]+"."+e[3]:null}return null}();return t.forEach((t=>{const e=function(t){const e=`; ${document.cookie}`.split(`; ${t}=`);return 2===e.length?e.pop().split(";").shift():null}(`_ga_${t.replace("G-","")}`);if(e){const o=e.split(".");if(o.length>3){const e=o[2];n.push({shopMeasurementId:t,gaClientId:c,gaSessionId:e})}}})),n.length||1===e?n:(await new Promise((t=>setTimeout(t,o))),i({measurementIds:t,limit:e-1,delay:o}))}const c={deserialize(t){const e={};return t.replace(/([^=]*)=([^&]*)&*/g,((t,o,n)=>{e[o]=encodeURIComponent(n)})),e}};function s(t){const e=("https:"==document.location.protocol?"https://":"http://")+"pixel.sitescout.com/iap/"+t;(new Image).src=e,function(t){var e=("https:"==document.location.protocol?"https://":"http://")+"pixel.sitescout.com/dmp/asyncPixelSync",o=t.createElement("iframe");(o.frameElement||o).style.cssText="width: 0; height: 0; border: 0; display:none;",o.src="javascript:false",t.body.appendChild(o);var n=o.contentWindow.document;n.open().write(""),n.close()}(document)}const{SCRIPT_TAG_GTM_ID:a}={NODE_ENV:"production",TRACK_URL:"https://kst.klickly.com",TRACK_API_URL:"https://dl-api.klickly.com",EXTERNAL_CHECKOUT_API:"https://external-checkout-api.klickly.com",PIXEL_SCRIPT_URL:"https://analytics.klickly.com/pixel.js?v=1.4.5-2",SCRIPT_TAG_DOMAIN_FILTER_LIST:"",SCRIPT_TAG_GTM_ID:"GTM-NMDRPTH",ANALYTICS_API_URL:"https://analytics-api.klickly.com",DISABLE_SESSION_PURCHASE_EVENT:1,WIDGET_PROMOTIONS_API:"https://widget-promotions-api.klickly.com",LIVERAMP_PIXEL_ID:711880};let r=!1;const{WIDGET_PROMOTIONS_API:l,ANALYTICS_API_URL:d}={NODE_ENV:"production",TRACK_URL:"https://kst.klickly.com",TRACK_API_URL:"https://dl-api.klickly.com",EXTERNAL_CHECKOUT_API:"https://external-checkout-api.klickly.com",PIXEL_SCRIPT_URL:"https://analytics.klickly.com/pixel.js?v=1.4.5-2",SCRIPT_TAG_DOMAIN_FILTER_LIST:"",SCRIPT_TAG_GTM_ID:"GTM-NMDRPTH",ANALYTICS_API_URL:"https://analytics-api.klickly.com",DISABLE_SESSION_PURCHASE_EVENT:1,WIDGET_PROMOTIONS_API:"https://widget-promotions-api.klickly.com",LIVERAMP_PIXEL_ID:711880},p=t=>{try{return JSON.parse(t.response)}catch(e){return t.response}},h=({baseURL:t,withCredentials:e=!0,httpMethod:o="POST"})=>(n,i)=>{const c=new XMLHttpRequest;return c.withCredentials=e,c.open(o,`${t}${n}`,!0),c.setRequestHeader("Content-Type","application/json"),c.send(JSON.stringify(i)),new Promise(((t,e)=>{c.onreadystatechange=()=>{4===c.readyState&&(c.status>=200&&c.status<300?t({data:p(c)}):e(c.statusText))}}))},u=h({baseURL:l,httpMethod:"GET"}),m=h({baseURL:window.location.origin,httpMethod:"GET"}),w=h({baseURL:d,httpMethod:"GET"});class _{static get(t){let e=document.cookie.match(new RegExp("(?:^|; )"+t.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));return e?decodeURIComponent(e[1]):void 0}static set(t,e,o={}){if((o={path:"/",secure:!0,sameSite:"none",...o}).expires)o.expires instanceof Date&&(o.expires=o.expires.toUTCString());else{const t=new Date;t.setDate(t.getDate()+365),o.expires=t.toUTCString()}let n=encodeURIComponent(t)+"="+encodeURIComponent(e);for(let t in o){n+="; "+t;let e=o[t];!0!==e&&(n+="="+e)}document.cookie=n}static remove(t){_.set(t,"",{expires:new Date(0)})}}class y{static get(t){try{return localStorage.getItem(t)}catch(t){return}}static set(t,e){try{return localStorage.setItem(t,e),y.get(t)===e}catch(t){return!1}}static remove(t){try{localStorage.removeItem(t)}catch(t){return!1}}}class k{static get(t){try{return sessionStorage.getItem(t)}catch(t){return}}static set(t,e){try{return sessionStorage.setItem(t,e),k.get(t)===e}catch(t){return!1}}static remove(t){try{sessionStorage.removeItem(t)}catch(t){return!1}}}const g=[_,y,k];class I{static get(t){let e;for(let o=0;o0,S=(t,e=!1)=>{let o=!1;if(e)return t(),!1;function n(){o||(o=!0,f.forEach((t=>{window.removeEventListener(t,n)})),T&&E.forEach((t=>{window.removeEventListener(t,n)})),t())}f.forEach((t=>{window.addEventListener(t,n)})),T&&E.forEach((t=>{window.addEventListener(t,n)}))},R=document.currentScript?document.currentScript.src:"",L=R&&"string"==typeof R?c.deserialize(R.slice(R.indexOf("?")+1)):{};L.gtm_enabled&&(()=>{if(!a)return;r=!0;const t=document.createElement("script");t.type="text/javascript",t.async=!0,t.text=`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','${a}');`,document.head.appendChild(t),window.dataLayer=window.dataLayer||[]})();const{SCRIPT_TAG_DOMAIN_FILTER_LIST:A,DISABLE_SESSION_PURCHASE_EVENT:P,LIVERAMP_PIXEL_ID:C}={NODE_ENV:"production",TRACK_URL:"https://kst.klickly.com",TRACK_API_URL:"https://dl-api.klickly.com",EXTERNAL_CHECKOUT_API:"https://external-checkout-api.klickly.com",PIXEL_SCRIPT_URL:"https://analytics.klickly.com/pixel.js?v=1.4.5-2",SCRIPT_TAG_DOMAIN_FILTER_LIST:"",SCRIPT_TAG_GTM_ID:"GTM-NMDRPTH",ANALYTICS_API_URL:"https://analytics-api.klickly.com",DISABLE_SESSION_PURCHASE_EVENT:1,WIDGET_PROMOTIONS_API:"https://widget-promotions-api.klickly.com",LIVERAMP_PIXEL_ID:711880},v=A?A.split(","):[],x=(()=>{let e=t(window,"Shopify.shop.permanent_domain")||t(window,"Shopify.shop")||t(window,"CHDataObject.store_urls.store_url")||t(window,"Klickly_BoldCommerce.shop");if((!e||"string"!=typeof e)&&document.currentScript.src){e=new URL(document.currentScript.src).searchParams.get("shop")}return e})(),D=v.includes(x),N={shopDomain:x,externalId:t(window,"meta.product.id"),checkout:(()=>{let e;return window.chData&&window.chData.order?(e={order_id:Number(window.chData.order.order_id)||null},e.referrer=document.location.host||""):window.Klickly_BoldCommerce&&window.Klickly_BoldCommerce.order_name?e={order_name:window.Klickly_BoldCommerce.order_name}:window.Klickly_Zipify&&window.Klickly_Zipify.order_id?e={order_id:Number(window.Klickly_Zipify.order_id)}:window.Klickly_Recharge&&window.Klickly_Recharge.order_id?e={order_id:Number(window.Klickly_Recharge.order_id)}:window.Klickly_Partially&&window.Klickly_Partially.checkout?e=window.Klickly_Partially.checkout:window.Shopify&&window.Shopify.checkout&&(e=t(window,"Shopify.checkout",{}),e.referrer=t(document,"location.host",""),e.customer=t(window,"Shopify.Checkout.customer"),e.geolocatedAddress=t(window,"Shopify.Checkout.geolocatedAddress",""),"string"==typeof e.order_id&&(e.order_id=Number(e.order_id))),e})()};async function O(){if(D)return!1;let e="visit";var o;"/cart"===t(window,"location.pathname","")&&(e="cart"),N.checkout&&(e="checkout"),function(t,e){const o=(L[`b_type_${e}`]||"").split(",").filter((t=>!!t));if(!o.length)return u(`/ads/tags?shopDomain=${t}&audienceAction=${e}`,{}).then((({data:t=[]})=>{t.forEach((t=>{s(t)}))}));o.forEach((t=>{s(t)}))}(x,e),o={event:"klicklyDataPush",klickly_event_name:e,klickly_cid:I.get("_klpixel_cid"),klickly_shop:x.replace(".myshopify.com",""),klickly_product:N.externalId||null},r&&window.dataLayer.push(o)}function U(){if(!D)return m("/cart.js").then((({data:t})=>{window.klpixel&&window.klpixel("event","cartChanged",{cart:t})}))}L.account_id&&(N.accountId=L.account_id);x&&(async()=>{O(),function(t){return"1"===L.tw?w(`/pixels?shop_domain=${t}`).then((({data:t})=>t.pixels)):Promise.resolve([])}(x).then((t=>{t.forEach((t=>{const e=`${t.name}_t`;!N.checkout&&(t=>{const e=t-Date.now();return!t||"number"!=typeof e||Math.floor(e/36e5)>24})(I.get(e))&&(((t={})=>{const e=document.createElement("iframe");Object.assign(e,t),e.style.display="none",e.style.position="absolute",e.style.top="-1000px",e.style.left="-1000px",e.style.width="0",e.style.height="0",e.style.border="none",e.style.overflow="hidden",e.style.zIndex="-1",e.style.visibility="hidden",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e)})({id:`kl_${t.name}_iframe`,src:t.src}),I.set(e,Date.now()))}))})).catch((()=>null));const t=L.te&&"1"===L.te,o=L.ga4&&"0"===L.ga4;S((()=>{(async function({shopData:t,isGA4Disabled:e=!1,isTouchEventsEnabled:o=!1}){((t,e,o,n)=>{if(t[n])return;const i=t[n]=function(){i.track&&i.ready?i.track.apply(i,arguments):i.queue.push(arguments)};i.queue=[];const c=e.createElement("script");c.id="klpixel-script",c.async=!0,c.src=o;const s=e.getElementsByTagName("script")[0];s.parentNode.insertBefore(c,s)})(window,document,"https://analytics.klickly.com/pixel.js?v=1.4.5-2","klpixel"),window.klpixel("init","shopify.shop"),window.klpixel("config","listeners",{change:!1,click:Boolean(t.externalId),scroll:!1,popstate:!1,mouseover:!1,touchend:Boolean(o),touchmove:Boolean(o),touchstart:Boolean(o),visibilitychange:!1}),e||window.klpixel("config","ga4",{enabled:!0}),window.klpixel("fetch_cookie"),window.klpixel("meta","shop",t),window.klpixel("ttd_event",{shop_domain:t.shopDomain,product_id:t.externalId}),window.klpixel("eyeota_event",{shop_domain:t.shopDomain,product_id:t.externalId}),t.checkout?window.klpixel("event","purchase"):window.klpixel("event","pageView")})({shopData:{...N,eventName:void 0},isGA4Disabled:o,isTouchEventsEnabled:t}).then((()=>{o||n().then((t=>{window.klpixel("config","ga4",{metadataFetched:!0,metadata:t})}))}))}),Boolean(N.checkout)),N.checkout&&I.remove("tw_t");const i=new URL(window.location);if(i.searchParams.get("klgooglecpc")&&window.klpixel){if(window.klpixel("event","click",[{google_cpc:{promotion:{accountId:N.accountId}}}],{id:"klickly.google_cpc",sendImmediately:!0,omitMetaFields:["shop"]}),C){const t={action:"click",account:N.accountId,shopDomain:x},e={platform:"klickly",source:"google_cpc",events:[JSON.stringify(t)]},o=new Image,n=btoa(JSON.stringify(e));o.src=`https://id.rlcdn.com/${C}.gif?cparams=${n}`}i.searchParams.delete("klcpc"),window.history.replaceState(history.state,"",i.href)}const c=XMLHttpRequest.prototype.open,s=window.fetch;window.fetch=function(){return s.apply(this,arguments).then((t=>(t.ok&&e(arguments[0])&&U(),t)))},XMLHttpRequest.prototype.open=function(){this.addEventListener("load",(function(){200===this.status&&e(this.responseURL)&&U()})),c.apply(this,arguments)}})(),D||s("357c6e9d4d9b263b")})();