(self.webpackChunk_klaviyo_onsite_modules=self.webpackChunk_klaviyo_onsite_modules||[]).push([[7327],{50154:function(e,t,n){"use strict";var a=n(21889);n(56816);const s="kl-post-identification-sync",i=JSON.stringify([]),r=(e,t)=>{(async e=>{const t=localStorage.getItem(s),n=null===t?[]:JSON.parse(t);n.push(e),n.length>1e4&&n.shift(),localStorage.setItem(s,JSON.stringify(n))})(e).finally((()=>{t&&t()}))},o=(e=1e3)=>(async e=>{const t=JSON.parse(localStorage.getItem(s)||i),n=t.slice(0,e),a=t.slice(e);return{events:n||[],deleteCallback:async()=>{localStorage.setItem(s,JSON.stringify(a))}}})(e),l=()=>{localStorage.removeItem(s)},c=(e,t)=>{var n;const a=(new Date).toISOString(),s={name:e.event,time:(null==(n=e.properties)?void 0:n.time)||a,properties:e.properties||{}};r(s,t)};var u=n(87789),p=n.n(u),d=(n(92461),n(44159),n(60873),n(37237)),m=n(60485),h=n(20265),v=n(34273);n(70917),n(93677),n(84304),n(75723),n(20696),n(38528),n(72418);const f=new Set(["$exchange_id","email","id","$email","$id","$anonymous","$phone_number"]),y=["name","properties"];let b=!1;const g=(e,t,n,a,s)=>{const i=((e,t,n,a)=>({data:{type:"event-bulk-create",attributes:{profile:{data:{type:"profile",attributes:Object.assign({},t)}},events:{data:e.map((e=>{const{name:t,properties:a}=e,s=p()(e,y),i=Object.assign({},a,n||{}),r=i.service;delete i.service;const o="klaviyo"===r?{name:t,service:r}:{name:t};return{type:"event",attributes:Object.assign({metric:{data:{type:"metric",attributes:o}}},s,{properties:i})}}))}},relationships:a}}))(e,n,a,s);return(0,m.W)((()=>((e,t)=>fetch(`https://a.klaviyo.com/client/event-bulk-create/?company_id=${e}`,{method:"POST",headers:Object.assign({"Access-Control-Allow-Headers":"*","Content-Type":"application/json"},(0,d.h)(),{revision:"2025-01-15"}),body:JSON.stringify(t)}))(t,i)),5,1e3+1e3*Math.random(),[429])},_={$exchange_id:"_kx",email:"email",$email:"email",$phone_number:"phone_number",phone_number:"phone_number",$id:"external_id",id:"id",$kid:"id",$anonymous:"anonymous_id"},k=e=>{let t={};return Object.keys(_).forEach((n=>{if(a=n,!Set.prototype.has.call(f,a))return;var a;const s=e[n];if(!s)return;const i=("$email"===n||"email"===n)&&!(0,h.v)(s),r="$phone_number"===n&&!(0,v.y)(s);i||r||(t=Object.assign({},t,{[_[n]]:s}))})),t},S=async(e,t,n,a,s)=>{if(0===e.events.length)return;const i=await g(e.events,t,n,a,s);if(429===i.status&&console.warn(`KL: Saving event cache due to rate limit. Status: ${i.status}`),i.status>=500)throw new Error(`Saving event cache due to failed request. Status: ${i.status}`);await(null==e||null==e.deleteCallback?void 0:e.deleteCallback());const r=await o();return S(r,t,n,a,s)},w=async(e,t,n,a,s)=>{const i=e||window.__klKey;if(!i||b)return;const r=k(t);if(r&&0!==Object.keys(r).length){b=!0;try{const e=await o();await S(e,i,r,n,s),l(),null==a||a()}catch(e){if(e instanceof Error)throw e;throw new Error("Failed to send bulk events")}finally{b=!1}}};(()=>{(0,a.e)("cacheEvent",c),(0,a.e)("sendCachedEvents",w)})()},87789:function(e){e.exports=function(e,t){if(null==e)return{};var n={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(t.includes(a))continue;n[a]=e[a]}return n},e.exports.__esModule=!0,e.exports.default=e.exports}},function(e){e.O(0,[2462],(function(){return t=50154,e(e.s=t);var t}));e.O()}]);