"use strict";(self.webpackChunk_klaviyo_onsite_modules=self.webpackChunk_klaviyo_onsite_modules||[]).push([[9179],{97591:function(e,i,t){var n=t(21889),s=t(82732),d=t(34755);t(92461),t(70818),t(83362);t(60873);const o=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]})))},a="extendedIdIdentifiers",r=e=>e.map((e=>e.key)).filter((e=>void 0!==localStorage[e])).map((e=>({[e]:String(localStorage[e])}))),l=e=>{var i,t;i=a,t=JSON.stringify(e),localStorage.setItem(i,t)},c=e=>{const i=localStorage.getItem(a);e(i?JSON.parse(i):{})};t(26650),t(60624),t(75479);const f=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 y=({_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:o}}=e.data,a=Object.keys(o),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]=o[i.key],e)),r),(0,d.pN)()?(0,s.B2)("Identifier and _kx pairs set in backend. Not identifying onsite, already identified."):Object.keys(r).length>0?((0,s.B2)(`Setting klSessionId: ${i}`),c=i,(0,d.p2)(c),(0,s.B2)(`Identified: ${JSON.stringify(r)}`),(0,d.ro)({fields:{$exchange_id:t,klSessionId:i}}),l(r)):(0,s.B2)("Could not identify via extended ID based on available identifiers")})).catch((e=>{(0,s.B2)("Failed to create client identity",e)}))},p=()=>{if(void 0===window.klaviyoModulesObject)return void(0,s.B2)("klaviyoModulesObject is not defined");if((0,d.W6)()&&(0,d.pN)())return void(0,s.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,d.zy)(),n=(e=>{let i=[];const t=e.filter((e=>1===e.identifier_type)),n=e.filter((e=>2===e.identifier_type)),s=e.filter((e=>0===e.identifier_type));return t.length>0&&(i=[...i,...o(t)]),n.length>0&&(i=[...i,...r(n)]),s.length>0&&(i=[...i,...f(s)]),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?y({companyId:e,_kx:t,clientIdentifiers:n,extendedIdIdentifiers:i}):(0,s.B2)("No identifiers found")};(0,n.e)("createClientSession",p),(0,n.e)("getClientIdentifiers",c)}},function(e){e.O(0,[2462,6540],(function(){return i=97591,e(e.s=i);var i}));e.O()}]);