"use strict";(self.webpackChunk_klaviyo_onsite_modules=self.webpackChunk_klaviyo_onsite_modules||[]).push([[9179],{49890:function(e,i,t){var n=t(15957),o=t(2609),s=t(82734),d=t(92719);t(92461),t(70818),t(83362);t(60873);const a=e=>{const i=document.cookie,t=i.split(";").map((e=>e.split("="))).reduce(((e,i)=>(i[0]&&i[1]&&(e[decodeURIComponent(i[0].trim())]=decodeURIComponent(i[1].trim())),e)),{});return e.map((e=>e.key)).filter((e=>void 0!==t[e])).map((e=>({[e]:t[e]})))},r=()=>(0,o.W6)(),c="extendedIdIdentifiers",l=e=>e.map((e=>e.key)).filter((e=>void 0!==localStorage[e])).map((e=>({[e]:String(localStorage[e])}))),f=e=>{var i,t;i=c,t=JSON.stringify(e),localStorage.setItem(i,t)},y=e=>{const i=localStorage.getItem(c);e(i?JSON.parse(i):{})};t(26650),t(60624),t(75479);const p=e=>{const i=new URLSearchParams(window.location.search);return e.map((e=>e.key)).filter((e=>i.has(e))).map((e=>({[e]:i.get(e)||void 0})))};t(61099);const k=({_kx:e,companyId:i,clientIdentifiers:t,extendedIdIdentifiers:n})=>{fetch(`https://a.klaviyo.com/client/sessions/?company_id=${i}`,{method:"POST",body:JSON.stringify({data:{type:"session",attributes:{identifiers:Object.assign({},t,{_kx:e})}}}),headers:{"X-Klaviyo-Onsite":"1",revision:"2024-07-15.pre","Content-Type":"application/json",accept:"application/json"}}).then((e=>e.json())).then((e=>{const{id:i,attributes:{kx:t,identifiers:s}}=e.data,a=Object.keys(s),r={};var c;n.filter((e=>a.some((i=>i===e.key))&&!1===e.is_warming&&!0===e.enabled&&!0===e.valid)).reduce(((e,i)=>(e[i.key]=s[i.key],e)),r),(0,o.pN)()?(0,d.B2)("Identifier and _kx pairs set in backend. Not identifying onsite, already identified."):Object.keys(r).length>0?((0,d.B2)(`Setting klSessionId: ${i}`),c=i,(0,o.p2)(c),(0,d.B2)(`Identified: ${JSON.stringify(r)}`),(0,o.ro)({fields:{$exchange_id:t,klSessionId:i}}),f(r)):(0,d.B2)("Could not identify via extended ID based on available identifiers")})).catch((e=>{(0,d.B2)("Failed to create client identity",e)}))},u=()=>{if(void 0===window.klaviyoModulesObject)return void(0,d.B2)("klaviyoModulesObject is not defined");if(r()&&(0,o.pN)())return void(0,d.B2)("Client session already exists and user is identified, should not set a new session");const{companyId:e,extendedIdIdentifiers:i}=window.klaviyoModulesObject,{$exchange_id:t}=(0,o.zy)(),n=(e=>{let i=[];const t=e.filter((e=>1===e.identifier_type)),n=e.filter((e=>2===e.identifier_type)),o=e.filter((e=>0===e.identifier_type));return t.length>0&&(i=[...i,...a(t)]),n.length>0&&(i=[...i,...l(n)]),o.length>0&&(i=[...i,...p(o)]),i.reduce(((e,i)=>{const t=Object.keys(i)[0];return void 0===t||void 0===i[t]||(e[t]=i[t]),e}),{})})(i);null!==n&&0!==Object.keys(n).length?k({companyId:e,_kx:t,clientIdentifiers:n,extendedIdIdentifiers:i}):(0,d.B2)("No identifiers found")};(0,n.e)("createClientSession",u),(0,n.e)("getClientIdentifiers",y),window.cookieStore&&(0,s.O)("onsite_shopify_cookie_listener")&&window.cookieStore.addEventListener("change",(e=>{for(const i of e.changed)if("shopify_client_id"===i.name){r()&&(0,o.gL)(),u();break}}))}},function(e){e.O(0,[2462,7537],(function(){return i=49890,e(e.s=i);var i}));e.O()}]);