@thg-agentic/hyper-personalisation-web 3.26.0 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -466,6 +466,12 @@ can include tax where `value` does not. It is `null`, so every rule on it fails,
466
466
  sends a Cart Updated, and again after one without a `value`. Send `cartUpdated` after every confirmed basket change, as the spec asks, or
467
467
  a basket audience goes stale.
468
468
 
469
+ Since 3.27, `campaign.source`, `campaign.medium`, `campaign.campaign`, `campaign.content` and
470
+ `campaign.term` are the campaign the visit arrived from: the `utm_*` tags of the first page of the
471
+ visit that had any (a page view records them), kept for the visit. They are text, compared trimmed
472
+ and in any case with `eq`, `neq`, `in` (a list) or `contains`. A visit that arrived untagged fails
473
+ every rule on them, `neq` included, so "not from Facebook" never means "from nowhere".
474
+
469
475
  ### Audiences only some integrations may target
470
476
 
471
477
  Since 3.8, only audiences marked Targetable in the console are membership. Pass the membership
@@ -682,7 +688,7 @@ each form did or did not show, and a preview link (`?hp_preview=`) counts nothin
682
688
  `onsite.min.js` under 5.875 KiB gzipped (about 5.6 KiB), `onsite-render.min.js` under 14 KiB (about
683
689
  13.7 KiB), so a page that shows a form loads about 19 KiB of onsite code and one whose forms never
684
690
  fire about 5.6 KiB; `onsite-wheel.min.js` under 8 KiB (about 1.3 KiB), `onsite-answers.min.js` under
685
- 2 KiB (about 1.5 KiB), `onsite-audiences.min.js` under 1.25 KiB (about 1.2 KiB). The core carries only the loader.
691
+ 2 KiB (about 1.5 KiB), `onsite-audiences.min.js` under 1.44 KiB (about 1.36 KiB). The core carries only the loader.
686
692
 
687
693
  Try it locally: `node tools/local/serve.mjs`, then
688
694
  `http://localhost:8099/onsite.html?hp_debug=onsite` (offline mocks by default, `?mode=live` for
package/dist/hp.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var gn=e=>{throw TypeError(e)};var co=(e,t,n)=>t.has(e)||gn("Cannot "+n);var yn=(e,t,n)=>t.has(e)?gn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n);var L=(e,t,n)=>(co(e,t,"access private method"),n);var Ae=[];for(let e=2;Ae.length<64;e++)Ae.every(t=>e%t!==0)&&Ae.push(e);var wn=e=>(e-Math.floor(e))*2**32>>>0,uo=Ae.slice(0,8).map(e=>wn(Math.sqrt(e))),lo=Ae.map(e=>wn(Math.cbrt(e))),Z=(e,t)=>e>>>t|e<<32-t;function Sn(e){let t=new TextEncoder().encode(String(e)),n=new Uint32Array((t.length+8>>6)*16+16);t.forEach((i,s)=>{n[s>>2]|=i<<24-s%4*8}),n[t.length>>2]|=128<<24-t.length%4*8,n[n.length-2]=Math.floor(t.length/2**29),n[n.length-1]=t.length*8;let r=Uint32Array.from(uo),o=new Uint32Array(64);for(let i=0;i<n.length;i+=16){for(let w=0;w<64;w++){if(w<16){o[w]=n[i+w];continue}let x=o[w-15],_=o[w-2],k=Z(x,7)^Z(x,18)^x>>>3,m=Z(_,17)^Z(_,19)^_>>>10;o[w]=o[w-16]+k+o[w-7]+m}let[s,c,u,d,f,p,g,A]=r;for(let w=0;w<64;w++){let x=Z(f,6)^Z(f,11)^Z(f,25),_=A+x+(f&p^~f&g)+lo[w]+o[w]|0,m=(Z(s,2)^Z(s,13)^Z(s,22))+(s&c^s&u^c&u)|0;[A,g,p,f,d,u,c,s]=[g,p,f,d+_|0,u,c,s,_+m|0]}[s,c,u,d,f,p,g,A].forEach((w,x)=>{r[x]+=w})}return Array.from(r,i=>i.toString(16).padStart(8,"0")).join("")}var _t=(e,t)=>e<<t|e>>>32-t;function _n(e){let t=new Uint32Array((e.length+8>>6)*16+16);e.forEach((i,s)=>{t[s>>2]|=i<<24-s%4*8}),t[e.length>>2]|=128<<24-e.length%4*8,t[t.length-2]=Math.floor(e.length/2**29),t[t.length-1]=e.length*8;let n=Uint32Array.of(1732584193,4023233417,2562383102,271733878,3285377520),r=new Uint32Array(80);for(let i=0;i<t.length;i+=16){for(let p=0;p<80;p++)r[p]=p<16?t[i+p]:_t(r[p-3]^r[p-8]^r[p-14]^r[p-16],1);let[s,c,u,d,f]=n;for(let p=0;p<80;p++){let g,A;p<20?(g=c&u|~c&d,A=1518500249):p<40?(g=c^u^d,A=1859775393):p<60?(g=c&u|c&d|u&d,A=2400959708):(g=c^u^d,A=3395469782);let w=_t(s,5)+g+f+A+r[p]|0;[f,d,u,c,s]=[d,u,_t(c,30),s,w]}[s,c,u,d,f].forEach((p,g)=>{n[g]+=p})}let o=new Uint8Array(20);return n.forEach((i,s)=>{o[s*4]=i>>>24,o[s*4+1]=i>>>16,o[s*4+2]=i>>>8,o[s*4+3]=i}),o}var fo="e28e8ada-5b76-4209-bba9-79b823a0af75",po=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join("");function bn(e,t){let n=Uint8Array.from(e.replace(/-/g,"").match(/../g),c=>Number.parseInt(c,16)),r=new TextEncoder().encode(t),o=new Uint8Array(16+r.length);o.set(n),o.set(r,16);let i=_n(o).slice(0,16);i[6]=i[6]&15|80,i[8]=i[8]&63|128;let s=po(i);return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}var ce=(e,t)=>typeof e=="string"&&e!==""&&e.length<=t?e:null;function Be(e,t){return ce(e,64)??ce(t,256)}function In({sessionId:e,slot:t,arm:n}={}){let r=ce(e,256);return!r||!ce(t,256)||!ce(n,256)?null:bn(fo,`${r}:${t}:${n}`)}var mo="4b1f2c7e-9a3d-4e58-b6c1-2d7f0a9e8c53";function xn({sessionId:e,surface:t}={}){let n=ce(e,256);return!n||!ce(t,64)?null:bn(mo,`${n}:${t}`)}var ho=Array.from({length:11},(e,t)=>t/10);function go(e,t){if(!e.isIntersecting)return!1;let{intersectionRect:n,boundingClientRect:r,rootBounds:o}=e;if(!n||!r)return!0;let i=n.width*n.height,s=r.width*r.height,c=o?Math.min(s,o.width*o.height):s;return c>0&&i/c>=t}function te(e){let{selector:t,onViewable:n,visibleRatio:r=.5,dwellMs:o=1e3,root:i=document}=e,s=new Map,c=new WeakSet,u=new Set,d=m=>{s.has(m)||s.set(m,setTimeout(()=>{s.delete(m),n(m)&&(p?.unobserve(m),u.delete(m))},o))},f=m=>{clearTimeout(s.get(m)),s.delete(m)},p=typeof IntersectionObserver>"u"?null:new IntersectionObserver(m=>{for(let E of m){let S=E.target;if(!go(E,r)){u.delete(S),f(S);continue}u.add(S),g()&&d(S)}},{threshold:ho}),g=()=>typeof document>"u"||document.visibilityState!=="hidden",A=()=>{if(g())for(let m of u)d(m);else for(let m of u)f(m)};document.addEventListener("visibilitychange",A);let w=()=>{for(let m of i.querySelectorAll(t))c.has(m)||(c.add(m),p?.observe(m))},x=typeof MutationObserver>"u"?null:new MutationObserver(()=>w()),_=()=>{w(),x?.observe(i===document?document.body:i,{childList:!0,subtree:!0})},k=i===document&&!document.body;return k?document.addEventListener("DOMContentLoaded",_,{once:!0}):_(),()=>{k&&document.removeEventListener("DOMContentLoaded",_),document.removeEventListener("visibilitychange",A),p?.disconnect(),x?.disconnect();for(let m of s.values())clearTimeout(m);s.clear(),u.clear()}}function bt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-exposure]",visibleRatio:r=.5,dwellMs:o=1e3,root:i=document}=t;return te({selector:n,root:i,visibleRatio:r,dwellMs:o,onViewable(s){let c=s.dataset?.hpExposure?.trim();return c&&e.surfaceViewed({surface:c}),!0}})}var kn=e=>{try{return new URL(e,document.baseURI).toString()}catch{return e}};function It(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-list]",tileSelector:r="[data-hp-product]",visibleRatio:o=.5,dwellMs:i=1e3,root:s=document}=t,c=new Set,u=w=>w.closest?.(n)??null,d=w=>{let x=w.dataset.hpList?.trim();return x?{list_id:x,category:w.dataset.hpListCategory?.trim()||null}:null},f=w=>Array.from(w.querySelectorAll(r)).filter(x=>u(x)===w),p=(w,x)=>{try{let _=JSON.parse(w.dataset.hpProduct??"");return!_||typeof _!="object"||!_.product_id?null:{..._,position:_.position??x+1,..._.url?{url:kn(_.url)}:{},..._.image_url?{image_url:kn(_.image_url)}:{}}}catch{return null}},g=te({selector:`${n} ${r}`,root:s,visibleRatio:o,dwellMs:i,onViewable(w){let x=u(w);if(!x||x.dataset.hpListView==="manual")return!0;let _=d(x);if(!_||c.has(_.list_id))return!0;let k=new Set,m=f(x).map(p).filter(E=>!E||k.has(E.product_id)?!1:(k.add(E.product_id),!0));return m.length===0||(c.add(_.list_id),e.productListViewed({..._,products:m})),!0}}),A=w=>{let _=w.target?.closest?.("a[href]")?.closest(r);if(!_)return;let k=u(_),m=p(_,k?f(k).indexOf(_):0);m&&e.productClicked({list_id:k?d(k)?.list_id??null:null,products:[m]})};return document.addEventListener("click",A,!0),()=>{document.removeEventListener("click",A,!0),g()}}function D(e,...t){let n=e.dataset??{};for(let r of t){let o=n[r];if(typeof o=="string"&&o.trim()!=="")return o.trim()}return null}function je(e,...t){let n=D(e,...t);if(n===null)return null;let r=Number(n);return Number.isFinite(r)?Math.trunc(r):null}function yo(e,t){let n=D(e,"hpPromotion");return n?{promotion_id:n,name:D(e,"hpPromotionName"),creative:D(e,"hpPromotionCreative"),position:D(e,"hpPromotionSlot")??String(t+1)}:null}function xt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-promotion]",resolve:r=yo,visibleRatio:o=.5,dwellMs:i=1e3,root:s=document}=t,c=new Set,u=p=>{let g=Array.from(s.querySelectorAll(n)),A=g.indexOf(p);try{return r(p,A<0?g.length:A)}catch{return null}},d=te({selector:n,root:s,visibleRatio:o,dwellMs:i,onViewable(p){let g=u(p);return!g||c.has(g.promotion_id)?!1:(c.add(g.promotion_id),e.promotionViewed(g),!0)}}),f=p=>{let g=p.target;if(!g||typeof g.closest!="function")return;let A=g.closest(n),w=g.closest("a[href]");if(!A||!w||!A.contains(w)&&!w.contains(A))return;let x=u(A);x&&e.promotionClicked({...x,href:w.getAttribute("href")})};return document.addEventListener("click",f,!0),()=>{document.removeEventListener("click",f,!0),d()}}function wo(e){let t=D(e,"hpRecoRequest"),n=D(e,"hpRecoPlacement"),r=D(e,"hpRecoStrategy");if(!t||!n||!r)return null;let o=D(e,"hpRecoHoldout");return{recommendation_request_id:t,placement:n,strategy:r,recipe:D(e,"hpRecoRecipe"),algorithm_version:D(e,"hpRecoAlgorithmVersion"),experiment:D(e,"hpRecoExperiment"),variant:D(e,"hpRecoVariant"),holdout:o===null?null:o==="true",assignment_bucket:je(e,"hpRecoBucket"),assignment_unit_kind:D(e,"hpRecoUnitKind"),candidate_set_fingerprint:D(e,"hpRecoFingerprint"),candidate_set_size:je(e,"hpRecoCandidates"),ranked_by:D(e,"hpRecoRankedBy"),served_at:D(e,"hpRecoServedAt")}}function So(e,t){let n=D(e,"hpRecoProduct");if(!n)return null;let r=D(e,"hpRecoPrice");return{product_id:n,sku:D(e,"hpRecoSku"),name:D(e,"hpRecoName"),brand:D(e,"hpRecoBrand"),price:r===null||Number.isNaN(Number(r))?null:Number(r),position:je(e,"hpRecoPosition")??t+1}}function kt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-reco-request]",tileSelector:r="[data-hp-reco-product]",resolveRail:o=wo,resolveTile:i=So,visibleRatio:s=.5,dwellMs:c=1e3,root:u=document}=t,d=new Set,f=new Map,p=new Map,g=(m,...E)=>{try{return m(...E)}catch{return null}},A=m=>typeof m.closest=="function"?m.closest(n):null,w=m=>Array.from(m.querySelectorAll(r)),x=(m,E)=>{if(p.delete(E.recommendation_request_id),d.has(E.recommendation_request_id))return;let S=w(m).map((y,O)=>g(i,y,O)).filter(y=>y?.product_id);if(S.length===0)return;d.add(E.recommendation_request_id);let h=[...f.get(E.recommendation_request_id)?.values()??[]].sort((y,O)=>y.position-O.position);e.recommendationsViewed({...E,products:S,viewable:h})},_=te({selector:`${n} ${r}`,root:u,visibleRatio:s,dwellMs:c,onViewable(m){let E=A(m);if(!E)return!0;let S=g(o,E);if(!S)return!0;let h=S.recommendation_request_id,y=g(i,m,w(E).indexOf(m));if(y?.product_id){f.has(h)||f.set(h,new Map);let O=f.get(h);O.has(y.position)||O.set(y.position,{position:y.position,product_id:y.product_id,viewable_at:new Date().toISOString()})}return!d.has(h)&&!p.has(h)&&p.set(h,setTimeout(()=>x(E,S),0)),!0}}),k=m=>{let E=m.target;if(!E||typeof E.closest!="function")return;let S=E.closest(r);if(!S)return;let h=E.closest("[data-hp-reco-interaction]"),y=E.closest("a[href]"),O=y&&(S.contains(y)||y.contains(S));if(!(h&&S.contains(h))&&!O)return;let N=A(S);if(!N)return;let U=g(o,N);if(!U)return;let G=g(i,S,w(N).indexOf(S));if(!G?.product_id)return;let K=U.recommendation_request_id;d.has(K)||(clearTimeout(p.get(K)),x(N,U)),e.productClicked({recommendation_request_id:U.recommendation_request_id,interaction:D(h??S,"hpRecoInteraction")??"navigate",products:[G]})};return document.addEventListener("click",k,!0),()=>{document.removeEventListener("click",k,!0);for(let m of p.values())clearTimeout(m);p.clear(),_()}}var Se=new Set(["home","list","product","search","basket","checkout","order_confirmation","login","register","account","info","blog","other"]),_o=new Set(["products"]),An=e=>e==null;function At(e,t=new WeakSet){if(e instanceof Date)return e.toJSON();if(e===null||typeof e!="object"||t.has(e))return e;t.add(e);let n=Array.isArray(e)?e.map(r=>At(r,t)):Object.fromEntries(Object.entries(e).filter(([,r])=>!An(r)).map(([r,o])=>[r,At(o,t)]));return t.delete(e),n}function vt(e){if(!e)return e;let t=At(e);for(let n of _o)n in e&&An(e[n])&&(t[n]=e[n]);return t}function vn(){try{let e=performance.getEntriesByType("navigation")[0];return e?["navigate","reload","back_forward","prerender"].includes(e.type)?e.type:"navigate":null}catch{return null}}var bo=new Set(["","unknown","undefined","null","none","nil","nan","anonymous","guest","0","-1"]);function F(e){if(e==null)return null;let t=String(e).trim();return bo.has(t.toLowerCase())?null:t}var ve=e=>typeof e=="string"&&e!==""?e:null;function ne(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var En="1.20";function V(e){if(typeof document>"u")return null;try{let t=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith(`${e}=`));return t&&decodeURIComponent(t.slice(e.length+1))||null}catch{return null}}var Io={gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid"},xo=/[a-z0-9._%+-]+@[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}/i,ko=/\d(?:[ -]?\d){12,}/,Ao=new Set(["gclid","fbclid","ttclid","msclkid"]);function On(e,t=""){if(typeof e!="string"||e==="")return!1;let n=[e];try{let o=decodeURIComponent(e.replace(/\+/g," "));o!==e&&n.push(o)}catch{}let r=!Ao.has(String(t).toLowerCase());return n.some(o=>xo.test(o)||r&&ko.test(o))}function Ct(e){if(!e)return null;let t=new URLSearchParams(e),n={},r={utm_source:"source",utm_medium:"medium",utm_campaign:"name",utm_term:"term",utm_content:"content"};for(let[o,i]of[...Object.entries(r),...Object.entries(Io)]){let s=t.get(o);s&&!On(s,o)&&(n[i]=s)}return Object.keys(n).length?n:null}var vo=["email","e-mail","password","pass","pwd","token","auth","code","uid","customer_id","postcode","zip","phone","applyCode"],Eo=["email","password","passwd","pwd","token","secret","auth","session","phone","postcode","zip","address","birth","card","cvv","iban","ssn","customerid","userid"],Co=["tel","uid","dob"],Oo=["utm_source","utm_medium","utm_campaign","utm_term","utm_content","gclid","fbclid","ttclid","msclkid"],Po=new Set(vo.map(e=>e.toLowerCase()));function Lo(e){let t=String(e).toLowerCase();if(Po.has(t))return!0;let n=t.replace(/[-_.]/g,"");return Eo.some(o=>n.includes(o))?!0:String(e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z0-9]+/).some(o=>Co.includes(o))}function Et(e){return(e??[]).map(t=>{try{return new RegExp(`^${t}$`,"i")}catch{return{test:n=>n.toLowerCase()===String(t).toLowerCase()}}})}function Pn(e,t={}){if(!e)return null;try{let n=new URLSearchParams(e),r=t.queryParamAllowlist?Et([...t.queryParamAllowlist,...Oo]):null,o=Et(t.queryParamBlocklist),i=Et(t.sensitiveParamAllowlist);for(let c of new Set(n.keys()))(Lo(c)&&!i.some(d=>d.test(c))||n.getAll(c).some(d=>On(d,c))||(r?!r.some(d=>d.test(c)):o.some(d=>d.test(c))))&&n.delete(c);let s=n.toString();return s?`?${s}`:""}catch{return""}}function Ln(e,t,n={}){if(!e)return null;try{let r=new URL(e);return t&&r.origin===t?r.origin+r.pathname+(Pn(r.search,n)??""):r.origin+r.pathname}catch{return null}}function Ot(e,t={}){if(typeof e!="string"||typeof location>"u")return null;try{let n=new URL(e,location.href);return n.protocol!=="https:"&&n.protocol!=="http:"?null:Ln(n.href,location.origin,t)}catch{return null}}function Pt(e){if(typeof e!="string")return null;let t=e.trim().toUpperCase();return/^[A-Z]{3}$/.test(t)?t:null}function Cn(e){if(typeof e!="string")return null;let t=e.trim().toUpperCase();return/^[A-Z]{2}$/.test(t)?t:null}function Lt(e){if(typeof e!="string")return null;let t=e.trim().replace(/_/g,"-");if(!/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(t))return null;try{return Intl.getCanonicalLocales(t)[0]}catch{return null}}function M(e,t){if(typeof e=="function")try{let n=e();if(n!=null)return n}catch{}return t}function To(e){return{...e.propertyId==null?{}:{property_id:String(e.propertyId)},channel:e.channel??null,market:e.market??null,environment:e.environment??null}}function No(e){let t=typeof window<"u"?window.location:null,n=t?Pn(t.search,e):null;return{url:t?t.origin+t.pathname+(n??""):e.pageUrl??null,path:t?t.pathname:e.pagePath??null,search:n??null,referrer:typeof document<"u"?Ln(document.referrer,t?.origin,e):null,title:typeof document<"u"&&document.title||null,type:e.pageType??null}}var Ee;function Ro(){if(Ee!==void 0)return Ee;try{Ee=globalThis.Temporal?.Now?.timeZoneId?.()||Intl.DateTimeFormat().resolvedOptions().timeZone||null}catch{Ee=null}return Ee}function Tn(e,t={}){let n=typeof window<"u"?window.location:null,r={library:{name:e.libraryName,version:e.libraryVersion},spec:{version:En},source:To(e),session_id:M(e.getSessionId,null),identity_trust:F(M(e.getAnonymousId,null))?"device":"none",page:No(e),campaign:n?Ct(n.search):null,device:{user_agent:typeof navigator<"u"?navigator.userAgent:null,type:null,viewport_width:typeof window<"u"?window.innerWidth:null,viewport_height:typeof window<"u"?window.innerHeight:null},currency:Pt(M(e.getCurrency,e.currency)),locale:Lt(M(e.getLocale,e.locale)),timezone:Ro(),country:Cn(e.country),ship_to_country:Cn(M(e.getShipToCountry,e.shipToCountry)),ip:null,bot:null,consent:e.getConsent?.()??null,experiments:M(e.getExperiments,null),audiences:M(e.getAudiences,null),decisions:M(e.getDecisions,null),recommendations:M(e.getRecommendations,null),extensions:M(e.getExtensions,null)};return Nn(r,t)}function Nn(e,t){if(!t)return e;let n={...e};for(let[r,o]of Object.entries(t))o&&typeof o=="object"&&!Array.isArray(o)&&e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?n[r]=Nn(e[r],o):o!==void 0&&(n[r]=o);return n}var de=Object.freeze({consent:"thg_hp_consent",retry:"thg_hp_retry",sessionSignals:"thg_hp_session_signals",identified:"thg_hp_identified",previousPage:"thg_hp_prev_page",decisions:"thg_hp_decisions",settings:"thg_hp_settings",held:"thg_hp_held",carried:"thg_hp_carried",recommendationContext:"thg_hp_recommendation_context",anonymousId:"thg_hp_anonymous_id",session:"thg_hp_session",preview:"thg_hp_preview",debug:"thg_hp_debug",onsite:"thg_hp_onsite",visitCampaign:"thg_hp_visit_campaign"}),Mo={retry:"cdp.retry",sessionSignals:"cdp_session_signals",identified:"cdp_identified",previousPage:"cdp_prev_page_message_id"},Tt={...de},Rn=!1;function He(e){let t={...de};for(let[n,r]of Object.entries(e??{})){if(!(n in de))throw new Error(`storageNames: unknown kind "${n}"`);if(typeof r!="string"||!/^[\w.-]+$/.test(r))throw new Error(`storageNames.${n} must be a non-empty cookie-safe name`);t[n]=r}Tt=t}function C(e){return Tt[e]}var Do="_",Mn=e=>e==null||e===""?Do:String(e);function $(e,t,n){let r=`${e}:${Mn(t)}`;return n==null||n===""?r:`${r}:${n}`}function Dn(e,t){return`${e}:${Mn(t)}:`}function Fe(){if(!Rn){Rn=!0;for(let e of[()=>localStorage,()=>sessionStorage]){let t;try{if(t=e(),!t)continue;for(let n of Object.keys(t))for(let[r,o]of Object.entries(Mo)){if(n!==o&&!n.startsWith(`${o}:`))continue;let i=Tt[r]+n.slice(o.length);t.getItem(i)===null&&t.setItem(i,t.getItem(n)),t.removeItem(n)}}catch{}}}}var Rt=1800*1e3,qe=()=>{try{return typeof sessionStorage>"u"?null:sessionStorage}catch{return null}},Nt=()=>{try{return typeof localStorage>"u"?null:localStorage}catch{return null}};function Un(e,t=()=>Date.now()){return{read(){try{let n=qe()?.getItem(e),r=n?JSON.parse(n):null;return!r||t()-r.savedAt>Rt?(r&&qe()?.removeItem(e),{items:[],anonymousId:null}):{items:Array.isArray(r.items)?r.items:[],anonymousId:typeof r.anonymousId=="string"?r.anonymousId:null}}catch{return{items:[],anonymousId:null}}},write(n,r=null){try{n.length===0?qe()?.removeItem(e):qe()?.setItem(e,JSON.stringify({savedAt:t(),items:n,anonymousId:r}))}catch{}}}}var Uo=400*24*60*60;function re(e,t,n,r){if(typeof document>"u")return!1;try{let o=typeof location<"u"&&location.protocol==="https:"?"; Secure":"",i=r?`; Domain=${r}`:"",s=n===null?"":`; Max-Age=${n}`;return document.cookie=`${e}=${encodeURIComponent(t)}; Path=/${s}; SameSite=Lax`+i+o,!0}catch{return!1}}function Vo({name:e,domain:t=null,legacyKey:n,read:r,mint:o,mayStore:i,carried:s=null}){let c=null;try{c=Nt()?.getItem(n)||null}catch{c=null}let u=r(e)??c??s,d=!1,f=()=>{if(!(d||u===null||!i())&&(d=re(e,u,Uo,t),!(!d||c===null)))try{Nt()?.removeItem(n),c=null}catch{}};return{get(){return u??(u=o()),f(),u},peek:()=>u,persist:f,forget(){re(e,"",0,t),u=null,d=!1;try{Nt()?.removeItem(n)}catch{}c=null}}}function Vn(e,{carried:t=null,mayStore:n,orOwn:r=!1}){let o=e.anonymousIdSource,i=()=>Vo({name:C("anonymousId"),domain:e.consentCookieDomain??null,legacyKey:$(C("anonymousId"),e.propertyId),read:V,mint:ne,mayStore:n,carried:t});if(o?.source==="hp_cookie"){let u=i();return e.getAnonymousId=()=>u.get(),u}if(o?.source==="site_cookie"&&o.cookie){let u=o.cookie;e.getAnonymousId=()=>V(u)}if(!r)return null;let s=e.getAnonymousId,c=i();return e.getAnonymousId=()=>F(M(s,null))??c.get(),c}var $o=200;function $n(e,t,n=()=>Date.now()){let r=()=>$(C("carried"),e),o=!1;function i(){try{let s=JSON.parse(sessionStorage.getItem(r())??"null");return!s||!(n()-s.savedAt<=Rt)?[]:Array.isArray(s.calls)?s.calls:[]}catch{return[]}}return{take(){let s=i();try{sessionStorage.removeItem(r())}catch{}return s},save(s){try{return o||!t()?!1:(sessionStorage.setItem(r(),JSON.stringify({savedAt:n(),calls:[...i(),...s].slice(-$o)})),!0)}catch{return!1}},close(){o=!0}}}var fa=de.consent,Ke=Object.freeze({visitor:"visitor",host:"host"}),Bn=()=>({basis:Ke.host}),Bo="hp-consent",fe=["analytics","marketing","personalisation","ad_user_data","ad_personalization"],jn={analytics:"a",marketing:"m",personalisation:"p",ad_user_data:"aud",ad_personalization:"adp"},ee=()=>typeof window<"u",Hn=()=>ee()&&typeof window.cookieStore?.addEventListener=="function",jo=e=>e===!0?!0:e===!1?!1:null;function _e(e){if(!e||typeof e!="object")return null;let t={};for(let n of fe)t[n]=jo(e[n]);return t}function Dt(e,t){return!e||!t?e===t:fe.every(n=>e[n]===t[n])}function Ut(e){if(!e)return"";let t=[];for(let n of fe){let r=e[n];(r===!0||r===!1)&&t.push(`${jn[n]}=${r?1:0}`)}return t.join("&")}function Vt(e){return{[Bo]:Ut(_e(e))}}function Ce(e){let t=_e({});if(e==null)return t;let n=String(e).trim();if(n.length>=2&&n.startsWith('"')&&n.endsWith('"')&&(n=n.slice(1,-1)),n.includes("%"))try{n=decodeURIComponent(n.replace(/\+/g," "))}catch{return t}let r=Object.fromEntries(Object.entries(jn).map(([i,s])=>[s,i])),o=new Set;for(let i of n.split("&")){let s=i.indexOf("=");if(s<=0)continue;let c=r[i.slice(0,s).trim()],u={1:!0,0:!1}[i.slice(s+1).trim()]??null;!c||u===null||o.has(c)||(t[c]===null?t[c]=u:t[c]!==u&&(t[c]=null,o.add(c)))}return t}function $t(e,t){if(!t)return e;let n=r=>{if(!r)return r;let o={...r};for(let i of fe)i!=="analytics"&&t[i]!==!0&&(o[i]=null);return o};return{name:e.name,basis:e.basis,read:()=>n(e.read()),subscribe:r=>e.subscribe(o=>r(n(o))),get observesChanges(){return e.observesChanges}}}function Bt(e,t={}){return{...e,ad_user_data:t.ad_user_data??e.marketing,ad_personalization:t.ad_personalization??e.marketing}}function Ge(e,t){let n=!0;return{notify:()=>{if(n)try{let o=e();o&&t(o)}catch{}},stop:()=>n=!1}}var Ho={analytics:["analytics","measure_content_performance","audience_measurement"],marketing:["marketing","targeting","advertising","select_personalized_ads","create_ads_profile"],personalisation:["personalisation","personalization","select_personalized_content","create_content_profile"]};function Fo(e,t){if(!t?.length)return null;let n=!1;for(let[r,o]of Object.entries(e)){let i=String(o?.id??r).toLowerCase();if(t.some(c=>{let u=String(c).toLowerCase();return i===u||i.startsWith(`${u}-`)})&&(n=!0,o?.enabled===!0))return!0}return n?!1:null}function Fn(e={}){let t={...Ho,...e.purposes};function n(){let r=ee()?window.Didomi:void 0;if(!r?.getCurrentUserStatus||r.shouldUserStatusBeCollected?.()!==!1||r.isUserStatusPartial?.()===!0)return null;let o=r.getCurrentUserStatus()?.purposes;if(!o||typeof o!="object")return null;let i=s=>Fo(o,t[s]);return Bt({analytics:i("analytics"),marketing:i("marketing"),personalisation:i("personalisation")},{ad_user_data:i("ad_user_data"),ad_personalization:i("ad_personalization")})}return{name:"didomi",read:n,observesChanges:!0,subscribe(r){if(!ee())return()=>{};let o=Ge(n,r),i={event:"consent.changed",listener:o.notify};return window.didomiEventListeners=window.didomiEventListeners||[],window.didomiEventListeners.push(i),window.didomiOnReady=window.didomiOnReady||[],window.didomiOnReady.push(s=>{o.notify(),(s??window.Didomi)?.on?.("consent.changed",o.notify)}),window.Didomi?.on?.("consent.changed",o.notify),o.stop}}}function Mt(e){let t={};if(!e)return t;for(let n of String(e).split("&")){let r=n.indexOf("=");if(r<=0)continue;let o=n.slice(r+1).replace(/\+/g," ");try{o=decodeURIComponent(o)}catch{}t[n.slice(0,r)]=o}return t}function qn(e={}){let t={analytics:"C0002",personalisation:"C0003",marketing:"C0004",...e.groups},n=e.impliedConsent===!0;function r(){let s=Mt(V("OptanonConsent"));if(s.groups){let d={};for(let f of s.groups.split(",")){let[p,g]=f.split(":");p?.trim()&&(d[p.trim()]=g==="1"?!0:g==="0"?!1:null)}return f=>d[f]??!1}let c=ee()?window.OnetrustActiveGroups:void 0;if(typeof c!="string"||!c.length)return null;let u=new Set(c.split(",").map(d=>d.trim()).filter(Boolean));return d=>u.has(d)}function o(){if(V("OptanonAlertBoxClosed"))return!0;try{if(ee()&&window.OneTrust?.IsAlertBoxClosed?.()===!0)return!0}catch{}return Number.parseInt(Mt(V("OptanonConsent")).interactionCount,10)>0?!0:n&&ee()&&(!!window.OneTrust||typeof window.OnetrustActiveGroups=="string")}function i(){if(!o())return null;let s=r();if(!s)return null;let c=p=>t[p]?s(t[p]):null,u=Bt({analytics:c("analytics"),marketing:c("marketing"),personalisation:c("personalisation")},{ad_user_data:c("ad_user_data"),ad_personalization:c("ad_personalization")}),d=Mt(V("OptanonConsent"));return(typeof navigator<"u"&&navigator.globalPrivacyControl===!0||d.isGpcEnabled==="1")&&(u.marketing=!1,u.ad_user_data=!1,u.ad_personalization=!1),u}return{name:"onetrust",read:i,observesChanges:!0,subscribe(s){if(!ee())return()=>{};let c=Ge(i,s),u=!1,d=()=>{u||!window.OneTrust?.OnConsentChanged||(u=!0,window.OneTrust.OnConsentChanged(c.notify))};window.addEventListener("OneTrustGroupsUpdated",c.notify);let f=window.OptanonWrapper;return window.OptanonWrapper=function(...g){try{typeof f=="function"&&f.apply(this,g)}finally{d(),c.notify()}},d(),()=>{c.stop(),window.removeEventListener("OneTrustGroupsUpdated",c.notify)}}}}function qo(e){let t=String(e).split(",").map(n=>n.trim()).filter(Boolean);return t.length?new Set(t):null}function Kn(e){let{name:t,categories:n,parse:r=qo,refusedValue:o,source:i="native",changeEvent:s="thg_hp_consent_change"}=e??{};if(typeof t!="string"||t==="")throw new Error("cookieConsent: `name` (the cookie your banner writes) is required");if(!n||typeof n.analytics!="string")throw new Error("cookieConsent: `categories.analytics` (the category id that grants analytics) is required");function c(){let u=V(t);if(u==null)return null;let d;if(o!==void 0&&u===o)d=new Set;else try{d=r(u)}catch{d=null}if(!(d instanceof Set))return null;let f=p=>n[p]?d.has(n[p]):null;return Bt({analytics:f("analytics"),marketing:f("marketing"),personalisation:f("personalisation")},{ad_user_data:f("ad_user_data"),ad_personalization:f("ad_personalization")})}return{name:i,read:c,get observesChanges(){return Hn()},subscribe(u){if(!ee())return()=>{};let d=Ge(c,u),f=p=>{[...p.changed??[],...p.deleted??[]].some(A=>A?.name===t)&&d.notify()};return window.addEventListener(s,d.notify),window.cookieStore?.addEventListener?.("change",f),()=>{d.stop(),window.removeEventListener(s,d.notify),window.cookieStore?.removeEventListener?.("change",f)}}}}function Gn(e={}){let t=e.name??C("consent"),n=()=>{let r=V(t);if(r==null)return null;let o=Ce(r);return o.analytics==null?null:o};return{name:"forwarded",read:n,get observesChanges(){return Hn()},subscribe(r){if(!ee())return()=>{};let o=Ge(n,r),i=s=>{[...s.changed??[],...s.deleted??[]].some(u=>u?.name===t)&&o.notify()};return window.cookieStore?.addEventListener?.("change",i),()=>{o.stop(),window.cookieStore?.removeEventListener?.("change",i)}}}}function zn(e){let t=_e(e);return{name:"static",basis:Ke.host,read:()=>t?{...t}:null,observesChanges:!0,subscribe:()=>()=>{}}}function Wn(e){if(e==null)return null;let t=String(e).split("/").map(n=>n.trim()).filter(Boolean).join("/");return t===""?null:t}function Ko(e){let t=e.item_category;if(t!=null&&String(t).includes("/"))return Wn(t);let n=[t,e.item_category2,e.item_category3,e.item_category4,e.item_category5].map(r=>r==null?"":String(r).trim()).filter(Boolean);return Wn(n.join("/"))}var Go=e=>{if(e==null||typeof e=="object")return null;let t=String(e).trim();return t===""?null:t};function zo(...e){for(let t of e){if(typeof t=="number"&&Number.isFinite(t))return String(t);if(typeof t=="string"&&t.trim()!=="")return t.trim()}return null}var ze=e=>zo(e.item_group_id,e.item_id);function Wo(e,t=ze){if(!e)return null;let n=c=>c==null||c===""||Number.isNaN(Number(c))?null:Number(c),r=c=>{let u=n(c);return u==null?null:Math.round(u*1e6)/1e6},o=c=>{let u=r(c);return u!=null&&u>=0?u:null},i=c=>{let u=n(c);return Number.isInteger(u)&&u>=0?u:null},s=Go;return{product_id:s(t(e)),sku:s(e.item_id),name:s(e.item_name),brand:s(e.item_brand),variant:s(e.item_variant)??s(e.variant),category:Ko(e),price:r(e.price),discount:o(e.discount),quantity:i(e.quantity),coupon:s(e.coupon),position:i(e.index)!=null?i(e.index)+1:null,url:s(e.url)??s(e.item_url)??null,image_url:s(e.image_url)??s(e.image_link)??null,displayed_sku:s(e.displayed_sku)??s(e.displayed_variant_sku)}}function jt(e,t=ze){return(e??[]).map(n=>Wo(n,t)).filter(n=>n?.product_id)}var Jo=1e3,Yo={shipping:2,payment:3},Xo=new Set(["password","google","apple","facebook","magic_link","sso","passkey","other"]),H=e=>{if(e==null||typeof e=="object")return null;let t=String(e).trim();return t===""?null:t},Zo=e=>{if(e==null||e===""||typeof e=="object")return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:null},We=e=>e!==null&&typeof e=="object";function Qo(e){return Array.isArray(e.items)?e.items.filter(We):null}function Jn(e){let t=H(e)?.toLowerCase().replace(/[\s-]+/g,"_");return t?Xo.has(t)?t:t==="email"||t==="email_password"?"password":"other":null}function es({ecommerce:e,items:t}){let n=i=>({promotion_id:H(i.promotion_id),name:H(i.promotion_name),creative:H(i.creative_name),position:H(i.creative_slot)}),r=new Set,o=[];for(let i of[n(e),...t.map(n)])!i.promotion_id||r.has(i.promotion_id)||(r.add(i.promotion_id),o.push(i));return o}var Yn=({ecommerce:e,items:t})=>H(e.item_list_id)??H(e.item_list_name)??H(t[0]?.item_list_id)??H(t[0]?.item_list_name),pe=(e,t)=>t.products?.length?{event:e,properties:t}:null,ts=new Set(["product","products","item","items"]);function ns({ecommerce:e}){let t=H(e.item_id),n=H(e.content_type)?.toLowerCase();return!t||n&&!ts.has(n)?null:{event:"Product Shared",properties:{share_via:H(e.method),products:[{product_id:t}]}}}function rs(e){let t=o=>pe("Product List Viewed",{list_id:Yn(o),products:o.products}),n=o=>{let i=H(o.ecommerce.search_term);return i?{event:"Products Searched",properties:{query:i,...o.products.length?{products:o.products}:{}}}:null},r=o=>i=>i.promotions.map(s=>({event:o,properties:s}));return{view_item:o=>pe("Product Viewed",{currency:o.currency,value:o.value,products:o.products.slice(0,1)}),view_item_list:t,view_search_results:o=>n(o)??t(o),search:n,select_item:o=>pe("Product Clicked",{list_id:Yn(o),products:o.products.slice(0,1)}),add_to_cart:o=>pe("Product Added",{cart_id:H(o.ecommerce.cart_id),products:o.products}),remove_from_cart:o=>pe("Product Removed",{cart_id:H(o.ecommerce.cart_id),products:o.products}),view_cart:o=>({event:"Cart Viewed",properties:{cart_id:H(o.ecommerce.cart_id),value:o.value,currency:o.currency,coupon:H(o.ecommerce.coupon),...o.itemsListed?{products:o.products}:{}}}),begin_checkout:o=>pe("Checkout Started",{value:o.value,currency:o.currency,coupon:H(o.ecommerce.coupon),products:o.products}),add_shipping_info:o=>({event:"Checkout Step Completed",properties:{step:e.shipping,step_name:"shipping",shipping_method:H(o.ecommerce.shipping_tier)}}),add_payment_info:o=>({event:"Payment Info Entered",properties:{step:e.payment,step_name:"payment",payment_method:H(o.ecommerce.payment_type)}}),view_promotion:r("Promotion Viewed"),select_promotion:r("Promotion Clicked"),add_to_wishlist:o=>pe("Product Added to Wishlist",{products:o.products}),share:ns,login:o=>({event:"Signed In",properties:{method:Jn(o.ecommerce.method)}}),sign_up:o=>({event:"Signed Up",properties:{method:Jn(o.ecommerce.method)}})}}var os=e=>e.event;function ss(e,t){if(!We(e))return null;if(typeof e.length=="number"&&e[0]==="event"&&typeof e[1]=="string"){let r=We(e[2])?e[2]:{};return{name:e[1],entry:r,ecommerce:r}}let n=H(t(e));return n?{name:n,entry:e,ecommerce:We(e.ecommerce)?e.ecommerce:e}:null}function Ht(e){return Array.isArray(e)?`[${e.map(Ht).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Ht(e[t])}`).join(",")}}`:JSON.stringify(e??null)}function Xn(e,t={}){if(!e||typeof e.track!="function")throw new Error("connectDataLayer: analytics must have a track(event, properties, options) method");let n=t.dataLayer??(typeof window<"u"?window.dataLayer=window.dataLayer||[]:null);if(!Array.isArray(n))return()=>{};let r=rs({...Yo,...t.steps}),o=t.map??{},i=t.eventName??os,s=t.productId??ze,c=new Set(["purchase","refund",...t.ignore??[]]),u=t.dedupeMs??Jo,d=new Map,f=!0;function p(S,h,y){if(u<=0)return!1;let O=`${S}|${y??""}|${Ht(h)}`,N=Date.now();for(let[U,G]of d)N-G>u&&d.delete(U);return d.has(O)?!0:(d.set(O,N),!1)}let g=null,A=new Set;function w(S,h){if(S!=="Product Viewed")return!1;let y=typeof location>"u"?"":location.pathname;y!==g&&(g=y,A.clear());let O=h.products?.[0]?.product_id;return O?A.has(O)?!0:(A.add(O),!1):!1}function x({event:S,properties:h={}},y){if(!S||p(S,h,y)||w(S,h))return;let O=y?{context:{currency:y}}:void 0;if(S==="Signed Out"&&typeof e.signedOut=="function"){e.signedOut(O);return}e.track(S,h,O)}function _(S){let h=t.transform?t.transform(S):S,y=ss(h,i);if(!y||c.has(y.name))return;let O=Object.hasOwn(o,y.name),N=O?o[y.name]:r[y.name];if(typeof N!="function")return;let U=Qo(y.ecommerce),G=U??[],K={...y,items:G,itemsListed:U!==null,products:jt(G,s),currency:Pt(y.ecommerce.currency),value:Zo(y.ecommerce.value)};K.promotions=es(K);let ie=O?N(h,{...K,toProducts:J=>jt(J,s)}):N(K);for(let J of[ie].flat())J&&x(J,K.currency)}function k(S){if(f)try{_(S)}catch(h){try{t.onError?.(h,S)}catch{}}}for(let S of n.slice())k(S);let m=n.push;function E(...S){let h=m.apply(this,S);for(let y of S)k(y);return h}return n.push=E,()=>{f=!1,n.push===E&&(n.push=m)}}var is="hp_debug",as=256;function cs(){try{return new URLSearchParams(location.search).get(is)}catch{return null}}function Zn(e,t){if(typeof location>"u")return!1;try{let n=cs();if(n!==null){let o=n.trim();o===""||o.length>as?sessionStorage.removeItem(t):sessionStorage.setItem(t,o)}let r=sessionStorage.getItem(t);return!!(e&&r&&Sn(r)===e)}catch{return!1}}var be=class extends Error{},us={inHoldout:()=>!0,personalisationGroup:()=>"excluded",servingHeaders:()=>({}),recommendationContext:()=>({}),flush:()=>Promise.resolve(),reset:()=>{}};function Ft(e,t){let n=us[e]??(()=>null),r=o=>(console.warn(`[hp] ${String(e)} failed; nothing was sent`,o),n());return function(...i){try{let s=t.apply(this,i);return typeof s?.then=="function"?Promise.resolve(s).catch(r):s}catch(s){if(s instanceof be)throw s;return r(s)}}}function Qn(e){for(let t of Reflect.ownKeys(e)){let{value:n}=Object.getOwnPropertyDescriptor(e,t)??{};typeof n=="function"&&(e[t]=Ft(t,n))}return e}var Oe=Symbol("hp.identityOption");var ls=4320*60*60,ds=100,fs=1e3,ps=2e3,er=500,Je=e=>(e?.unref?.(),e);function ms(e,t){if(t?.analytics===!0&&e.analytics===!1)return"withdrawn";let n=fe.map(r=>e[r]).filter(r=>r!==null);return n.length&&n.every(Boolean)?"accept_all":n.length&&n.every(r=>!r)?"reject_all":"custom"}function hs(e,t,n=C("consent")){if(!(typeof document>"u"))try{let r=typeof location<"u"&&location.protocol==="https:"?"; Secure":"",o=t?`; Domain=${t}`:"";document.cookie=`${n}=${Ut(e)}; Path=/; Max-Age=${ls}; SameSite=Lax`+o+r}catch{}}function gs(e){let t=Ce(V(e));return fe.some(n=>t[n]!==null)?t:null}function tr(e){let{adapter:t,timeoutMs:n=5e3,cookieDomain:r=null,cookieName:o=C("consent"),release:i,announce:s}=e,c=e.discard??(()=>{}),u="pending",d=null,f=null,p=null,g=null,A=!1,w=null,x=[],_=R=>{u=R,e.onStatus?.(R)};function k(){try{return _e(t.read())}catch{return null}}function m(){f&&clearInterval(f),p&&clearTimeout(p),f=null,p=null}let E=()=>typeof window<"u"&&typeof document<"u",S=()=>{try{return typeof t.subscribe=="function"&&t.observesChanges===!0}catch{return!1}};function h(){g&&clearInterval(g),g=null}function y(){A||g||d===null||S()||E()&&document.visibilityState==="hidden"||(g=Je(setInterval(()=>K(k()),ps)))}let O=()=>u==="pending"||u==="unknown",N=e.store??null,U=()=>{let R=x.splice(0);N?.write([]);for(let j of R)i(j)},G=()=>{let R=x.splice(0);N?.write([]);for(let j of R)c(j)};function K(R){let j=_e(R);if(!j||j.analytics===null)return;let we=d===null,X=we?gs(o):d;if(!we&&Dt(X,j))return;m(),d=j,y(),hs(j,r,o);let gt=!Dt(X,j);if(j.analytics){_("granted"),U(),gt&&s({action:ms(j,X),state:j,previous:X,withdrawal:!1});return}G(),X?.analytics===!0&&s({action:"withdrawn",state:j,previous:X,withdrawal:!0}),_("denied")}function ie(){p=null,u==="pending"&&(_("unknown"),f&&clearInterval(f),f=Je(setInterval(()=>K(k()),fs)))}function J(R){if(O()){if(N){N.write(x);return}R?.type!=="visibilitychange"&&!R?.persisted&&G()}}let Ue=R=>{document.visibilityState==="hidden"?(h(),J(R)):y()},ae=R=>{h(),J(R)},Ve=R=>{R?.persisted&&d!==null&&K(k()),y()};return{get status(){return u},get state(){return d?{...d}:null},stamp(){return d?{...d,source:t.name??null,basis:t.basis??Ke.visitor}:null},admits(){return u==="granted"},hold(R){return!O()||x.length>=er?(c(R),!1):(x.push(R),!0)},onHidden:J,start(){A=!1;try{w=t.subscribe?.(R=>K(R))??null}catch(R){e.debug&&console.warn("[hp] consent adapter subscribe failed",R)}E()&&(window.addEventListener("pagehide",ae),window.addEventListener("pageshow",Ve),document.addEventListener("visibilitychange",Ue)),N&&x.length===0&&x.push(...N.read().slice(-er)),K(k()),!d&&(f=Je(setInterval(()=>K(k()),ds)),p=Je(setTimeout(ie,n)))},stop(){A=!0,m(),h(),typeof w=="function"&&w(),E()&&(window.removeEventListener("pagehide",ae),window.removeEventListener("pageshow",Ve),document.removeEventListener("visibilitychange",Ue))}}}var ys=["recommendation","search_rank","banner","offer","layout","copy","price","other"],Ye=e=>typeof e=="string"&&e!=="";function nr(e){return(Array.isArray(e?.decisions)?e.decisions:[]).filter(t=>Ye(t?.slot)&&Ye(t.decision_id)&&t.holdout!==!0).map(({decision_id:t,slot:n,arm:r,kind:o})=>({decision_id:t,slot:n,...Ye(r)&&{arm:r},...ys.includes(o)&&{kind:o}}))}function rr({key:e,mayStore:t}){let n,r=()=>{if(n)return n;try{let i=JSON.parse(sessionStorage.getItem(e));n=Array.isArray(i)?i.filter(s=>Ye(s?.slot)):[]}catch{n=[]}return n},o=()=>{try{n?.length&&t()&&sessionStorage.setItem(e,JSON.stringify(n))}catch{}};return{persist:o,current:()=>r().length?n.map(i=>({...i})):null,remember(i){if(!i.length)return;let s=new Set(i.map(c=>c.slot));n=[...r().filter(c=>!s.has(c.slot)),...i],o()},forget(){n=[];try{sessionStorage.removeItem(e)}catch{}}}}function ws(e){let t=2166136261,n=String(e);for(let r=0;r<n.length;r+=1)t^=n.charCodeAt(r),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t^=t>>>16,t=Math.imul(t,2246822507)>>>0,t^=t>>>13,t=Math.imul(t,3266489909)>>>0,t^=t>>>16,t>>>0}function Xe(e,t,n=1e4){return ws(`${t}\0${e}`)%n}function qt(e){let t=o=>Math.min(Math.max(Number(o)||0,0),1),n=t(e.share),r=1-n;return{holdout_share:n,personalised_share:e.ramp==null?r:Math.min(t(e.ramp),r)}}function Kt(e,t){if(!e||typeof e.salt!="string")return{holdout:!1,bucket:null,group:"personalised"};let n=e.ramp!=null;if(t==null||t==="")return{holdout:!1,bucket:null,group:n?"excluded":"personalised"};let{holdout_share:r,personalised_share:o}=qt(e),i=Xe(t,e.salt),s=u=>Math.round(u*1e4),c=r>0&&i<s(r)?"holdout":!n||i<s(r+o)?"personalised":"excluded";return{holdout:c==="holdout",bucket:i,group:c}}function or(e,t){return typeof e!="string"||e===""||t==null||t===""?null:Xe(t,`bandit-vs-default:${e}`)<1e4/2?"default":"bandit"}var Ss="hp_preview",_s=256;function sr(e,t=null){if(typeof location>"u")return V(e);let n=null;try{n=new URLSearchParams(location.search).get(Ss)}catch{n=null}if(n===null)return V(e);let r=n.trim();return r===""||r.length>_s?(re(e,"",0,t),null):(re(e,r,null,t),r)}var bs=40,Is=128,xs=5,ks=60,ar=e=>typeof e=="string"&&e!==""&&e.length<=Is&&!e.includes(","),ir=e=>Array.isArray(e)?e.filter(ar).slice(0,bs):[],As=e=>Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.replaceAll(","," ").trim()).filter(t=>t!=="").slice(0,xs):[],vs=e=>Object.entries(e&&typeof e=="object"?e:{}).filter(([t,n])=>ar(t)&&Number.isFinite(n)&&n>=1).sort(([,t],[,n])=>n-t).slice(0,ks).map(([t,n])=>`${t}:${Math.floor(n)}`);function Gt(e){let t={},n={viewed:ir(e?.recentProducts),basket:ir(e?.basketProducts),q:As(e?.recentSearches),impressed:vs(e?.impressions)};for(let[r,o]of Object.entries(n))o.length>0&&(t[r]=o.join(","));return t}var Es=1800*1e3;function cr(e,t=Date.now()){try{localStorage.setItem(C("recommendationContext"),JSON.stringify({context:e,until:t+Es}))}catch{}}function ur(){try{localStorage.removeItem(C("recommendationContext"))}catch{}}var Cs="hp_sample",lr=1e4;function dr(e,t){return!(typeof t=="number"&&t<1)||e==null||e===""?!0:Xe(e,Cs,lr)<Math.round(t*lr)}function Ie(e){return e.trim().toLowerCase().replace(/\s*\/\s*/g,"/").replace(/^\/+|\/+$/g,"")}var Os=2,Ps=12;function Pe(e,t=Os){return e.split("/").slice(0,t).join("/")}function zt(e,t){if(typeof t!="string"||!t.trim())return null;let n=Pe(Ie(t));return n?(e.unshift(n),e.length=Math.min(e.length,Ps),n):null}var me=()=>C("sessionSignals"),xe=null,Wt=()=>xe??me();function fr(){try{return xe?localStorage:sessionStorage}catch{return}}function pr(e,t){let n=t==null?null:String(t),r=e?$(me(),n,e):null;if(r===xe)return;let o=xe===null?Ls():null;if(xe=r,!!xe)try{let i=Wt(),s=Dn(me(),n);for(let c of Object.keys(localStorage))c.startsWith(s)&&c!==i&&localStorage.removeItem(c);o&&!localStorage.getItem(i)&&(localStorage.setItem(i,JSON.stringify(o)),sessionStorage.removeItem(me()))}catch{}}function Ls(){try{let e=sessionStorage.getItem(me());if(!e)return null;let t=JSON.parse(e);return t&&(t.productViews>0||t.listViews>0||t.basketValue!=null||t.recentProducts?.length||t.recentBrowse?.length)?t:null}catch{return null}}function Ze(){return{productViews:0,listViews:0,cartAdds:0,searches:0,recentProducts:[],recentCategories:[],recentBrowse:[],basketProducts:[],basketValue:null,recentSearches:[],impressions:{},browsingCategory:null,recentBrowseCategories:[],browsingListing:null,listViewsByCategory:{},startedAt:0}}function Jt(){let e=fr();if(!e)return Ze();try{let t=e.getItem(Wt());return t?{...Ze(),...JSON.parse(t)}:{...Ze(),startedAt:Date.now()}}catch{return{...Ze(),startedAt:Date.now()}}}function Yt(e){let t=fr();if(t)try{t.setItem(Wt(),JSON.stringify(e))}catch{}}function Qe(){return Jt()}function mr(){for(let e of[()=>sessionStorage,()=>localStorage])try{let t=e();t.removeItem(me());for(let n of Object.keys(t))n.startsWith(`${me()}:`)&&t.removeItem(n)}catch{}}var hr=20,gr=200,Ts=new Set(["Product Viewed","Product Clicked","Product Added","Product Added to Wishlist"]),Ns=new Set(["Product Viewed","Product Added"]),yr=50;function et(e,t){let n=zt(e.recentBrowse,t);return n?(e.recentBrowseCategories=[e.browsingListing?.category??null,...e.recentBrowseCategories].slice(0,e.recentBrowse.length),n):null}function Rs(e,t){let n=e.listViewsByCategory;n[t]=(n[t]??0)+1;let r=Object.keys(n);if(r.length>yr){let o={};for(let i of r.sort((s,c)=>n[c]-n[s]).slice(0,yr))o[i]=n[i];e.listViewsByCategory=o}}function wr(e,t){let n=Jt();n.startedAt||(n.startedAt=Date.now());let r=Array.isArray(t?.products)?t.products:[];switch(e){case"Product Viewed":n.productViews+=1,et(n,n.browsingCategory);break;case"Product List Viewed":{let s=t?.list_id,c=t?.category;if(!(typeof s=="string"&&s.includes("/")&&!s.startsWith("cdp-")))break;let d=typeof c=="string"&&Pe(Ie(c))||null,f=d?Pe(Ie(s)):"";if(!f){n.browsingCategory=null,n.browsingListing=null;break}n.browsingListing={key:f,category:d},et(n,f),n.browsingCategory=f,Rs(n,d),n.listViews+=1}break;case"Product List Filtered":{let s=t?.change,c=typeof t?.list_id=="string"?t.list_id:"",u=typeof s?.value=="string"?s.value:"",d=n.browsingListing;if(u&&s?.action!=="removed"&&d&&Pe(Ie(c))===d.key){let f=et(n,`${c}/${u}`);f&&(n.browsingCategory=f)}break}case"Product Added":{n.cartAdds+=1,et(n,n.browsingCategory);for(let s of r){let c=s.product_id;typeof c!="string"||!c||(n.basketProducts=[c,...n.basketProducts.filter(u=>u!==c)].slice(0,hr))}break}case"Product Removed":{for(let s of r){let c=s.product_id;typeof c=="string"&&c&&(n.basketProducts=n.basketProducts.filter(u=>u!==c))}break}case"Products Searched":{n.searches+=1;let s=t?.query;if(typeof s=="string"&&s.trim()){let c=s.trim().toLowerCase().slice(0,64);n.recentSearches=[c,...n.recentSearches.filter(u=>u!==c)].slice(0,5)}break}case"Product Clicked":case"Product Added to Wishlist":break;case"Cart Updated":{let s=t?.value;return n.basketValue=typeof s=="number"&&Number.isFinite(s)&&s>=0?s:null,Yt(n),n}default:return n}let o=Ts.has(e);if(o)for(let s of r)typeof s.product_id=="string"&&s.product_id&&delete n.impressions[s.product_id];else{for(let c of r){let u=c.product_id;typeof u!="string"||!u||(n.impressions[u]=(n.impressions[u]??0)+1)}let s=Object.keys(n.impressions);if(s.length>gr){let c={};for(let u of s.sort((d,f)=>n.impressions[f]-n.impressions[d]).slice(0,gr))c[u]=n.impressions[u];n.impressions=c}}let i=new Set;for(let s of r){let c=s.product_id;if(o&&typeof c=="string"&&c&&(n.recentProducts=[c,...n.recentProducts.filter(u=>u!==c)].slice(0,hr)),Ns.has(e)&&typeof s.category=="string"&&s.category){let u=Ie(s.category);u&&!i.has(u)&&(i.add(u),zt(n.recentCategories,u))}}return Yt(n),n}var tt=1800*1e3;function Sr({name:e,domain:t=null,mayStore:n,now:r=()=>Date.now(),mint:o=ne}){let i=null,s=0,c=()=>{i!==null&&n()&&re(e,i,tt/1e3,t)};return{get(){let u=r(),d=V(e);return d?i=d:(i===null||u-s>=tt)&&(i=o()),s=u,c(),i},persist:c,forget(){re(e,"",0,t),i=null}}}var W=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),_r=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"),br=Object.freeze({enabled:!1}),Zt=Object.freeze({enabled:!0,queryParamAllowlist:Object.freeze([])});function Ir(e,t){let n=e?.track;return W(n)?(Object.hasOwn(n,t)?n[t]:n.__default)?.enabled!==!1:!0}function Ms(e,t){return`${oe(e)}/v1/projects/${encodeURIComponent(t)}/settings`}var Ds="https://hp.thgingenuity.com";function oe(e){return e==null||e===""?Ds:kr(e)}function xr(e,t){return e!=null&&e!==""?oe(e):t?.startsWith("https://")?t:oe(void 0)}function kr(e){if(typeof e!="string")return null;let t=e.trim().replace(/\/+$/,"");return/^https?:\/\/[^/\s]+$/i.test(t)?t:/^[a-z0-9.-]+(:\d+)?$/i.test(t)?`https://${t}`:null}function Us(e){if(!W(e))return null;let t=Object.fromEntries(Object.entries(e).filter(([,n])=>typeof n=="boolean"));return Object.keys(t).length?t:null}var Xt=e=>typeof e=="number"&&e>=0&&e<=1,Vs=/^[0-9a-f]{64}$/;function $s(e){return W(e)?{enabled:e.enabled===!0,tokenSha256:typeof e.tokenSha256=="string"&&Vs.test(e.tokenSha256)?e.tokenSha256:null}:{enabled:!1,tokenSha256:null}}function Bs(e){if(!W(e))return null;let t=Object.fromEntries(Object.entries(e).filter(([,n])=>W(n)&&Xt(n.share)&&(n.ramp==null||Xt(n.ramp))&&typeof n.salt=="string"&&n.salt!=="").map(([n,r])=>[n,{share:r.share,ramp:r.ramp??null,salt:r.salt,..._r(r.readoutSlots)&&r.readoutSlots.length>0&&{readoutSlots:r.readoutSlots}}]));return Object.keys(t).length?t:null}var js=/^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;function Hs(e){return W(e)?e.source==="hp_cookie"?{source:"hp_cookie"}:e.source!=="site_cookie"?null:e.cookie==null?{source:"site_cookie",cookie:null}:typeof e.cookie=="string"&&js.test(e.cookie)?{source:"site_cookie",cookie:e.cookie}:null:null}function Fs(e){let t=Array.isArray(e?.forms)?e.forms.filter(W):[];return t.length===0?null:{forms:t,capture:W(e.capture)?e.capture:null,...Number.isInteger(e.overlay_gap_minutes)?{overlay_gap_minutes:e.overlay_gap_minutes}:{}}}function qs(e){let t=W(e)?e.hp:null;return W(t)&&typeof t.enabled=="boolean"}function Qt(e){let t=W(e)?e.hp:null;if(!W(t)||t.enabled!==!0)return br;let n=Fs(t.onsite);return{enabled:!0,propertyId:typeof t.propertyId=="string"&&t.propertyId!==""?t.propertyId:null,environment:typeof t.environment=="string"?t.environment:null,consentPurposes:Us(t.consent?.purposes),queryParamAllowlist:_r(t.queryParamAllowlist)?t.queryParamAllowlist:null,anonymousId:Hs(t.anonymousId),apiHost:kr(t.apiHost),holdouts:Bs(t.holdouts),sampleRate:Xt(t.sampleRate)?t.sampleRate:1,debug:$s(t.debug),...n&&{onsite:n},plan:W(e.plan)&&W(e.plan.track)?{track:e.plan.track}:null}}var Ks=3e3;async function Ar(e,t,n=globalThis.fetch,r=Ks){try{let o=await n(Ms(e,t),{credentials:"omit",headers:{accept:"application/json"},signal:AbortSignal.timeout?.(r)});if(o.status>=400&&o.status<500&&o.status!==408&&o.status!==429)return br;if(!o.ok)return null;let i=await o.json();return qs(i)?Qt(i):null}catch{return null}}var nt=e=>$(C("settings"),e);function vr(e){try{let t=localStorage.getItem(nt(e));if(!t)return null;let n=JSON.parse(t);return n?.enabled===!0?n:null}catch{return null}}function Er(e,t){try{t?.enabled===!0?localStorage.setItem(nt(e),JSON.stringify(t)):localStorage.removeItem(nt(e))}catch{}}function en(e){try{localStorage.removeItem(nt(e))}catch{}}var Gs={flushAt:20,flushIntervalMs:1e4,maxQueue:500,maxRetryAgeMs:1440*60*1e3,maxRetries:5,maxPersistedBatches:20,maxPersistedBytes:1024*1024,storageKey:de.retry,beaconSafeBytes:56*1024,maxBatchEvents:100,maxBatchBytes:500*1024},rt=()=>Date.now(),Cr=3e4,an=55*1024;function zs(e,t=rt()){if(typeof e!="string")return 0;let n=e.trim();if(/^\d+$/.test(n))return Number(n)*1e3;if(n==="")return 0;let r=Date.parse(n);return Number.isNaN(r)?0:Math.max(0,r-t)}var se=e=>typeof TextEncoder<"u"?new TextEncoder().encode(e).length:Buffer.byteLength(e),tn=()=>typeof window<"u"&&typeof document<"u";function Ws(){try{return!tn()||!window.localStorage?null:(window.localStorage.getItem("thg_hp_probe"),window.localStorage)}catch{return null}}var b,nn,rn,ot,on,sn,Or,Le,Te,Ne,Pr,st,Lr,it,at=class{constructor(t){yn(this,b);this.o={...Gs,...t},this.queue=[],this.timer=null,this.storage=Ws(),this.inflight=null,this.sending=new Set,this.epoch=0,this.sinceRefusal=new Set,this.wakers=new Set,this.replayAllowed=!this.o.deferReplay,this.draining=null,this.failing=!1,this.answered=!1,tn()&&(window.addEventListener("pagehide",()=>this.flush({beacon:!0})),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush()}),L(this,b,it).call(this))}markFailing(){this.answered||(this.failing=!0)}replayPersisted(){return this.replayAllowed=!0,L(this,b,it).call(this)}clearPersisted(){if(this.replayAllowed=!1,!!this.storage)try{let t=L(this,b,Ne).call(this).filter(n=>this.sinceRefusal.has(n?.id));t.length?this.storage.setItem(this.o.storageKey,JSON.stringify(t)):this.storage.removeItem(this.o.storageKey)}catch{}}discardQueued(){this.queue=[],this.epoch+=1,this.sinceRefusal.clear(),L(this,b,rn).call(this);for(let t of this.wakers)t()}enqueue(t){let n;try{n=JSON.parse(JSON.stringify(t))}catch(r){this.o.onError?.(`event ${t?.messageId??""} cannot be serialised; dropped`,r);return}this.queue.push(n),this.queue.length>this.o.maxQueue&&this.queue.splice(0,this.queue.length-this.o.maxQueue),this.queue.length>=this.o.flushAt?this.flush():L(this,b,nn).call(this)}flush(t={}){if(L(this,b,rn).call(this),this.queue.length===0)return Promise.resolve();if(t.beacon&&tn()&&typeof navigator<"u"&&navigator.sendBeacon)return L(this,b,Or).call(this),Promise.resolve();if(this.inflight)return this.inflight;let n=L(this,b,sn).call(this,this.queue,this.o.maxBatchEvents,this.o.maxBatchBytes).map(o=>{let i=L(this,b,st).call(this,o);return i&&(this.sending.add(i),this.sinceRefusal.add(i)),{batch:o,id:i}});this.queue=[];let r=this.epoch;return this.inflight=(async()=>{for(let{batch:o,id:i}of n){if(r!==this.epoch){L(this,b,Te).call(this,i);continue}await L(this,b,Le).call(this,o,0,i,r)}})().finally(()=>{this.inflight=null,this.queue.length>=this.o.flushAt?this.flush():this.queue.length&&L(this,b,nn).call(this)}),this.inflight}};b=new WeakSet,nn=function(){this.timer||(this.timer=setTimeout(()=>this.flush(),this.o.flushIntervalMs),this.timer?.unref?.())},rn=function(){this.timer&&(clearTimeout(this.timer),this.timer=null)},ot=function(t){return JSON.stringify({batch:t,writeKey:this.o.writeKey,sentAt:new Date().toISOString()})},on=function(){return`${this.o.apiHost.replace(/\/$/,"")}/v1/batch`},sn=function(t,n,r){let o=se(L(this,b,ot).call(this,[])),i=[],s=[],c=o;for(let u of t){let d=se(JSON.stringify(u))+1;s.length&&(s.length>=n||c+d>r)&&(i.push(s),s=[],c=o),s.push(u),c+=d}return s.length&&i.push(s),i},Or=function(){let t=this.queue;this.queue=[];let n=L(this,b,on).call(this);for(let r of L(this,b,sn).call(this,t,this.o.maxBatchEvents,this.o.beaconSafeBytes)){let o=L(this,b,ot).call(this,r);if(se(o)<=this.o.beaconSafeBytes){let i=!1;try{i=navigator.sendBeacon(n,new Blob([o],{type:"text/plain"}))}catch{i=!1}if(i){let s=this.failing?L(this,b,st).call(this,r):null;s&&this.sending.add(s);continue}}L(this,b,Le).call(this,r,0,L(this,b,st).call(this,r))}},Le=async function(t,n,r=null,o=this.epoch){r&&this.sending.add(r);let i=L(this,b,ot).call(this,t),s=0;try{let c=await fetch(L(this,b,on).call(this),{method:"POST",headers:{"Content-Type":"text/plain"},body:i,keepalive:se(i)<=this.o.beaconSafeBytes});if(c.ok)return this.failing=!1,this.answered=!0,L(this,b,Te).call(this,r),L(this,b,it).call(this),!0;let u=c.status===408||c.status===429||c.status>=500;if(u&&(s=zs(c.headers?.get?.("retry-after"))),!u)return L(this,b,Te).call(this,r),this.o.onError?.(`CDP ingest rejected batch (${c.status}); dropping ${t.length} events`),!0;throw new Error(`retryable ${c.status}`)}catch(c){if(this.failing=!0,n>=this.o.maxRetries){r&&this.sending.delete(r);let d=r?"kept for the next page":"dropped";return this.o.onError?.(`CDP ingest unreachable after ${n} attempts; ${d}: ${t.length} events`,c),!1}let u=Math.max(Math.min(1e3*2**n,Cr)*(.5+Math.random()),Math.min(s,Cr));return o===this.epoch&&await new Promise(d=>{let f=()=>{clearTimeout(p),this.wakers.delete(f),d()},p=setTimeout(f,u);this.wakers.add(f)}),o!==this.epoch?(L(this,b,Te).call(this,r),!1):L(this,b,Le).call(this,t,n+1,r,o)}},Te=function(t){t&&(this.sending.delete(t),this.sinceRefusal.delete(t),L(this,b,Lr).call(this,t))},Ne=function(){let t=JSON.parse(this.storage.getItem(this.o.storageKey)||"[]");return Array.isArray(t)?t:[]},Pr=function(t,n){let r=s=>se(JSON.stringify(s))+1,o=[...t,n].slice(-this.o.maxPersistedBatches),i=o.reduce((s,c)=>s+r(c),2);for(;o.length>1&&i>this.o.maxPersistedBytes;)i-=r(o[0]),o=o.slice(1);for(;o.length;)try{return this.storage.setItem(this.o.storageKey,JSON.stringify(o)),!0}catch{o=o.slice(1)}return!1},st=function(t){if(!this.storage||this.o.mayPersist&&!this.o.mayPersist())return null;try{let n={at:rt(),id:`${rt()}-${Math.random().toString(36).slice(2)}`,batch:t};return se(JSON.stringify(n))+3>this.o.maxPersistedBytes?null:L(this,b,Pr).call(this,L(this,b,Ne).call(this),n)?n.id:null}catch{return null}},Lr=function(t){if(!(!t||!this.storage))try{let n=L(this,b,Ne).call(this).filter(r=>r.id!==t);n.length?this.storage.setItem(this.o.storageKey,JSON.stringify(n)):this.storage.removeItem(this.o.storageKey)}catch{}},it=function(){if(!this.storage||!this.replayAllowed)return this.draining??Promise.resolve();if(this.draining)return this.draining;let t;try{let r=L(this,b,Ne).call(this);t=r.filter(o=>Array.isArray(o?.batch)&&rt()-o.at<this.o.maxRetryAgeMs).map(o=>o.id?o:{...o,id:`${o.at}-${Math.random().toString(36).slice(2)}`}),(t.length!==r.length||t.some((o,i)=>o!==r[i]))&&(t.length?this.storage.setItem(this.o.storageKey,JSON.stringify(t)):this.storage.removeItem(this.o.storageKey))}catch{return Promise.resolve()}let n=t.filter(r=>!this.sending.has(r.id));return n.length?(this.draining=(async()=>{for(let r of n)if(!this.replayAllowed||!await L(this,b,Le).call(this,r.batch,0,r.id))return})().finally(()=>{this.draining=null}),this.draining):Promise.resolve()};var Tr="3.26.0",Nr="@thg-agentic/hyper-personalisation-web";var Js=100,Ys=["source","medium","campaign","content","term"];function Mr(e){if(!e||typeof e!="object")return null;let t={};for(let n of Ys){let r=e[n==="campaign"?"name":n];typeof r=="string"&&r&&(t[n]=r.slice(0,Js))}return Object.keys(t).length?t:null}var Dr=e=>$(C("visitCampaign"),e==null?null:String(e)),ke=new Map;function Ur(e){if(ke.has(e))return ke.get(e);try{let t=JSON.parse(localStorage.getItem(e));return t&&typeof t=="object"?t:null}catch{return null}}function Rr(e,t){try{t?localStorage.setItem(e,JSON.stringify(t)):localStorage.removeItem(e),ke.delete(e)}catch{t?ke.set(e,t):ke.delete(e)}}function Vr(e,t,n){return typeof e?.tags=="object"&&e.tags!==null&&Number.isFinite(e.at)&&n-e.at<tt&&!(t&&e.sid&&e.sid!==t)?e:null}function $r(e,{sessionId:t=null,now:n=Date.now()}={}){return Vr(Ur(Dr(e)),t,n)?.tags??null}function Br(e,t,{sessionId:n=null,keepSession:r=!1,now:o=Date.now()}={}){let i=Dr(e),s=Ur(i),c=Vr(s,n,o),u=c?.tags??t??null;return u?Rr(i,{tags:u,at:o,sid:(r?n:null)??c?.sid??null}):s&&Rr(i,null),u}function cn(){ke.clear();try{let e=`${C("visitCampaign")}:`;for(let t of Object.keys(localStorage))t.startsWith(e)&&localStorage.removeItem(t)}catch{}}var Xs=new Set(["audiences","decisions","recommendations"]);var Zs=Symbol.for("@thg-agentic/hyper-personalisation-web.replay"),Qs=Symbol.for("@thg-agentic/hyper-personalisation-web.unreachable"),ei=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access");function ti(e){let t={...e??{}},n=Array.isArray(t.products)?t.products:null;if(t.item_count==null&&n){let r=n.map(o=>o?.quantity);r.every(Number.isInteger)&&(t.item_count=r.reduce((o,i)=>o+i,0))}return t}var ni="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";function ri(e){if(/^[0-9a-fA-F]{64}$/.test(e))return e.toLowerCase();if(!/^[A-Za-z0-9+/_-]{43}=?$/.test(e))return null;try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(44,"="));return t.length!==32?null:Array.from(t,n=>n.charCodeAt(0).toString(16).padStart(2,"0")).join("")}catch{return null}}function ut(e){if(typeof e!="string")return null;let t=ri(e.trim());return t===ni?null:t}var jr=Object.freeze({email_sha256:"sha256",phone_sha256:"sha256",accepts_marketing:"boolean",gender:"string",created_at:"date-time"}),oi=/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)$/i;function si(e){if(typeof e!="string"||!oi.test(e))return!1;let[t,n,r]=e.slice(0,10).split("-").map(Number),o=new Date(Date.UTC(t,n-1,r));return o.getUTCMonth()===n-1&&o.getUTCDate()===r&&!Number.isNaN(Date.parse(e))}function ii(e,t){return t===null?null:e==="sha256"?ut(t)??void 0:e==="date-time"?t instanceof Date?Number.isNaN(t.getTime())?void 0:t.toISOString():si(t)?t:void 0:typeof t===e?t:void 0}function ai(e,t){let n={},r=[];for(let[o,i]of Object.entries(e)){let s=Object.hasOwn(jr,o)?jr[o]:null,c=s?ii(s,i):void 0;c===void 0?r.push(o):n[o]=c}return t&&r.length&&console.warn(`[hp] identify: not sent, not spec traits: ${r.join(", ")}`),n}var Hr=!1,Fr=!1;function ci(){Fr||(Fr=!0,console.warn("[hp] no consent adapter: events are sent under the host's lawful basis (basis 'host'). Pass `consent` to send only once the visitor allows analytics."))}function ui(e){!e||Hr||(Hr=!0,console.warn("[hp] mintAnonymousId is ignored since 3.6: where device ids come from is set per source in the console (the site\u2019s own cookie, or Hyper-Personalisation\u2019s)."))}function li(e){try{return se(JSON.stringify(e))}catch{return 0}}function ct(e){return e&&typeof e.context=="object"&&e.context!==null?e.context:e}function di(e,t){if(e==null||String(e)===t)return;let n=[["localStorage","retry",(r,o)=>[...Array.isArray(r)?r:[],...Array.isArray(o)?o:[]]],["sessionStorage","held",(r,o)=>o?{...o,items:[...r.items??[],...o.items??[]]}:r]];for(let[r,o,i]of n)try{let s=globalThis[r],c=$(C(o),e),u=s?.getItem(c);if(!u)continue;let d=$(C(o),t),f=s.getItem(d);s.setItem(d,JSON.stringify(i(JSON.parse(u),f?JSON.parse(f):null))),s.removeItem(c)}catch{}}function qr(e){let t=oe(e?.apiHost);if(!t)throw new Error("createAnalytics: apiHost, when given, must be a host or an http(s) origin");if(e?.propertyId!==null&&!e?.propertyId)throw new Error("createAnalytics: propertyId is required (null: the ingest stamps the key\u2019s)");let n={libraryName:Nr,libraryVersion:Tr,writeKey:"web",queryParamBlocklist:[],debug:!1,validate:null,consentTimeoutMs:5e3,...e,apiHost:t};He(n.storageNames),Fe();let r=!!n.consent;r||ci();let o=null;n.getConsent=()=>o?o.stamp():Bn();let i=()=>!r||o?.status==="granted";di(n.propertyId,n.writeKey);let s=r&&n.holdAcrossPages?Un($(C("held"),n.writeKey)):null,c=s?.read()??{items:[],anonymousId:null};n.mintAnonymousId!==void 0&&ui(n.debug);let u=Vn(n,{carried:c.anonymousId,mayStore:i,orOwn:!0}),d=Sr({name:C("session"),domain:n.consentCookieDomain??null,mayStore:i}),f=n.getSessionId;n.getSessionId=()=>F(M(f,null))??d.get();let p=sr(C("preview"),n.consentCookieDomain??null),g=()=>F(M(f,null))??V(C("session")),A=Mr(typeof location>"u"?null:Ct(location.search)),w=(a=null)=>{p||Br(n.propertyId,a,{sessionId:g(),keepSession:i()})},x=(a,l)=>n.debug&&console.warn("[hp]",a,l??""),_=n.transport??new at({apiHost:n.apiHost,writeKey:n.writeKey,storageKey:$(C("retry"),n.writeKey),mayPersist:r?()=>o?.status==="granted":void 0,deferReplay:r,onError:x}),k=$(C("previousPage"),n.propertyId),m=null,E=()=>{if(m)return m;try{return sessionStorage.getItem(k)||null}catch{return null}};typeof window<"u"&&window.addEventListener("pageshow",a=>{a.persisted&&(m=null)});let S=a=>{if(m=a||null,!(r&&o.status!=="granted"))try{sessionStorage.setItem(k,a)}catch{}},h=rr({key:$(C("decisions"),n.propertyId),mayStore:i});n.getDecisions??(n.getDecisions=h.current);let y=F(M(n.getUserId,null)),O=null,N=null,U=y?ve(n.identityToken):null,G=null,K=null,ie=new Set,J=new Set;function Ue(a){if(a.type!=="track"||a.event!=="Cart Updated")return;let l=a.properties?.value;K=typeof l=="number"&&Number.isFinite(l)&&l>=0?l:null;for(let I of ie)try{I()}catch(P){console.warn("[hp] a basket listener failed",P)}}function ae(a,l,I=!1){Ue(a),w();try{return Ve(a,l,I)}catch(P){if(P instanceof be)throw P;return console.warn("[hp] the event was not sent",P),null}}function Ve(a,l,I){let P=G;G=null;let q=a.type==="track"?a.event:a.type;if(!I&&!Ir(n.plan,q))return null;let T={messageId:P?.messageId??ne(),timestamp:P?.timestamp??new Date().toISOString(),anonymousId:F(M(n.getAnonymousId,null)),userId:y??null,...a,context:Tn(n,ct(l))};if(T.properties&&(T.properties=vt(T.properties)),typeof T.properties?.href=="string"&&(T.properties.href=Ot(T.properties.href,n)),!I&&!dr(T.anonymousId,n.sampleRate))return n.debug&&console.debug("[hp] not sent: outside the sample",T),null;if(n.beforeSend){let Q;try{Q=n.beforeSend(T)}catch(ao){return console.warn("[hp] beforeSend failed; the event was not sent",ao),null}if(!Q)return null;let{type:z,event:hn,messageId:so,timestamp:io}=T;T={...Q,type:z,messageId:so,timestamp:io,...hn?{event:hn}:{}}}if(n.validate){let Q=n.validate(T,{producer:"web"});if(!Q.valid){let z=`[hp] invalid ${T.event??T.type}:
1
+ (()=>{var yn=e=>{throw TypeError(e)};var co=(e,t,n)=>t.has(e)||yn("Cannot "+n);var wn=(e,t,n)=>t.has(e)?yn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n);var L=(e,t,n)=>(co(e,t,"access private method"),n);var Ae=[];for(let e=2;Ae.length<64;e++)Ae.every(t=>e%t!==0)&&Ae.push(e);var Sn=e=>(e-Math.floor(e))*2**32>>>0,uo=Ae.slice(0,8).map(e=>Sn(Math.sqrt(e))),lo=Ae.map(e=>Sn(Math.cbrt(e))),Z=(e,t)=>e>>>t|e<<32-t;function _n(e){let t=new TextEncoder().encode(String(e)),n=new Uint32Array((t.length+8>>6)*16+16);t.forEach((s,i)=>{n[i>>2]|=s<<24-i%4*8}),n[t.length>>2]|=128<<24-t.length%4*8,n[n.length-2]=Math.floor(t.length/2**29),n[n.length-1]=t.length*8;let r=Uint32Array.from(uo),o=new Uint32Array(64);for(let s=0;s<n.length;s+=16){for(let w=0;w<64;w++){if(w<16){o[w]=n[s+w];continue}let x=o[w-15],_=o[w-2],k=Z(x,7)^Z(x,18)^x>>>3,h=Z(_,17)^Z(_,19)^_>>>10;o[w]=o[w-16]+k+o[w-7]+h}let[i,u,c,l,f,p,m,A]=r;for(let w=0;w<64;w++){let x=Z(f,6)^Z(f,11)^Z(f,25),_=A+x+(f&p^~f&m)+lo[w]+o[w]|0,h=(Z(i,2)^Z(i,13)^Z(i,22))+(i&u^i&c^u&c)|0;[A,m,p,f,l,c,u,i]=[m,p,f,l+_|0,c,u,i,_+h|0]}[i,u,c,l,f,p,m,A].forEach((w,x)=>{r[x]+=w})}return Array.from(r,s=>s.toString(16).padStart(8,"0")).join("")}var It=(e,t)=>e<<t|e>>>32-t;function bn(e){let t=new Uint32Array((e.length+8>>6)*16+16);e.forEach((s,i)=>{t[i>>2]|=s<<24-i%4*8}),t[e.length>>2]|=128<<24-e.length%4*8,t[t.length-2]=Math.floor(e.length/2**29),t[t.length-1]=e.length*8;let n=Uint32Array.of(1732584193,4023233417,2562383102,271733878,3285377520),r=new Uint32Array(80);for(let s=0;s<t.length;s+=16){for(let p=0;p<80;p++)r[p]=p<16?t[s+p]:It(r[p-3]^r[p-8]^r[p-14]^r[p-16],1);let[i,u,c,l,f]=n;for(let p=0;p<80;p++){let m,A;p<20?(m=u&c|~u&l,A=1518500249):p<40?(m=u^c^l,A=1859775393):p<60?(m=u&c|u&l|c&l,A=2400959708):(m=u^c^l,A=3395469782);let w=It(i,5)+m+f+A+r[p]|0;[f,l,c,u,i]=[l,c,It(u,30),i,w]}[i,u,c,l,f].forEach((p,m)=>{n[m]+=p})}let o=new Uint8Array(20);return n.forEach((s,i)=>{o[i*4]=s>>>24,o[i*4+1]=s>>>16,o[i*4+2]=s>>>8,o[i*4+3]=s}),o}var fo="e28e8ada-5b76-4209-bba9-79b823a0af75",po=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join("");function In(e,t){let n=Uint8Array.from(e.replace(/-/g,"").match(/../g),u=>Number.parseInt(u,16)),r=new TextEncoder().encode(t),o=new Uint8Array(16+r.length);o.set(n),o.set(r,16);let s=bn(o).slice(0,16);s[6]=s[6]&15|80,s[8]=s[8]&63|128;let i=po(s);return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}var ce=(e,t)=>typeof e=="string"&&e!==""&&e.length<=t?e:null;function Be(e,t){return ce(e,64)??ce(t,256)}function xn({sessionId:e,slot:t,arm:n}={}){let r=ce(e,256);return!r||!ce(t,256)||!ce(n,256)?null:In(fo,`${r}:${t}:${n}`)}var mo="4b1f2c7e-9a3d-4e58-b6c1-2d7f0a9e8c53";function kn({sessionId:e,surface:t}={}){let n=ce(e,256);return!n||!ce(t,64)?null:In(mo,`${n}:${t}`)}var ho=Array.from({length:11},(e,t)=>t/10);function go(e,t){if(!e.isIntersecting)return!1;let{intersectionRect:n,boundingClientRect:r,rootBounds:o}=e;if(!n||!r)return!0;let s=n.width*n.height,i=r.width*r.height,u=o?Math.min(i,o.width*o.height):i;return u>0&&s/u>=t}function te(e){let{selector:t,onViewable:n,visibleRatio:r=.5,dwellMs:o=1e3,root:s=document}=e,i=new Map,u=new WeakSet,c=new Set,l=h=>{i.has(h)||i.set(h,setTimeout(()=>{i.delete(h),n(h)&&(p?.unobserve(h),c.delete(h))},o))},f=h=>{clearTimeout(i.get(h)),i.delete(h)},p=typeof IntersectionObserver>"u"?null:new IntersectionObserver(h=>{for(let E of h){let S=E.target;if(!go(E,r)){c.delete(S),f(S);continue}c.add(S),m()&&l(S)}},{threshold:ho}),m=()=>typeof document>"u"||document.visibilityState!=="hidden",A=()=>{if(m())for(let h of c)l(h);else for(let h of c)f(h)};document.addEventListener("visibilitychange",A);let w=()=>{for(let h of s.querySelectorAll(t))u.has(h)||(u.add(h),p?.observe(h))},x=typeof MutationObserver>"u"?null:new MutationObserver(()=>w()),_=()=>{w(),x?.observe(s===document?document.body:s,{childList:!0,subtree:!0})},k=s===document&&!document.body;return k?document.addEventListener("DOMContentLoaded",_,{once:!0}):_(),()=>{k&&document.removeEventListener("DOMContentLoaded",_),document.removeEventListener("visibilitychange",A),p?.disconnect(),x?.disconnect();for(let h of i.values())clearTimeout(h);i.clear(),c.clear()}}function xt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-exposure]",visibleRatio:r=.5,dwellMs:o=1e3,root:s=document}=t;return te({selector:n,root:s,visibleRatio:r,dwellMs:o,onViewable(i){let u=i.dataset?.hpExposure?.trim();return u&&e.surfaceViewed({surface:u}),!0}})}var An=e=>{try{return new URL(e,document.baseURI).toString()}catch{return e}};function kt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-list]",tileSelector:r="[data-hp-product]",visibleRatio:o=.5,dwellMs:s=1e3,root:i=document}=t,u=new Set,c=w=>w.closest?.(n)??null,l=w=>{let x=w.dataset.hpList?.trim();return x?{list_id:x,category:w.dataset.hpListCategory?.trim()||null}:null},f=w=>Array.from(w.querySelectorAll(r)).filter(x=>c(x)===w),p=(w,x)=>{try{let _=JSON.parse(w.dataset.hpProduct??"");return!_||typeof _!="object"||!_.product_id?null:{..._,position:_.position??x+1,..._.url?{url:An(_.url)}:{},..._.image_url?{image_url:An(_.image_url)}:{}}}catch{return null}},m=te({selector:`${n} ${r}`,root:i,visibleRatio:o,dwellMs:s,onViewable(w){let x=c(w);if(!x||x.dataset.hpListView==="manual")return!0;let _=l(x);if(!_||u.has(_.list_id))return!0;let k=new Set,h=f(x).map(p).filter(E=>!E||k.has(E.product_id)?!1:(k.add(E.product_id),!0));return h.length===0||(u.add(_.list_id),e.productListViewed({..._,products:h})),!0}}),A=w=>{let _=w.target?.closest?.("a[href]")?.closest(r);if(!_)return;let k=c(_),h=p(_,k?f(k).indexOf(_):0);h&&e.productClicked({list_id:k?l(k)?.list_id??null:null,products:[h]})};return document.addEventListener("click",A,!0),()=>{document.removeEventListener("click",A,!0),m()}}function D(e,...t){let n=e.dataset??{};for(let r of t){let o=n[r];if(typeof o=="string"&&o.trim()!=="")return o.trim()}return null}function je(e,...t){let n=D(e,...t);if(n===null)return null;let r=Number(n);return Number.isFinite(r)?Math.trunc(r):null}function yo(e,t){let n=D(e,"hpPromotion");return n?{promotion_id:n,name:D(e,"hpPromotionName"),creative:D(e,"hpPromotionCreative"),position:D(e,"hpPromotionSlot")??String(t+1)}:null}function At(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-promotion]",resolve:r=yo,visibleRatio:o=.5,dwellMs:s=1e3,root:i=document}=t,u=new Set,c=p=>{let m=Array.from(i.querySelectorAll(n)),A=m.indexOf(p);try{return r(p,A<0?m.length:A)}catch{return null}},l=te({selector:n,root:i,visibleRatio:o,dwellMs:s,onViewable(p){let m=c(p);return!m||u.has(m.promotion_id)?!1:(u.add(m.promotion_id),e.promotionViewed(m),!0)}}),f=p=>{let m=p.target;if(!m||typeof m.closest!="function")return;let A=m.closest(n),w=m.closest("a[href]");if(!A||!w||!A.contains(w)&&!w.contains(A))return;let x=c(A);x&&e.promotionClicked({...x,href:w.getAttribute("href")})};return document.addEventListener("click",f,!0),()=>{document.removeEventListener("click",f,!0),l()}}function wo(e){let t=D(e,"hpRecoRequest"),n=D(e,"hpRecoPlacement"),r=D(e,"hpRecoStrategy");if(!t||!n||!r)return null;let o=D(e,"hpRecoHoldout");return{recommendation_request_id:t,placement:n,strategy:r,recipe:D(e,"hpRecoRecipe"),algorithm_version:D(e,"hpRecoAlgorithmVersion"),experiment:D(e,"hpRecoExperiment"),variant:D(e,"hpRecoVariant"),holdout:o===null?null:o==="true",assignment_bucket:je(e,"hpRecoBucket"),assignment_unit_kind:D(e,"hpRecoUnitKind"),candidate_set_fingerprint:D(e,"hpRecoFingerprint"),candidate_set_size:je(e,"hpRecoCandidates"),ranked_by:D(e,"hpRecoRankedBy"),served_at:D(e,"hpRecoServedAt")}}function So(e,t){let n=D(e,"hpRecoProduct");if(!n)return null;let r=D(e,"hpRecoPrice");return{product_id:n,sku:D(e,"hpRecoSku"),name:D(e,"hpRecoName"),brand:D(e,"hpRecoBrand"),price:r===null||Number.isNaN(Number(r))?null:Number(r),position:je(e,"hpRecoPosition")??t+1}}function vt(e,t={}){if(typeof window>"u"||typeof document>"u")return()=>{};let{selector:n="[data-hp-reco-request]",tileSelector:r="[data-hp-reco-product]",resolveRail:o=wo,resolveTile:s=So,visibleRatio:i=.5,dwellMs:u=1e3,root:c=document}=t,l=new Set,f=new Map,p=new Map,m=(h,...E)=>{try{return h(...E)}catch{return null}},A=h=>typeof h.closest=="function"?h.closest(n):null,w=h=>Array.from(h.querySelectorAll(r)),x=(h,E)=>{if(p.delete(E.recommendation_request_id),l.has(E.recommendation_request_id))return;let S=w(h).map((y,O)=>m(s,y,O)).filter(y=>y?.product_id);if(S.length===0)return;l.add(E.recommendation_request_id);let g=[...f.get(E.recommendation_request_id)?.values()??[]].sort((y,O)=>y.position-O.position);e.recommendationsViewed({...E,products:S,viewable:g})},_=te({selector:`${n} ${r}`,root:c,visibleRatio:i,dwellMs:u,onViewable(h){let E=A(h);if(!E)return!0;let S=m(o,E);if(!S)return!0;let g=S.recommendation_request_id,y=m(s,h,w(E).indexOf(h));if(y?.product_id){f.has(g)||f.set(g,new Map);let O=f.get(g);O.has(y.position)||O.set(y.position,{position:y.position,product_id:y.product_id,viewable_at:new Date().toISOString()})}return!l.has(g)&&!p.has(g)&&p.set(g,setTimeout(()=>x(E,S),0)),!0}}),k=h=>{let E=h.target;if(!E||typeof E.closest!="function")return;let S=E.closest(r);if(!S)return;let g=E.closest("[data-hp-reco-interaction]"),y=E.closest("a[href]"),O=y&&(S.contains(y)||y.contains(S));if(!(g&&S.contains(g))&&!O)return;let N=A(S);if(!N)return;let U=m(o,N);if(!U)return;let G=m(s,S,w(N).indexOf(S));if(!G?.product_id)return;let K=U.recommendation_request_id;l.has(K)||(clearTimeout(p.get(K)),x(N,U)),e.productClicked({recommendation_request_id:U.recommendation_request_id,interaction:D(g??S,"hpRecoInteraction")??"navigate",products:[G]})};return document.addEventListener("click",k,!0),()=>{document.removeEventListener("click",k,!0);for(let h of p.values())clearTimeout(h);p.clear(),_()}}var Se=new Set(["home","list","product","search","basket","checkout","order_confirmation","login","register","account","info","blog","other"]),_o=new Set(["products"]),vn=e=>e==null;function Et(e,t=new WeakSet){if(e instanceof Date)return e.toJSON();if(e===null||typeof e!="object"||t.has(e))return e;t.add(e);let n=Array.isArray(e)?e.map(r=>Et(r,t)):Object.fromEntries(Object.entries(e).filter(([,r])=>!vn(r)).map(([r,o])=>[r,Et(o,t)]));return t.delete(e),n}function Ct(e){if(!e)return e;let t=Et(e);for(let n of _o)n in e&&vn(e[n])&&(t[n]=e[n]);return t}function En(){try{let e=performance.getEntriesByType("navigation")[0];return e?["navigate","reload","back_forward","prerender"].includes(e.type)?e.type:"navigate":null}catch{return null}}var bo=new Set(["","unknown","undefined","null","none","nil","nan","anonymous","guest","0","-1"]);function F(e){if(e==null)return null;let t=String(e).trim();return bo.has(t.toLowerCase())?null:t}var ve=e=>typeof e=="string"&&e!==""?e:null;function ne(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var Cn="1.20";function V(e){if(typeof document>"u")return null;try{let t=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith(`${e}=`));return t&&decodeURIComponent(t.slice(e.length+1))||null}catch{return null}}var Io={gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid"},xo=/[a-z0-9._%+-]+@[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}/i,ko=/\d(?:[ -]?\d){12,}/,Ao=new Set(["gclid","fbclid","ttclid","msclkid"]);function Pn(e,t=""){if(typeof e!="string"||e==="")return!1;let n=[e];try{let o=decodeURIComponent(e.replace(/\+/g," "));o!==e&&n.push(o)}catch{}let r=!Ao.has(String(t).toLowerCase());return n.some(o=>xo.test(o)||r&&ko.test(o))}function Pt(e){if(!e)return null;let t=new URLSearchParams(e),n={},r={utm_source:"source",utm_medium:"medium",utm_campaign:"name",utm_term:"term",utm_content:"content"};for(let[o,s]of[...Object.entries(r),...Object.entries(Io)]){let i=t.get(o);i&&!Pn(i,o)&&(n[s]=i)}return Object.keys(n).length?n:null}var vo=["email","e-mail","password","pass","pwd","token","auth","code","uid","customer_id","postcode","zip","phone","applyCode"],Eo=["email","password","passwd","pwd","token","secret","auth","session","phone","postcode","zip","address","birth","card","cvv","iban","ssn","customerid","userid"],Co=["tel","uid","dob"],Oo=["utm_source","utm_medium","utm_campaign","utm_term","utm_content","gclid","fbclid","ttclid","msclkid"],Po=new Set(vo.map(e=>e.toLowerCase()));function Lo(e){let t=String(e).toLowerCase();if(Po.has(t))return!0;let n=t.replace(/[-_.]/g,"");return Eo.some(o=>n.includes(o))?!0:String(e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z0-9]+/).some(o=>Co.includes(o))}function Ot(e){return(e??[]).map(t=>{try{return new RegExp(`^${t}$`,"i")}catch{return{test:n=>n.toLowerCase()===String(t).toLowerCase()}}})}function Ln(e,t={}){if(!e)return null;try{let n=new URLSearchParams(e),r=t.queryParamAllowlist?Ot([...t.queryParamAllowlist,...Oo]):null,o=Ot(t.queryParamBlocklist),s=Ot(t.sensitiveParamAllowlist);for(let u of new Set(n.keys()))(Lo(u)&&!s.some(l=>l.test(u))||n.getAll(u).some(l=>Pn(l,u))||(r?!r.some(l=>l.test(u)):o.some(l=>l.test(u))))&&n.delete(u);let i=n.toString();return i?`?${i}`:""}catch{return""}}function Tn(e,t,n={}){if(!e)return null;try{let r=new URL(e);return t&&r.origin===t?r.origin+r.pathname+(Ln(r.search,n)??""):r.origin+r.pathname}catch{return null}}function Lt(e,t={}){if(typeof e!="string"||typeof location>"u")return null;try{let n=new URL(e,location.href);return n.protocol!=="https:"&&n.protocol!=="http:"?null:Tn(n.href,location.origin,t)}catch{return null}}function Tt(e){if(typeof e!="string")return null;let t=e.trim().toUpperCase();return/^[A-Z]{3}$/.test(t)?t:null}function On(e){if(typeof e!="string")return null;let t=e.trim().toUpperCase();return/^[A-Z]{2}$/.test(t)?t:null}function Nt(e){if(typeof e!="string")return null;let t=e.trim().replace(/_/g,"-");if(!/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(t))return null;try{return Intl.getCanonicalLocales(t)[0]}catch{return null}}function M(e,t){if(typeof e=="function")try{let n=e();if(n!=null)return n}catch{}return t}function To(e){return{...e.propertyId==null?{}:{property_id:String(e.propertyId)},channel:e.channel??null,market:e.market??null,environment:e.environment??null}}function No(e){let t=typeof window<"u"?window.location:null,n=t?Ln(t.search,e):null;return{url:t?t.origin+t.pathname+(n??""):e.pageUrl??null,path:t?t.pathname:e.pagePath??null,search:n??null,referrer:typeof document<"u"?Tn(document.referrer,t?.origin,e):null,title:typeof document<"u"&&document.title||null,type:e.pageType??null}}var Ee;function Ro(){if(Ee!==void 0)return Ee;try{Ee=globalThis.Temporal?.Now?.timeZoneId?.()||Intl.DateTimeFormat().resolvedOptions().timeZone||null}catch{Ee=null}return Ee}function Nn(e,t={}){let n=typeof window<"u"?window.location:null,r={library:{name:e.libraryName,version:e.libraryVersion},spec:{version:Cn},source:To(e),session_id:M(e.getSessionId,null),identity_trust:F(M(e.getAnonymousId,null))?"device":"none",page:No(e),campaign:n?Pt(n.search):null,device:{user_agent:typeof navigator<"u"?navigator.userAgent:null,type:null,viewport_width:typeof window<"u"?window.innerWidth:null,viewport_height:typeof window<"u"?window.innerHeight:null},currency:Tt(M(e.getCurrency,e.currency)),locale:Nt(M(e.getLocale,e.locale)),timezone:Ro(),country:On(e.country),ship_to_country:On(M(e.getShipToCountry,e.shipToCountry)),ip:null,bot:null,consent:e.getConsent?.()??null,experiments:M(e.getExperiments,null),audiences:M(e.getAudiences,null),decisions:M(e.getDecisions,null),recommendations:M(e.getRecommendations,null),extensions:M(e.getExtensions,null)};return Rn(r,t)}function Rn(e,t){if(!t)return e;let n={...e};for(let[r,o]of Object.entries(t))o&&typeof o=="object"&&!Array.isArray(o)&&e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?n[r]=Rn(e[r],o):o!==void 0&&(n[r]=o);return n}var de=Object.freeze({consent:"thg_hp_consent",retry:"thg_hp_retry",sessionSignals:"thg_hp_session_signals",identified:"thg_hp_identified",previousPage:"thg_hp_prev_page",decisions:"thg_hp_decisions",settings:"thg_hp_settings",held:"thg_hp_held",carried:"thg_hp_carried",recommendationContext:"thg_hp_recommendation_context",anonymousId:"thg_hp_anonymous_id",session:"thg_hp_session",preview:"thg_hp_preview",debug:"thg_hp_debug",onsite:"thg_hp_onsite",visitCampaign:"thg_hp_visit_campaign"}),Mo={retry:"cdp.retry",sessionSignals:"cdp_session_signals",identified:"cdp_identified",previousPage:"cdp_prev_page_message_id"},Rt={...de},Mn=!1;function He(e){let t={...de};for(let[n,r]of Object.entries(e??{})){if(!(n in de))throw new Error(`storageNames: unknown kind "${n}"`);if(typeof r!="string"||!/^[\w.-]+$/.test(r))throw new Error(`storageNames.${n} must be a non-empty cookie-safe name`);t[n]=r}Rt=t}function C(e){return Rt[e]}var Do="_",Dn=e=>e==null||e===""?Do:String(e);function $(e,t,n){let r=`${e}:${Dn(t)}`;return n==null||n===""?r:`${r}:${n}`}function Un(e,t){return`${e}:${Dn(t)}:`}function Fe(){if(!Mn){Mn=!0;for(let e of[()=>localStorage,()=>sessionStorage]){let t;try{if(t=e(),!t)continue;for(let n of Object.keys(t))for(let[r,o]of Object.entries(Mo)){if(n!==o&&!n.startsWith(`${o}:`))continue;let s=Rt[r]+n.slice(o.length);t.getItem(s)===null&&t.setItem(s,t.getItem(n)),t.removeItem(n)}}catch{}}}}var Dt=1800*1e3,qe=()=>{try{return typeof sessionStorage>"u"?null:sessionStorage}catch{return null}},Mt=()=>{try{return typeof localStorage>"u"?null:localStorage}catch{return null}};function Vn(e,t=()=>Date.now()){return{read(){try{let n=qe()?.getItem(e),r=n?JSON.parse(n):null;return!r||t()-r.savedAt>Dt?(r&&qe()?.removeItem(e),{items:[],anonymousId:null}):{items:Array.isArray(r.items)?r.items:[],anonymousId:typeof r.anonymousId=="string"?r.anonymousId:null}}catch{return{items:[],anonymousId:null}}},write(n,r=null){try{n.length===0?qe()?.removeItem(e):qe()?.setItem(e,JSON.stringify({savedAt:t(),items:n,anonymousId:r}))}catch{}}}}var Uo=400*24*60*60;function re(e,t,n,r){if(typeof document>"u")return!1;try{let o=typeof location<"u"&&location.protocol==="https:"?"; Secure":"",s=r?`; Domain=${r}`:"",i=n===null?"":`; Max-Age=${n}`;return document.cookie=`${e}=${encodeURIComponent(t)}; Path=/${i}; SameSite=Lax`+s+o,!0}catch{return!1}}function Vo({name:e,domain:t=null,legacyKey:n,read:r,mint:o,mayStore:s,carried:i=null}){let u=null;try{u=Mt()?.getItem(n)||null}catch{u=null}let c=r(e)??u??i,l=!1,f=()=>{if(!(l||c===null||!s())&&(l=re(e,c,Uo,t),!(!l||u===null)))try{Mt()?.removeItem(n),u=null}catch{}};return{get(){return c??(c=o()),f(),c},peek:()=>c,persist:f,forget(){re(e,"",0,t),c=null,l=!1;try{Mt()?.removeItem(n)}catch{}u=null}}}function $n(e,{carried:t=null,mayStore:n,orOwn:r=!1}){let o=e.anonymousIdSource,s=()=>Vo({name:C("anonymousId"),domain:e.consentCookieDomain??null,legacyKey:$(C("anonymousId"),e.propertyId),read:V,mint:ne,mayStore:n,carried:t});if(o?.source==="hp_cookie"){let c=s();return e.getAnonymousId=()=>c.get(),c}if(o?.source==="site_cookie"&&o.cookie){let c=o.cookie;e.getAnonymousId=()=>V(c)}if(!r)return null;let i=e.getAnonymousId,u=s();return e.getAnonymousId=()=>F(M(i,null))??u.get(),u}var $o=200;function Bn(e,t,n=()=>Date.now()){let r=()=>$(C("carried"),e),o=!1;function s(){try{let i=JSON.parse(sessionStorage.getItem(r())??"null");return!i||!(n()-i.savedAt<=Dt)?[]:Array.isArray(i.calls)?i.calls:[]}catch{return[]}}return{take(){let i=s();try{sessionStorage.removeItem(r())}catch{}return i},save(i){try{return o||!t()?!1:(sessionStorage.setItem(r(),JSON.stringify({savedAt:n(),calls:[...s(),...i].slice(-$o)})),!0)}catch{return!1}},close(){o=!0}}}var fa=de.consent,Ke=Object.freeze({visitor:"visitor",host:"host"}),jn=()=>({basis:Ke.host}),Bo="hp-consent",fe=["analytics","marketing","personalisation","ad_user_data","ad_personalization"],Hn={analytics:"a",marketing:"m",personalisation:"p",ad_user_data:"aud",ad_personalization:"adp"},ee=()=>typeof window<"u",Fn=()=>ee()&&typeof window.cookieStore?.addEventListener=="function",jo=e=>e===!0?!0:e===!1?!1:null;function _e(e){if(!e||typeof e!="object")return null;let t={};for(let n of fe)t[n]=jo(e[n]);return t}function Vt(e,t){return!e||!t?e===t:fe.every(n=>e[n]===t[n])}function $t(e){if(!e)return"";let t=[];for(let n of fe){let r=e[n];(r===!0||r===!1)&&t.push(`${Hn[n]}=${r?1:0}`)}return t.join("&")}function Bt(e){return{[Bo]:$t(_e(e))}}function Ce(e){let t=_e({});if(e==null)return t;let n=String(e).trim();if(n.length>=2&&n.startsWith('"')&&n.endsWith('"')&&(n=n.slice(1,-1)),n.includes("%"))try{n=decodeURIComponent(n.replace(/\+/g," "))}catch{return t}let r=Object.fromEntries(Object.entries(Hn).map(([s,i])=>[i,s])),o=new Set;for(let s of n.split("&")){let i=s.indexOf("=");if(i<=0)continue;let u=r[s.slice(0,i).trim()],c={1:!0,0:!1}[s.slice(i+1).trim()]??null;!u||c===null||o.has(u)||(t[u]===null?t[u]=c:t[u]!==c&&(t[u]=null,o.add(u)))}return t}function jt(e,t){if(!t)return e;let n=r=>{if(!r)return r;let o={...r};for(let s of fe)s!=="analytics"&&t[s]!==!0&&(o[s]=null);return o};return{name:e.name,basis:e.basis,read:()=>n(e.read()),subscribe:r=>e.subscribe(o=>r(n(o))),get observesChanges(){return e.observesChanges}}}function Ht(e,t={}){return{...e,ad_user_data:t.ad_user_data??e.marketing,ad_personalization:t.ad_personalization??e.marketing}}function Ge(e,t){let n=!0;return{notify:()=>{if(n)try{let o=e();o&&t(o)}catch{}},stop:()=>n=!1}}var Ho={analytics:["analytics","measure_content_performance","audience_measurement"],marketing:["marketing","targeting","advertising","select_personalized_ads","create_ads_profile"],personalisation:["personalisation","personalization","select_personalized_content","create_content_profile"]};function Fo(e,t){if(!t?.length)return null;let n=!1;for(let[r,o]of Object.entries(e)){let s=String(o?.id??r).toLowerCase();if(t.some(u=>{let c=String(u).toLowerCase();return s===c||s.startsWith(`${c}-`)})&&(n=!0,o?.enabled===!0))return!0}return n?!1:null}function qn(e={}){let t={...Ho,...e.purposes};function n(){let r=ee()?window.Didomi:void 0;if(!r?.getCurrentUserStatus||r.shouldUserStatusBeCollected?.()!==!1||r.isUserStatusPartial?.()===!0)return null;let o=r.getCurrentUserStatus()?.purposes;if(!o||typeof o!="object")return null;let s=i=>Fo(o,t[i]);return Ht({analytics:s("analytics"),marketing:s("marketing"),personalisation:s("personalisation")},{ad_user_data:s("ad_user_data"),ad_personalization:s("ad_personalization")})}return{name:"didomi",read:n,observesChanges:!0,subscribe(r){if(!ee())return()=>{};let o=Ge(n,r),s={event:"consent.changed",listener:o.notify};return window.didomiEventListeners=window.didomiEventListeners||[],window.didomiEventListeners.push(s),window.didomiOnReady=window.didomiOnReady||[],window.didomiOnReady.push(i=>{o.notify(),(i??window.Didomi)?.on?.("consent.changed",o.notify)}),window.Didomi?.on?.("consent.changed",o.notify),o.stop}}}function Ut(e){let t={};if(!e)return t;for(let n of String(e).split("&")){let r=n.indexOf("=");if(r<=0)continue;let o=n.slice(r+1).replace(/\+/g," ");try{o=decodeURIComponent(o)}catch{}t[n.slice(0,r)]=o}return t}function Kn(e={}){let t={analytics:"C0002",personalisation:"C0003",marketing:"C0004",...e.groups},n=e.impliedConsent===!0;function r(){let i=Ut(V("OptanonConsent"));if(i.groups){let l={};for(let f of i.groups.split(",")){let[p,m]=f.split(":");p?.trim()&&(l[p.trim()]=m==="1"?!0:m==="0"?!1:null)}return f=>l[f]??!1}let u=ee()?window.OnetrustActiveGroups:void 0;if(typeof u!="string"||!u.length)return null;let c=new Set(u.split(",").map(l=>l.trim()).filter(Boolean));return l=>c.has(l)}function o(){if(V("OptanonAlertBoxClosed"))return!0;try{if(ee()&&window.OneTrust?.IsAlertBoxClosed?.()===!0)return!0}catch{}return Number.parseInt(Ut(V("OptanonConsent")).interactionCount,10)>0?!0:n&&ee()&&(!!window.OneTrust||typeof window.OnetrustActiveGroups=="string")}function s(){if(!o())return null;let i=r();if(!i)return null;let u=p=>t[p]?i(t[p]):null,c=Ht({analytics:u("analytics"),marketing:u("marketing"),personalisation:u("personalisation")},{ad_user_data:u("ad_user_data"),ad_personalization:u("ad_personalization")}),l=Ut(V("OptanonConsent"));return(typeof navigator<"u"&&navigator.globalPrivacyControl===!0||l.isGpcEnabled==="1")&&(c.marketing=!1,c.ad_user_data=!1,c.ad_personalization=!1),c}return{name:"onetrust",read:s,observesChanges:!0,subscribe(i){if(!ee())return()=>{};let u=Ge(s,i),c=!1,l=()=>{c||!window.OneTrust?.OnConsentChanged||(c=!0,window.OneTrust.OnConsentChanged(u.notify))};window.addEventListener("OneTrustGroupsUpdated",u.notify);let f=window.OptanonWrapper;return window.OptanonWrapper=function(...m){try{typeof f=="function"&&f.apply(this,m)}finally{l(),u.notify()}},l(),()=>{u.stop(),window.removeEventListener("OneTrustGroupsUpdated",u.notify)}}}}function qo(e){let t=String(e).split(",").map(n=>n.trim()).filter(Boolean);return t.length?new Set(t):null}function Gn(e){let{name:t,categories:n,parse:r=qo,refusedValue:o,source:s="native",changeEvent:i="thg_hp_consent_change"}=e??{};if(typeof t!="string"||t==="")throw new Error("cookieConsent: `name` (the cookie your banner writes) is required");if(!n||typeof n.analytics!="string")throw new Error("cookieConsent: `categories.analytics` (the category id that grants analytics) is required");function u(){let c=V(t);if(c==null)return null;let l;if(o!==void 0&&c===o)l=new Set;else try{l=r(c)}catch{l=null}if(!(l instanceof Set))return null;let f=p=>n[p]?l.has(n[p]):null;return Ht({analytics:f("analytics"),marketing:f("marketing"),personalisation:f("personalisation")},{ad_user_data:f("ad_user_data"),ad_personalization:f("ad_personalization")})}return{name:s,read:u,get observesChanges(){return Fn()},subscribe(c){if(!ee())return()=>{};let l=Ge(u,c),f=p=>{[...p.changed??[],...p.deleted??[]].some(A=>A?.name===t)&&l.notify()};return window.addEventListener(i,l.notify),window.cookieStore?.addEventListener?.("change",f),()=>{l.stop(),window.removeEventListener(i,l.notify),window.cookieStore?.removeEventListener?.("change",f)}}}}function zn(e={}){let t=e.name??C("consent"),n=()=>{let r=V(t);if(r==null)return null;let o=Ce(r);return o.analytics==null?null:o};return{name:"forwarded",read:n,get observesChanges(){return Fn()},subscribe(r){if(!ee())return()=>{};let o=Ge(n,r),s=i=>{[...i.changed??[],...i.deleted??[]].some(c=>c?.name===t)&&o.notify()};return window.cookieStore?.addEventListener?.("change",s),()=>{o.stop(),window.cookieStore?.removeEventListener?.("change",s)}}}}function Wn(e){let t=_e(e);return{name:"static",basis:Ke.host,read:()=>t?{...t}:null,observesChanges:!0,subscribe:()=>()=>{}}}function Jn(e){if(e==null)return null;let t=String(e).split("/").map(n=>n.trim()).filter(Boolean).join("/");return t===""?null:t}function Ko(e){let t=e.item_category;if(t!=null&&String(t).includes("/"))return Jn(t);let n=[t,e.item_category2,e.item_category3,e.item_category4,e.item_category5].map(r=>r==null?"":String(r).trim()).filter(Boolean);return Jn(n.join("/"))}var Go=e=>{if(e==null||typeof e=="object")return null;let t=String(e).trim();return t===""?null:t};function zo(...e){for(let t of e){if(typeof t=="number"&&Number.isFinite(t))return String(t);if(typeof t=="string"&&t.trim()!=="")return t.trim()}return null}var ze=e=>zo(e.item_group_id,e.item_id);function Wo(e,t=ze){if(!e)return null;let n=u=>u==null||u===""||Number.isNaN(Number(u))?null:Number(u),r=u=>{let c=n(u);return c==null?null:Math.round(c*1e6)/1e6},o=u=>{let c=r(u);return c!=null&&c>=0?c:null},s=u=>{let c=n(u);return Number.isInteger(c)&&c>=0?c:null},i=Go;return{product_id:i(t(e)),sku:i(e.item_id),name:i(e.item_name),brand:i(e.item_brand),variant:i(e.item_variant)??i(e.variant),category:Ko(e),price:r(e.price),discount:o(e.discount),quantity:s(e.quantity),coupon:i(e.coupon),position:s(e.index)!=null?s(e.index)+1:null,url:i(e.url)??i(e.item_url)??null,image_url:i(e.image_url)??i(e.image_link)??null,displayed_sku:i(e.displayed_sku)??i(e.displayed_variant_sku)}}function Ft(e,t=ze){return(e??[]).map(n=>Wo(n,t)).filter(n=>n?.product_id)}var Jo=1e3,Yo={shipping:2,payment:3},Xo=new Set(["password","google","apple","facebook","magic_link","sso","passkey","other"]),H=e=>{if(e==null||typeof e=="object")return null;let t=String(e).trim();return t===""?null:t},Zo=e=>{if(e==null||e===""||typeof e=="object")return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:null},We=e=>e!==null&&typeof e=="object";function Qo(e){return Array.isArray(e.items)?e.items.filter(We):null}function Yn(e){let t=H(e)?.toLowerCase().replace(/[\s-]+/g,"_");return t?Xo.has(t)?t:t==="email"||t==="email_password"?"password":"other":null}function es({ecommerce:e,items:t}){let n=s=>({promotion_id:H(s.promotion_id),name:H(s.promotion_name),creative:H(s.creative_name),position:H(s.creative_slot)}),r=new Set,o=[];for(let s of[n(e),...t.map(n)])!s.promotion_id||r.has(s.promotion_id)||(r.add(s.promotion_id),o.push(s));return o}var Xn=({ecommerce:e,items:t})=>H(e.item_list_id)??H(e.item_list_name)??H(t[0]?.item_list_id)??H(t[0]?.item_list_name),pe=(e,t)=>t.products?.length?{event:e,properties:t}:null,ts=new Set(["product","products","item","items"]);function ns({ecommerce:e}){let t=H(e.item_id),n=H(e.content_type)?.toLowerCase();return!t||n&&!ts.has(n)?null:{event:"Product Shared",properties:{share_via:H(e.method),products:[{product_id:t}]}}}function rs(e){let t=o=>pe("Product List Viewed",{list_id:Xn(o),products:o.products}),n=o=>{let s=H(o.ecommerce.search_term);return s?{event:"Products Searched",properties:{query:s,...o.products.length?{products:o.products}:{}}}:null},r=o=>s=>s.promotions.map(i=>({event:o,properties:i}));return{view_item:o=>pe("Product Viewed",{currency:o.currency,value:o.value,products:o.products.slice(0,1)}),view_item_list:t,view_search_results:o=>n(o)??t(o),search:n,select_item:o=>pe("Product Clicked",{list_id:Xn(o),products:o.products.slice(0,1)}),add_to_cart:o=>pe("Product Added",{cart_id:H(o.ecommerce.cart_id),products:o.products}),remove_from_cart:o=>pe("Product Removed",{cart_id:H(o.ecommerce.cart_id),products:o.products}),view_cart:o=>({event:"Cart Viewed",properties:{cart_id:H(o.ecommerce.cart_id),value:o.value,currency:o.currency,coupon:H(o.ecommerce.coupon),...o.itemsListed?{products:o.products}:{}}}),begin_checkout:o=>pe("Checkout Started",{value:o.value,currency:o.currency,coupon:H(o.ecommerce.coupon),products:o.products}),add_shipping_info:o=>({event:"Checkout Step Completed",properties:{step:e.shipping,step_name:"shipping",shipping_method:H(o.ecommerce.shipping_tier)}}),add_payment_info:o=>({event:"Payment Info Entered",properties:{step:e.payment,step_name:"payment",payment_method:H(o.ecommerce.payment_type)}}),view_promotion:r("Promotion Viewed"),select_promotion:r("Promotion Clicked"),add_to_wishlist:o=>pe("Product Added to Wishlist",{products:o.products}),share:ns,login:o=>({event:"Signed In",properties:{method:Yn(o.ecommerce.method)}}),sign_up:o=>({event:"Signed Up",properties:{method:Yn(o.ecommerce.method)}})}}var os=e=>e.event;function ss(e,t){if(!We(e))return null;if(typeof e.length=="number"&&e[0]==="event"&&typeof e[1]=="string"){let r=We(e[2])?e[2]:{};return{name:e[1],entry:r,ecommerce:r}}let n=H(t(e));return n?{name:n,entry:e,ecommerce:We(e.ecommerce)?e.ecommerce:e}:null}function qt(e){return Array.isArray(e)?`[${e.map(qt).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${qt(e[t])}`).join(",")}}`:JSON.stringify(e??null)}function Zn(e,t={}){if(!e||typeof e.track!="function")throw new Error("connectDataLayer: analytics must have a track(event, properties, options) method");let n=t.dataLayer??(typeof window<"u"?window.dataLayer=window.dataLayer||[]:null);if(!Array.isArray(n))return()=>{};let r=rs({...Yo,...t.steps}),o=t.map??{},s=t.eventName??os,i=t.productId??ze,u=new Set(["purchase","refund",...t.ignore??[]]),c=t.dedupeMs??Jo,l=new Map,f=!0;function p(S,g,y){if(c<=0)return!1;let O=`${S}|${y??""}|${qt(g)}`,N=Date.now();for(let[U,G]of l)N-G>c&&l.delete(U);return l.has(O)?!0:(l.set(O,N),!1)}let m=null,A=new Set;function w(S,g){if(S!=="Product Viewed")return!1;let y=typeof location>"u"?"":location.pathname;y!==m&&(m=y,A.clear());let O=g.products?.[0]?.product_id;return O?A.has(O)?!0:(A.add(O),!1):!1}function x({event:S,properties:g={}},y){if(!S||p(S,g,y)||w(S,g))return;let O=y?{context:{currency:y}}:void 0;if(S==="Signed Out"&&typeof e.signedOut=="function"){e.signedOut(O);return}e.track(S,g,O)}function _(S){let g=t.transform?t.transform(S):S,y=ss(g,s);if(!y||u.has(y.name))return;let O=Object.hasOwn(o,y.name),N=O?o[y.name]:r[y.name];if(typeof N!="function")return;let U=Qo(y.ecommerce),G=U??[],K={...y,items:G,itemsListed:U!==null,products:Ft(G,i),currency:Tt(y.ecommerce.currency),value:Zo(y.ecommerce.value)};K.promotions=es(K);let ie=O?N(g,{...K,toProducts:J=>Ft(J,i)}):N(K);for(let J of[ie].flat())J&&x(J,K.currency)}function k(S){if(f)try{_(S)}catch(g){try{t.onError?.(g,S)}catch{}}}for(let S of n.slice())k(S);let h=n.push;function E(...S){let g=h.apply(this,S);for(let y of S)k(y);return g}return n.push=E,()=>{f=!1,n.push===E&&(n.push=h)}}var is="hp_debug",as=256;function cs(){try{return new URLSearchParams(location.search).get(is)}catch{return null}}function Qn(e,t){if(typeof location>"u")return!1;try{let n=cs();if(n!==null){let o=n.trim();o===""||o.length>as?sessionStorage.removeItem(t):sessionStorage.setItem(t,o)}let r=sessionStorage.getItem(t);return!!(e&&r&&_n(r)===e)}catch{return!1}}var be=class extends Error{},us={inHoldout:()=>!0,personalisationGroup:()=>"excluded",servingHeaders:()=>({}),recommendationContext:()=>({}),flush:()=>Promise.resolve(),reset:()=>{}};function Kt(e,t){let n=us[e]??(()=>null),r=o=>(console.warn(`[hp] ${String(e)} failed; nothing was sent`,o),n());return function(...s){try{let i=t.apply(this,s);return typeof i?.then=="function"?Promise.resolve(i).catch(r):i}catch(i){if(i instanceof be)throw i;return r(i)}}}function er(e){for(let t of Reflect.ownKeys(e)){let{value:n}=Object.getOwnPropertyDescriptor(e,t)??{};typeof n=="function"&&(e[t]=Kt(t,n))}return e}var Oe=Symbol("hp.identityOption");var ls=4320*60*60,ds=100,fs=1e3,ps=2e3,tr=500,Je=e=>(e?.unref?.(),e);function ms(e,t){if(t?.analytics===!0&&e.analytics===!1)return"withdrawn";let n=fe.map(r=>e[r]).filter(r=>r!==null);return n.length&&n.every(Boolean)?"accept_all":n.length&&n.every(r=>!r)?"reject_all":"custom"}function hs(e,t,n=C("consent")){if(!(typeof document>"u"))try{let r=typeof location<"u"&&location.protocol==="https:"?"; Secure":"",o=t?`; Domain=${t}`:"";document.cookie=`${n}=${$t(e)}; Path=/; Max-Age=${ls}; SameSite=Lax`+o+r}catch{}}function gs(e){let t=Ce(V(e));return fe.some(n=>t[n]!==null)?t:null}function nr(e){let{adapter:t,timeoutMs:n=5e3,cookieDomain:r=null,cookieName:o=C("consent"),release:s,announce:i}=e,u=e.discard??(()=>{}),c="pending",l=null,f=null,p=null,m=null,A=!1,w=null,x=[],_=R=>{c=R,e.onStatus?.(R)};function k(){try{return _e(t.read())}catch{return null}}function h(){f&&clearInterval(f),p&&clearTimeout(p),f=null,p=null}let E=()=>typeof window<"u"&&typeof document<"u",S=()=>{try{return typeof t.subscribe=="function"&&t.observesChanges===!0}catch{return!1}};function g(){m&&clearInterval(m),m=null}function y(){A||m||l===null||S()||E()&&document.visibilityState==="hidden"||(m=Je(setInterval(()=>K(k()),ps)))}let O=()=>c==="pending"||c==="unknown",N=e.store??null,U=()=>{let R=x.splice(0);N?.write([]);for(let j of R)s(j)},G=()=>{let R=x.splice(0);N?.write([]);for(let j of R)u(j)};function K(R){let j=_e(R);if(!j||j.analytics===null)return;let we=l===null,X=we?gs(o):l;if(!we&&Vt(X,j))return;h(),l=j,y(),hs(j,r,o);let wt=!Vt(X,j);if(j.analytics){_("granted"),U(),wt&&i({action:ms(j,X),state:j,previous:X,withdrawal:!1});return}G(),X?.analytics===!0&&i({action:"withdrawn",state:j,previous:X,withdrawal:!0}),_("denied")}function ie(){p=null,c==="pending"&&(_("unknown"),f&&clearInterval(f),f=Je(setInterval(()=>K(k()),fs)))}function J(R){if(O()){if(N){N.write(x);return}R?.type!=="visibilitychange"&&!R?.persisted&&G()}}let Ue=R=>{document.visibilityState==="hidden"?(g(),J(R)):y()},ae=R=>{g(),J(R)},Ve=R=>{R?.persisted&&l!==null&&K(k()),y()};return{get status(){return c},get state(){return l?{...l}:null},stamp(){return l?{...l,source:t.name??null,basis:t.basis??Ke.visitor}:null},admits(){return c==="granted"},hold(R){return!O()||x.length>=tr?(u(R),!1):(x.push(R),!0)},onHidden:J,start(){A=!1;try{w=t.subscribe?.(R=>K(R))??null}catch(R){e.debug&&console.warn("[hp] consent adapter subscribe failed",R)}E()&&(window.addEventListener("pagehide",ae),window.addEventListener("pageshow",Ve),document.addEventListener("visibilitychange",Ue)),N&&x.length===0&&x.push(...N.read().slice(-tr)),K(k()),!l&&(f=Je(setInterval(()=>K(k()),ds)),p=Je(setTimeout(ie,n)))},stop(){A=!0,h(),g(),typeof w=="function"&&w(),E()&&(window.removeEventListener("pagehide",ae),window.removeEventListener("pageshow",Ve),document.removeEventListener("visibilitychange",Ue))}}}var ys=["recommendation","search_rank","banner","offer","layout","copy","price","other"],Ye=e=>typeof e=="string"&&e!=="";function rr(e){return(Array.isArray(e?.decisions)?e.decisions:[]).filter(t=>Ye(t?.slot)&&Ye(t.decision_id)&&t.holdout!==!0).map(({decision_id:t,slot:n,arm:r,kind:o})=>({decision_id:t,slot:n,...Ye(r)&&{arm:r},...ys.includes(o)&&{kind:o}}))}function or({key:e,mayStore:t}){let n,r=()=>{if(n)return n;try{let s=JSON.parse(sessionStorage.getItem(e));n=Array.isArray(s)?s.filter(i=>Ye(i?.slot)):[]}catch{n=[]}return n},o=()=>{try{n?.length&&t()&&sessionStorage.setItem(e,JSON.stringify(n))}catch{}};return{persist:o,current:()=>r().length?n.map(s=>({...s})):null,remember(s){if(!s.length)return;let i=new Set(s.map(u=>u.slot));n=[...r().filter(u=>!i.has(u.slot)),...s],o()},forget(){n=[];try{sessionStorage.removeItem(e)}catch{}}}}function ws(e){let t=2166136261,n=String(e);for(let r=0;r<n.length;r+=1)t^=n.charCodeAt(r),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t^=t>>>16,t=Math.imul(t,2246822507)>>>0,t^=t>>>13,t=Math.imul(t,3266489909)>>>0,t^=t>>>16,t>>>0}function Xe(e,t,n=1e4){return ws(`${t}\0${e}`)%n}function Gt(e){let t=o=>Math.min(Math.max(Number(o)||0,0),1),n=t(e.share),r=1-n;return{holdout_share:n,personalised_share:e.ramp==null?r:Math.min(t(e.ramp),r)}}function zt(e,t){if(!e||typeof e.salt!="string")return{holdout:!1,bucket:null,group:"personalised"};let n=e.ramp!=null;if(t==null||t==="")return{holdout:!1,bucket:null,group:n?"excluded":"personalised"};let{holdout_share:r,personalised_share:o}=Gt(e),s=Xe(t,e.salt),i=c=>Math.round(c*1e4),u=r>0&&s<i(r)?"holdout":!n||s<i(r+o)?"personalised":"excluded";return{holdout:u==="holdout",bucket:s,group:u}}function sr(e,t){return typeof e!="string"||e===""||t==null||t===""?null:Xe(t,`bandit-vs-default:${e}`)<1e4/2?"default":"bandit"}var Ss="hp_preview",_s=256;function ir(e,t=null){if(typeof location>"u")return V(e);let n=null;try{n=new URLSearchParams(location.search).get(Ss)}catch{n=null}if(n===null)return V(e);let r=n.trim();return r===""||r.length>_s?(re(e,"",0,t),null):(re(e,r,null,t),r)}var bs=40,Is=128,xs=5,ks=60,cr=e=>typeof e=="string"&&e!==""&&e.length<=Is&&!e.includes(","),ar=e=>Array.isArray(e)?e.filter(cr).slice(0,bs):[],As=e=>Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.replaceAll(","," ").trim()).filter(t=>t!=="").slice(0,xs):[],vs=e=>Object.entries(e&&typeof e=="object"?e:{}).filter(([t,n])=>cr(t)&&Number.isFinite(n)&&n>=1).sort(([,t],[,n])=>n-t).slice(0,ks).map(([t,n])=>`${t}:${Math.floor(n)}`);function Wt(e){let t={},n={viewed:ar(e?.recentProducts),basket:ar(e?.basketProducts),q:As(e?.recentSearches),impressed:vs(e?.impressions)};for(let[r,o]of Object.entries(n))o.length>0&&(t[r]=o.join(","));return t}var Es=1800*1e3;function ur(e,t=Date.now()){try{localStorage.setItem(C("recommendationContext"),JSON.stringify({context:e,until:t+Es}))}catch{}}function lr(){try{localStorage.removeItem(C("recommendationContext"))}catch{}}var Cs="hp_sample",dr=1e4;function fr(e,t){return!(typeof t=="number"&&t<1)||e==null||e===""?!0:Xe(e,Cs,dr)<Math.round(t*dr)}function Ie(e){return e.trim().toLowerCase().replace(/\s*\/\s*/g,"/").replace(/^\/+|\/+$/g,"")}var Os=2,Ps=12;function Pe(e,t=Os){return e.split("/").slice(0,t).join("/")}function Jt(e,t){if(typeof t!="string"||!t.trim())return null;let n=Pe(Ie(t));return n?(e.unshift(n),e.length=Math.min(e.length,Ps),n):null}var me=()=>C("sessionSignals"),xe=null,Yt=()=>xe??me();function pr(){try{return xe?localStorage:sessionStorage}catch{return}}function mr(e,t){let n=t==null?null:String(t),r=e?$(me(),n,e):null;if(r===xe)return;let o=xe===null?Ls():null;if(xe=r,!!xe)try{let s=Yt(),i=Un(me(),n);for(let u of Object.keys(localStorage))u.startsWith(i)&&u!==s&&localStorage.removeItem(u);o&&!localStorage.getItem(s)&&(localStorage.setItem(s,JSON.stringify(o)),sessionStorage.removeItem(me()))}catch{}}function Ls(){try{let e=sessionStorage.getItem(me());if(!e)return null;let t=JSON.parse(e);return t&&(t.productViews>0||t.listViews>0||t.basketValue!=null||t.recentProducts?.length||t.recentBrowse?.length||t.campaign)?t:null}catch{return null}}function Ze(){return{productViews:0,listViews:0,cartAdds:0,searches:0,recentProducts:[],recentCategories:[],recentBrowse:[],basketProducts:[],basketValue:null,recentSearches:[],impressions:{},browsingCategory:null,recentBrowseCategories:[],browsingListing:null,listViewsByCategory:{},campaign:null,startedAt:0}}function Xt(){let e=pr();if(!e)return Ze();try{let t=e.getItem(Yt());return t?{...Ze(),...JSON.parse(t)}:{...Ze(),startedAt:Date.now()}}catch{return{...Ze(),startedAt:Date.now()}}}function Qe(e){let t=pr();if(t)try{t.setItem(Yt(),JSON.stringify(e))}catch{}}function et(){return Xt()}function hr(){for(let e of[()=>sessionStorage,()=>localStorage])try{let t=e();t.removeItem(me());for(let n of Object.keys(t))n.startsWith(`${me()}:`)&&t.removeItem(n)}catch{}}var gr=20,yr=200,Ts=new Set(["Product Viewed","Product Clicked","Product Added","Product Added to Wishlist"]),Ns=new Set(["Product Viewed","Product Added"]),wr=50;function tt(e,t){let n=Jt(e.recentBrowse,t);return n?(e.recentBrowseCategories=[e.browsingListing?.category??null,...e.recentBrowseCategories].slice(0,e.recentBrowse.length),n):null}function Rs(e,t){let n=e.listViewsByCategory;n[t]=(n[t]??0)+1;let r=Object.keys(n);if(r.length>wr){let o={};for(let s of r.sort((i,u)=>n[u]-n[i]).slice(0,wr))o[s]=n[s];e.listViewsByCategory=o}}function Sr(e,t,n){let r=Xt();r.startedAt||(r.startedAt=Date.now());let o=n!==void 0&&JSON.stringify(n??null)!==JSON.stringify(r.campaign??null);o&&(r.campaign=n??null);let s=Array.isArray(t?.products)?t.products:[];switch(e){case"Product Viewed":r.productViews+=1,tt(r,r.browsingCategory);break;case"Product List Viewed":{let c=t?.list_id,l=t?.category;if(!(typeof c=="string"&&c.includes("/")&&!c.startsWith("cdp-")))break;let p=typeof l=="string"&&Pe(Ie(l))||null,m=p?Pe(Ie(c)):"";if(!m){r.browsingCategory=null,r.browsingListing=null;break}r.browsingListing={key:m,category:p},tt(r,m),r.browsingCategory=m,Rs(r,p),r.listViews+=1}break;case"Product List Filtered":{let c=t?.change,l=typeof t?.list_id=="string"?t.list_id:"",f=typeof c?.value=="string"?c.value:"",p=r.browsingListing;if(f&&c?.action!=="removed"&&p&&Pe(Ie(l))===p.key){let m=tt(r,`${l}/${f}`);m&&(r.browsingCategory=m)}break}case"Product Added":{r.cartAdds+=1,tt(r,r.browsingCategory);for(let c of s){let l=c.product_id;typeof l!="string"||!l||(r.basketProducts=[l,...r.basketProducts.filter(f=>f!==l)].slice(0,gr))}break}case"Product Removed":{for(let c of s){let l=c.product_id;typeof l=="string"&&l&&(r.basketProducts=r.basketProducts.filter(f=>f!==l))}break}case"Products Searched":{r.searches+=1;let c=t?.query;if(typeof c=="string"&&c.trim()){let l=c.trim().toLowerCase().slice(0,64);r.recentSearches=[l,...r.recentSearches.filter(f=>f!==l)].slice(0,5)}break}case"Product Clicked":case"Product Added to Wishlist":break;case"Cart Updated":{let c=t?.value;return r.basketValue=typeof c=="number"&&Number.isFinite(c)&&c>=0?c:null,Qe(r),r}default:return o&&Qe(r),r}let i=Ts.has(e);if(i)for(let c of s)typeof c.product_id=="string"&&c.product_id&&delete r.impressions[c.product_id];else{for(let l of s){let f=l.product_id;typeof f!="string"||!f||(r.impressions[f]=(r.impressions[f]??0)+1)}let c=Object.keys(r.impressions);if(c.length>yr){let l={};for(let f of c.sort((p,m)=>r.impressions[m]-r.impressions[p]).slice(0,yr))l[f]=r.impressions[f];r.impressions=l}}let u=new Set;for(let c of s){let l=c.product_id;if(i&&typeof l=="string"&&l&&(r.recentProducts=[l,...r.recentProducts.filter(f=>f!==l)].slice(0,gr)),Ns.has(e)&&typeof c.category=="string"&&c.category){let f=Ie(c.category);f&&!u.has(f)&&(u.add(f),Jt(r.recentCategories,f))}}return Qe(r),r}var nt=1800*1e3;function _r({name:e,domain:t=null,mayStore:n,now:r=()=>Date.now(),mint:o=ne}){let s=null,i=0,u=()=>{s!==null&&n()&&re(e,s,nt/1e3,t)};return{get(){let c=r(),l=V(e);return l?s=l:(s===null||c-i>=nt)&&(s=o()),i=c,u(),s},persist:u,forget(){re(e,"",0,t),s=null}}}var W=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),br=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"),Ir=Object.freeze({enabled:!1}),Qt=Object.freeze({enabled:!0,queryParamAllowlist:Object.freeze([])});function xr(e,t){let n=e?.track;return W(n)?(Object.hasOwn(n,t)?n[t]:n.__default)?.enabled!==!1:!0}function Ms(e,t){return`${oe(e)}/v1/projects/${encodeURIComponent(t)}/settings`}var Ds="https://hp.thgingenuity.com";function oe(e){return e==null||e===""?Ds:Ar(e)}function kr(e,t){return e!=null&&e!==""?oe(e):t?.startsWith("https://")?t:oe(void 0)}function Ar(e){if(typeof e!="string")return null;let t=e.trim().replace(/\/+$/,"");return/^https?:\/\/[^/\s]+$/i.test(t)?t:/^[a-z0-9.-]+(:\d+)?$/i.test(t)?`https://${t}`:null}function Us(e){if(!W(e))return null;let t=Object.fromEntries(Object.entries(e).filter(([,n])=>typeof n=="boolean"));return Object.keys(t).length?t:null}var Zt=e=>typeof e=="number"&&e>=0&&e<=1,Vs=/^[0-9a-f]{64}$/;function $s(e){return W(e)?{enabled:e.enabled===!0,tokenSha256:typeof e.tokenSha256=="string"&&Vs.test(e.tokenSha256)?e.tokenSha256:null}:{enabled:!1,tokenSha256:null}}function Bs(e){if(!W(e))return null;let t=Object.fromEntries(Object.entries(e).filter(([,n])=>W(n)&&Zt(n.share)&&(n.ramp==null||Zt(n.ramp))&&typeof n.salt=="string"&&n.salt!=="").map(([n,r])=>[n,{share:r.share,ramp:r.ramp??null,salt:r.salt,...br(r.readoutSlots)&&r.readoutSlots.length>0&&{readoutSlots:r.readoutSlots}}]));return Object.keys(t).length?t:null}var js=/^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;function Hs(e){return W(e)?e.source==="hp_cookie"?{source:"hp_cookie"}:e.source!=="site_cookie"?null:e.cookie==null?{source:"site_cookie",cookie:null}:typeof e.cookie=="string"&&js.test(e.cookie)?{source:"site_cookie",cookie:e.cookie}:null:null}function Fs(e){let t=Array.isArray(e?.forms)?e.forms.filter(W):[];return t.length===0?null:{forms:t,capture:W(e.capture)?e.capture:null,...Number.isInteger(e.overlay_gap_minutes)?{overlay_gap_minutes:e.overlay_gap_minutes}:{}}}function qs(e){let t=W(e)?e.hp:null;return W(t)&&typeof t.enabled=="boolean"}function en(e){let t=W(e)?e.hp:null;if(!W(t)||t.enabled!==!0)return Ir;let n=Fs(t.onsite);return{enabled:!0,propertyId:typeof t.propertyId=="string"&&t.propertyId!==""?t.propertyId:null,environment:typeof t.environment=="string"?t.environment:null,consentPurposes:Us(t.consent?.purposes),queryParamAllowlist:br(t.queryParamAllowlist)?t.queryParamAllowlist:null,anonymousId:Hs(t.anonymousId),apiHost:Ar(t.apiHost),holdouts:Bs(t.holdouts),sampleRate:Zt(t.sampleRate)?t.sampleRate:1,debug:$s(t.debug),...n&&{onsite:n},plan:W(e.plan)&&W(e.plan.track)?{track:e.plan.track}:null}}var Ks=3e3;async function vr(e,t,n=globalThis.fetch,r=Ks){try{let o=await n(Ms(e,t),{credentials:"omit",headers:{accept:"application/json"},signal:AbortSignal.timeout?.(r)});if(o.status>=400&&o.status<500&&o.status!==408&&o.status!==429)return Ir;if(!o.ok)return null;let s=await o.json();return qs(s)?en(s):null}catch{return null}}var rt=e=>$(C("settings"),e);function Er(e){try{let t=localStorage.getItem(rt(e));if(!t)return null;let n=JSON.parse(t);return n?.enabled===!0?n:null}catch{return null}}function Cr(e,t){try{t?.enabled===!0?localStorage.setItem(rt(e),JSON.stringify(t)):localStorage.removeItem(rt(e))}catch{}}function tn(e){try{localStorage.removeItem(rt(e))}catch{}}var Gs={flushAt:20,flushIntervalMs:1e4,maxQueue:500,maxRetryAgeMs:1440*60*1e3,maxRetries:5,maxPersistedBatches:20,maxPersistedBytes:1024*1024,storageKey:de.retry,beaconSafeBytes:56*1024,maxBatchEvents:100,maxBatchBytes:500*1024},ot=()=>Date.now(),Or=3e4,cn=55*1024;function zs(e,t=ot()){if(typeof e!="string")return 0;let n=e.trim();if(/^\d+$/.test(n))return Number(n)*1e3;if(n==="")return 0;let r=Date.parse(n);return Number.isNaN(r)?0:Math.max(0,r-t)}var se=e=>typeof TextEncoder<"u"?new TextEncoder().encode(e).length:Buffer.byteLength(e),nn=()=>typeof window<"u"&&typeof document<"u";function Ws(){try{return!nn()||!window.localStorage?null:(window.localStorage.getItem("thg_hp_probe"),window.localStorage)}catch{return null}}var b,rn,on,st,sn,an,Pr,Le,Te,Ne,Lr,it,Tr,at,ct=class{constructor(t){wn(this,b);this.o={...Gs,...t},this.queue=[],this.timer=null,this.storage=Ws(),this.inflight=null,this.sending=new Set,this.epoch=0,this.sinceRefusal=new Set,this.wakers=new Set,this.replayAllowed=!this.o.deferReplay,this.draining=null,this.failing=!1,this.answered=!1,nn()&&(window.addEventListener("pagehide",()=>this.flush({beacon:!0})),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush()}),L(this,b,at).call(this))}markFailing(){this.answered||(this.failing=!0)}replayPersisted(){return this.replayAllowed=!0,L(this,b,at).call(this)}clearPersisted(){if(this.replayAllowed=!1,!!this.storage)try{let t=L(this,b,Ne).call(this).filter(n=>this.sinceRefusal.has(n?.id));t.length?this.storage.setItem(this.o.storageKey,JSON.stringify(t)):this.storage.removeItem(this.o.storageKey)}catch{}}discardQueued(){this.queue=[],this.epoch+=1,this.sinceRefusal.clear(),L(this,b,on).call(this);for(let t of this.wakers)t()}enqueue(t){let n;try{n=JSON.parse(JSON.stringify(t))}catch(r){this.o.onError?.(`event ${t?.messageId??""} cannot be serialised; dropped`,r);return}this.queue.push(n),this.queue.length>this.o.maxQueue&&this.queue.splice(0,this.queue.length-this.o.maxQueue),this.queue.length>=this.o.flushAt?this.flush():L(this,b,rn).call(this)}flush(t={}){if(L(this,b,on).call(this),this.queue.length===0)return Promise.resolve();if(t.beacon&&nn()&&typeof navigator<"u"&&navigator.sendBeacon)return L(this,b,Pr).call(this),Promise.resolve();if(this.inflight)return this.inflight;let n=L(this,b,an).call(this,this.queue,this.o.maxBatchEvents,this.o.maxBatchBytes).map(o=>{let s=L(this,b,it).call(this,o);return s&&(this.sending.add(s),this.sinceRefusal.add(s)),{batch:o,id:s}});this.queue=[];let r=this.epoch;return this.inflight=(async()=>{for(let{batch:o,id:s}of n){if(r!==this.epoch){L(this,b,Te).call(this,s);continue}await L(this,b,Le).call(this,o,0,s,r)}})().finally(()=>{this.inflight=null,this.queue.length>=this.o.flushAt?this.flush():this.queue.length&&L(this,b,rn).call(this)}),this.inflight}};b=new WeakSet,rn=function(){this.timer||(this.timer=setTimeout(()=>this.flush(),this.o.flushIntervalMs),this.timer?.unref?.())},on=function(){this.timer&&(clearTimeout(this.timer),this.timer=null)},st=function(t){return JSON.stringify({batch:t,writeKey:this.o.writeKey,sentAt:new Date().toISOString()})},sn=function(){return`${this.o.apiHost.replace(/\/$/,"")}/v1/batch`},an=function(t,n,r){let o=se(L(this,b,st).call(this,[])),s=[],i=[],u=o;for(let c of t){let l=se(JSON.stringify(c))+1;i.length&&(i.length>=n||u+l>r)&&(s.push(i),i=[],u=o),i.push(c),u+=l}return i.length&&s.push(i),s},Pr=function(){let t=this.queue;this.queue=[];let n=L(this,b,sn).call(this);for(let r of L(this,b,an).call(this,t,this.o.maxBatchEvents,this.o.beaconSafeBytes)){let o=L(this,b,st).call(this,r);if(se(o)<=this.o.beaconSafeBytes){let s=!1;try{s=navigator.sendBeacon(n,new Blob([o],{type:"text/plain"}))}catch{s=!1}if(s){let i=this.failing?L(this,b,it).call(this,r):null;i&&this.sending.add(i);continue}}L(this,b,Le).call(this,r,0,L(this,b,it).call(this,r))}},Le=async function(t,n,r=null,o=this.epoch){r&&this.sending.add(r);let s=L(this,b,st).call(this,t),i=0;try{let u=await fetch(L(this,b,sn).call(this),{method:"POST",headers:{"Content-Type":"text/plain"},body:s,keepalive:se(s)<=this.o.beaconSafeBytes});if(u.ok)return this.failing=!1,this.answered=!0,L(this,b,Te).call(this,r),L(this,b,at).call(this),!0;let c=u.status===408||u.status===429||u.status>=500;if(c&&(i=zs(u.headers?.get?.("retry-after"))),!c)return L(this,b,Te).call(this,r),this.o.onError?.(`CDP ingest rejected batch (${u.status}); dropping ${t.length} events`),!0;throw new Error(`retryable ${u.status}`)}catch(u){if(this.failing=!0,n>=this.o.maxRetries){r&&this.sending.delete(r);let l=r?"kept for the next page":"dropped";return this.o.onError?.(`CDP ingest unreachable after ${n} attempts; ${l}: ${t.length} events`,u),!1}let c=Math.max(Math.min(1e3*2**n,Or)*(.5+Math.random()),Math.min(i,Or));return o===this.epoch&&await new Promise(l=>{let f=()=>{clearTimeout(p),this.wakers.delete(f),l()},p=setTimeout(f,c);this.wakers.add(f)}),o!==this.epoch?(L(this,b,Te).call(this,r),!1):L(this,b,Le).call(this,t,n+1,r,o)}},Te=function(t){t&&(this.sending.delete(t),this.sinceRefusal.delete(t),L(this,b,Tr).call(this,t))},Ne=function(){let t=JSON.parse(this.storage.getItem(this.o.storageKey)||"[]");return Array.isArray(t)?t:[]},Lr=function(t,n){let r=i=>se(JSON.stringify(i))+1,o=[...t,n].slice(-this.o.maxPersistedBatches),s=o.reduce((i,u)=>i+r(u),2);for(;o.length>1&&s>this.o.maxPersistedBytes;)s-=r(o[0]),o=o.slice(1);for(;o.length;)try{return this.storage.setItem(this.o.storageKey,JSON.stringify(o)),!0}catch{o=o.slice(1)}return!1},it=function(t){if(!this.storage||this.o.mayPersist&&!this.o.mayPersist())return null;try{let n={at:ot(),id:`${ot()}-${Math.random().toString(36).slice(2)}`,batch:t};return se(JSON.stringify(n))+3>this.o.maxPersistedBytes?null:L(this,b,Lr).call(this,L(this,b,Ne).call(this),n)?n.id:null}catch{return null}},Tr=function(t){if(!(!t||!this.storage))try{let n=L(this,b,Ne).call(this).filter(r=>r.id!==t);n.length?this.storage.setItem(this.o.storageKey,JSON.stringify(n)):this.storage.removeItem(this.o.storageKey)}catch{}},at=function(){if(!this.storage||!this.replayAllowed)return this.draining??Promise.resolve();if(this.draining)return this.draining;let t;try{let r=L(this,b,Ne).call(this);t=r.filter(o=>Array.isArray(o?.batch)&&ot()-o.at<this.o.maxRetryAgeMs).map(o=>o.id?o:{...o,id:`${o.at}-${Math.random().toString(36).slice(2)}`}),(t.length!==r.length||t.some((o,s)=>o!==r[s]))&&(t.length?this.storage.setItem(this.o.storageKey,JSON.stringify(t)):this.storage.removeItem(this.o.storageKey))}catch{return Promise.resolve()}let n=t.filter(r=>!this.sending.has(r.id));return n.length?(this.draining=(async()=>{for(let r of n)if(!this.replayAllowed||!await L(this,b,Le).call(this,r.batch,0,r.id))return})().finally(()=>{this.draining=null}),this.draining):Promise.resolve()};var Nr="3.27.0",Rr="@thg-agentic/hyper-personalisation-web";var Js=100,Ys=["source","medium","campaign","content","term"];function Dr(e){if(!e||typeof e!="object")return null;let t={};for(let n of Ys){let r=e[n==="campaign"?"name":n];typeof r=="string"&&r&&(t[n]=r.slice(0,Js))}return Object.keys(t).length?t:null}var Ur=e=>$(C("visitCampaign"),e==null?null:String(e)),ke=new Map;function Vr(e){if(ke.has(e))return ke.get(e);try{let t=JSON.parse(localStorage.getItem(e));return t&&typeof t=="object"?t:null}catch{return null}}function Mr(e,t){try{t?localStorage.setItem(e,JSON.stringify(t)):localStorage.removeItem(e),ke.delete(e)}catch{t?ke.set(e,t):ke.delete(e)}}function $r(e,t,n){return typeof e?.tags=="object"&&e.tags!==null&&Number.isFinite(e.at)&&n-e.at<nt&&!(t&&e.sid&&e.sid!==t)?e:null}function ut(e,{sessionId:t=null,now:n=Date.now()}={}){return $r(Vr(Ur(e)),t,n)?.tags??null}function Br(e,t,{sessionId:n=null,keepSession:r=!1,now:o=Date.now()}={}){let s=Ur(e),i=Vr(s),u=$r(i,n,o),c=u?.tags??t??null;return c?Mr(s,{tags:c,at:o,sid:(r?n:null)??u?.sid??null}):i&&Mr(s,null),c}function un(){ke.clear();try{let e=`${C("visitCampaign")}:`;for(let t of Object.keys(localStorage))t.startsWith(e)&&localStorage.removeItem(t)}catch{}}var Xs=new Set(["audiences","decisions","recommendations"]);var Zs=Symbol.for("@thg-agentic/hyper-personalisation-web.replay"),Qs=Symbol.for("@thg-agentic/hyper-personalisation-web.unreachable"),ei=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access");function ti(e){let t={...e??{}},n=Array.isArray(t.products)?t.products:null;if(t.item_count==null&&n){let r=n.map(o=>o?.quantity);r.every(Number.isInteger)&&(t.item_count=r.reduce((o,s)=>o+s,0))}return t}var ni="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";function ri(e){if(/^[0-9a-fA-F]{64}$/.test(e))return e.toLowerCase();if(!/^[A-Za-z0-9+/_-]{43}=?$/.test(e))return null;try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(44,"="));return t.length!==32?null:Array.from(t,n=>n.charCodeAt(0).toString(16).padStart(2,"0")).join("")}catch{return null}}function dt(e){if(typeof e!="string")return null;let t=ri(e.trim());return t===ni?null:t}var jr=Object.freeze({email_sha256:"sha256",phone_sha256:"sha256",accepts_marketing:"boolean",gender:"string",created_at:"date-time"}),oi=/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)$/i;function si(e){if(typeof e!="string"||!oi.test(e))return!1;let[t,n,r]=e.slice(0,10).split("-").map(Number),o=new Date(Date.UTC(t,n-1,r));return o.getUTCMonth()===n-1&&o.getUTCDate()===r&&!Number.isNaN(Date.parse(e))}function ii(e,t){return t===null?null:e==="sha256"?dt(t)??void 0:e==="date-time"?t instanceof Date?Number.isNaN(t.getTime())?void 0:t.toISOString():si(t)?t:void 0:typeof t===e?t:void 0}function ai(e,t){let n={},r=[];for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(jr,o)?jr[o]:null,u=i?ii(i,s):void 0;u===void 0?r.push(o):n[o]=u}return t&&r.length&&console.warn(`[hp] identify: not sent, not spec traits: ${r.join(", ")}`),n}var Hr=!1,Fr=!1;function ci(){Fr||(Fr=!0,console.warn("[hp] no consent adapter: events are sent under the host's lawful basis (basis 'host'). Pass `consent` to send only once the visitor allows analytics."))}function ui(e){!e||Hr||(Hr=!0,console.warn("[hp] mintAnonymousId is ignored since 3.6: where device ids come from is set per source in the console (the site\u2019s own cookie, or Hyper-Personalisation\u2019s)."))}function li(e){try{return se(JSON.stringify(e))}catch{return 0}}function lt(e){return e&&typeof e.context=="object"&&e.context!==null?e.context:e}function di(e,t){if(e==null||String(e)===t)return;let n=[["localStorage","retry",(r,o)=>[...Array.isArray(r)?r:[],...Array.isArray(o)?o:[]]],["sessionStorage","held",(r,o)=>o?{...o,items:[...r.items??[],...o.items??[]]}:r]];for(let[r,o,s]of n)try{let i=globalThis[r],u=$(C(o),e),c=i?.getItem(u);if(!c)continue;let l=$(C(o),t),f=i.getItem(l);i.setItem(l,JSON.stringify(s(JSON.parse(c),f?JSON.parse(f):null))),i.removeItem(u)}catch{}}function qr(e){let t=oe(e?.apiHost);if(!t)throw new Error("createAnalytics: apiHost, when given, must be a host or an http(s) origin");if(e?.propertyId!==null&&!e?.propertyId)throw new Error("createAnalytics: propertyId is required (null: the ingest stamps the key\u2019s)");let n={libraryName:Rr,libraryVersion:Nr,writeKey:"web",queryParamBlocklist:[],debug:!1,validate:null,consentTimeoutMs:5e3,...e,apiHost:t};He(n.storageNames),Fe();let r=!!n.consent;r||ci();let o=null;n.getConsent=()=>o?o.stamp():jn();let s=()=>!r||o?.status==="granted";di(n.propertyId,n.writeKey);let i=r&&n.holdAcrossPages?Vn($(C("held"),n.writeKey)):null,u=i?.read()??{items:[],anonymousId:null};n.mintAnonymousId!==void 0&&ui(n.debug);let c=$n(n,{carried:u.anonymousId,mayStore:s,orOwn:!0}),l=_r({name:C("session"),domain:n.consentCookieDomain??null,mayStore:s}),f=n.getSessionId;n.getSessionId=()=>F(M(f,null))??l.get();let p=ir(C("preview"),n.consentCookieDomain??null),m=()=>F(M(f,null))??V(C("session")),A=Dr(typeof location>"u"?null:Pt(location.search)),w=(a=null)=>{p||Br(n.propertyId,a,{sessionId:m(),keepSession:s()})},x=(a,d)=>n.debug&&console.warn("[hp]",a,d??""),_=n.transport??new ct({apiHost:n.apiHost,writeKey:n.writeKey,storageKey:$(C("retry"),n.writeKey),mayPersist:r?()=>o?.status==="granted":void 0,deferReplay:r,onError:x}),k=$(C("previousPage"),n.propertyId),h=null,E=()=>{if(h)return h;try{return sessionStorage.getItem(k)||null}catch{return null}};typeof window<"u"&&window.addEventListener("pageshow",a=>{a.persisted&&(h=null)});let S=a=>{if(h=a||null,!(r&&o.status!=="granted"))try{sessionStorage.setItem(k,a)}catch{}},g=or({key:$(C("decisions"),n.propertyId),mayStore:s});n.getDecisions??(n.getDecisions=g.current);let y=F(M(n.getUserId,null)),O=null,N=null,U=y?ve(n.identityToken):null,G=null,K=null,ie=new Set,J=new Set;function Ue(a){if(a.type!=="track"||a.event!=="Cart Updated")return;let d=a.properties?.value;K=typeof d=="number"&&Number.isFinite(d)&&d>=0?d:null;for(let I of ie)try{I()}catch(P){console.warn("[hp] a basket listener failed",P)}}function ae(a,d,I=!1){Ue(a),w();try{return Ve(a,d,I)}catch(P){if(P instanceof be)throw P;return console.warn("[hp] the event was not sent",P),null}}function Ve(a,d,I){let P=G;G=null;let q=a.type==="track"?a.event:a.type;if(!I&&!xr(n.plan,q))return null;let T={messageId:P?.messageId??ne(),timestamp:P?.timestamp??new Date().toISOString(),anonymousId:F(M(n.getAnonymousId,null)),userId:y??null,...a,context:Nn(n,lt(d))};if(T.properties&&(T.properties=Ct(T.properties)),typeof T.properties?.href=="string"&&(T.properties.href=Lt(T.properties.href,n)),!I&&!fr(T.anonymousId,n.sampleRate))return n.debug&&console.debug("[hp] not sent: outside the sample",T),null;if(n.beforeSend){let Q;try{Q=n.beforeSend(T)}catch(ao){return console.warn("[hp] beforeSend failed; the event was not sent",ao),null}if(!Q)return null;let{type:z,event:gn,messageId:so,timestamp:io}=T;T={...Q,type:z,messageId:so,timestamp:io,...gn?{event:gn}:{}}}if(n.validate){let Q=n.validate(T,{producer:"web"});if(!Q.valid){let z=`[hp] invalid ${T.event??T.type}:
2
2
  ${Q.errors.join(`
3
- `)}`;if(n.throwOnInvalid)throw new be(z);console.error(z)}}n.debug&&console.debug("[hp]",T.event??T.type,T);let St=li(T);return St>an?(x(`${T.event??T.type} not sent: ${St} bytes, over the ${an}-byte limit for one event`),null):(no(T,I),T)}function R(a){if(a.type==="track"&&gt(a),n.onEvent)try{n.onEvent(a)}catch(l){console.warn("[hp] onEvent observer failed",l)}}let j=()=>r&&o?.state?.personalisation===!0,we=()=>pr(M(n.getSessionId,null),n.propertyId),X=!1;function gt(a){try{j()?(we(),cr(Gt(wr(a.event,a.properties))),X=!0):$e()}catch(l){n.debug&&console.warn("[hp] the visit was not recorded",l)}}function $e(a=!1){ur(),(a||X)&&mr(),X=!1}function yt(){d.forget(),h.forget(),wt.clear(),u?.forget(),$e(!0),cn()}function no(a,l){!r||l||o.admits()?(R(a),_.enqueue(a)):o.hold(a)}let v=(a,l,I)=>ae({type:"track",event:a,properties:l??{}},I),wt=new Set,ro=(a,l,I)=>a==="audiences"?{audiences:l?null:I.audiences??[]}:a==="decisions"?{decisions:(I.decisions??[]).map(P=>({slot:P.slot,decision_id:P.decision_id??null,arm:P.arm??null,...P.variant&&{variant:P.variant}}))}:{recommendation_request_id:I.recommendation_request_id??null};w(A),r&&(o=tr({adapter:n.consent,timeoutMs:n.consentTimeoutMs,cookieDomain:n.consentCookieDomain,debug:n.debug,store:s&&{read:()=>c.items,write:a=>s.write(a,u?.peek()??null)},release(a){a.context&&(a.context.consent=o.stamp()),R(a),_.enqueue(a)},onStatus(a){if(a==="granted"&&(u?.persist(),d.persist(),m&&S(m),h.persist(),_.replayPersisted?.()),a==="denied"){_.clearPersisted?.(),u?.forget(),d.forget();try{sessionStorage.removeItem(k)}catch{}h.forget(),$e(!0)}try{n.onConsentStatus?.(a)}catch(l){console.warn("[hp] onConsentStatus observer failed",l)}if(a==="granted"||a==="denied")for(let l of J)try{l()}catch(I){console.warn("[hp] a consent listener failed",I)}},announce({action:a,state:l,previous:I,withdrawal:P}){l?.personalisation!==!0&&$e(I?.personalisation===!0),P&&(_.discardQueued?.(),cn()),ae({type:"track",event:"Consent Updated",properties:{action:a,state:l}},void 0,P),P&&_.flush()}}),o.start(),w());let dn=()=>n.holdout?qt(n.holdout):null,fn=()=>Kt(n.holdout,F(M(n.getAnonymousId,null))).group;function oo(a,l){if(!Array.isArray(a?.decisions))return a;let I=n.holdout?.readoutSlots??[],P=F(M(n.getAnonymousId,null));return{...a,decisions:a.decisions.map(q=>{let T=q?.variant==="bandit"||q?.variant==="default"?q.variant:!l&&q?.holdout!==!0&&I.includes(q?.slot)?or(q.slot,P):null;return T?T==="default"?{...q,variant:T,decision_id:null}:{...q,variant:T}:q})}}function pn(a,l){if(p)return null;let I=a?.exposure,P=I?.holdout===!0,q=oo(a,P);return h.remember(nr(q)),!I?.token||wt.has(I.token)?null:(wt.add(I.token),v("Personalisation Exposed",{exposure_token:I.token,surface:I.surface,holdout:P,holdout_share:I.holdout_share??dn()?.holdout_share??null,personalised_share:I.personalised_share??dn()?.personalised_share??null,...ro(I.surface,P,q)},l))}function mn(a){return y&&yt(),y=null,O=null,N=null,U=null,a}return Qn({track:(a,l,I)=>a==="Signed Out"?mn(v(a,l,I)):v(a,l,I),page(a,l){a??(a={});let I=n.pageType??null;a.type&&(Se.has(a.type)?(I=a.type,n.pageType=a.type):n.debug&&console.warn(`[hp] ignoring unknown page.type "${a.type}". Allowed: ${[...Se].join(", ")}`));let P=ae({type:"page",properties:{name:a.name??null,navigation_trigger:a.navigation_trigger??vn(),previous_message_id:E()}},{page:{type:I},...ct(l)??{}});return P&&S(P.messageId),P},identify(a,l,I){let{userId:P,...q}=a&&typeof a=="object"?a:{},T=ve(ct(l)?.identity_token);if(P!==void 0){let z=F(P);U=z?z===y?T??U:T:null,I===Oe?N=z:O&&z&&z!==O?yt():n.debug&&N&&z&&z!==N&&console.warn("[hp] identify names another userId than the identity option; using the new one"),y=z,z&&I!==Oe&&(O=z)}else T&&y&&(U=T);let{identity_token:St,...Q}=ct(l)??{};return ae({type:"identify",traits:ai(q,n.debug)},U?{...Q,identity_token:U}:Q)},reset(){y&&yt(),y=null,O=null,N=null,U=null,S("")},productViewed:(a,l)=>v("Product Viewed",a,l),productListViewed:(a,l)=>v("Product List Viewed",a,l),recommendationsViewed:(a,l)=>v("Recommendations Viewed",a,l),personalisationExposed:(a,l)=>v("Personalisation Exposed",a,l),recordExposure:pn,surfaceViewed({surface:a}={},l){if(!Xs.has(a)||!n.holdout||a!=="decisions"&&!j())return null;let I=F(M(n.getAnonymousId,null)),P=Kt(n.holdout,I).group;if(P==="excluded")return null;let q=xn({sessionId:Be(M(n.getSessionId,null),I),surface:a});return q?pn({exposure:{token:q,surface:a,holdout:P==="holdout"}},l):null},inHoldout:()=>fn()!=="personalised",personalisationGroup:fn,productClicked:(a,l)=>v("Product Clicked",a,l),productListFiltered:(a,l)=>v("Product List Filtered",a,l),productsSearched:(a,l)=>v("Products Searched",a,l),searchSuggestionsViewed:(a,l)=>v("Search Suggestions Viewed",a,l),productAdded:(a,l)=>v("Product Added",a,l),productRemoved:(a,l)=>v("Product Removed",a,l),cartUpdated:(a,l)=>v("Cart Updated",ti(a),l),identityLinked:(a,l)=>v("Identity Linked",a,l),slotEngaged:(a,l)=>p?null:v("Slot Engaged",a,l),productVariantSelected:(a,l)=>v("Product Variant Selected",a,l),cartViewed:(a,l)=>v("Cart Viewed",a,l),productAddedToWishlist:(a,l)=>v("Product Added to Wishlist",a,l),productRemovedFromWishlist:(a,l)=>v("Product Removed from Wishlist",a,l),wishlistProductAddedToCart:(a,l)=>v("Wishlist Product Added to Cart",a,l),productShared:(a,l)=>v("Product Shared",a,l),cartShared:(a,l)=>v("Cart Shared",a,l),couponEntered:(a,l)=>v("Coupon Entered",a,l),couponApplied:(a,l)=>v("Coupon Applied",a,l),couponDenied:(a,l)=>v("Coupon Denied",a,l),couponRemoved:(a,l)=>v("Coupon Removed",a,l),checkoutStarted:(a,l)=>v("Checkout Started",a,l),promotionViewed:(a,l)=>v("Promotion Viewed",a,l),promotionClicked:(a,l)=>v("Promotion Clicked",a,l),checkoutStepViewed:(a,l)=>v("Checkout Step Viewed",a,l),checkoutStepCompleted:(a,l)=>v("Checkout Step Completed",a,l),paymentInfoEntered:(a,l)=>v("Payment Info Entered",a,l),checkoutFailed:(a,l)=>v("Checkout Failed",a,l),signedIn:(a,l)=>v("Signed In",a,l),signedUp:(a,l)=>v("Signed Up",a,l),signedOut:a=>mn(v("Signed Out",{},a)),newsletterSubscribed:(a,l)=>v("Newsletter Subscribed",a,l),newsletterUnsubscribed:(a,l)=>v("Newsletter Unsubscribed",a,l),preferencesStated:(a,l)=>v("Preferences Stated",a,l),backInStockSubscribed:(a,l)=>v("Back In Stock Subscribed",a,l),productReviewed:(a,l)=>v("Product Reviewed",a,l),consentUpdated:(a,l)=>v("Consent Updated",a,l),flush:a=>_.flush(a),recommendationContext(){if(!j())return{};try{return we(),Gt(Qe())}catch{return{}}},get consent(){return o?o.state:null},servingHeaders:()=>Vt(o?.state??null),get lastPageMessageId(){return E()},get anonymousId(){return F(M(n.getAnonymousId,null))},[ei](){return{writeKey:n.writeKey,storageKey:$(C("onsite"),n.propertyId),gatewayHost:n.apiHost,servingHost:n.servingHost??n.apiHost,settings:n.onsite??null,debug:n.debug===!0,preview:p,anonymousId:()=>F(M(n.getAnonymousId,null)),sessionId:()=>F(M(n.getSessionId,null)),identityToken:()=>j()?U:null,analytics:i,personalisation:j,consent:()=>n.getConsent(),headers:()=>Vt(o?.state??null),pageUrl:()=>typeof location>"u"?null:Ot(location.href,n),locale:()=>Lt(M(n.getLocale,n.locale)),campaign:()=>p?A:$r(n.propertyId,{sessionId:g()}),basketValue:()=>{let a=Qe().basketValue;return K??(Number.isFinite(a)?a:null)},sessionSignals:()=>j()?(we(),Qe()):null,onBasket:a=>(ie.add(a),()=>ie.delete(a)),consentAnswered:()=>!o||o.status==="granted"||o.status==="denied",onConsentAnswered:a=>(J.add(a),()=>J.delete(a))}},[Qs](){_.markFailing?.()},[Zs](a,l,I){if(typeof this[a]=="function"){G=typeof I?.messageId=="string"&&typeof I?.timestamp=="string"?{messageId:I.messageId,timestamp:I.timestamp}:null;try{this[a](...Array.isArray(l)?l:[])}finally{G=null}}}})}var Re=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),Y=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),Me=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),lt=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),fi=["shown","submitted","apply","closed","held"],Kr=10,he=()=>typeof window>"u"?null:window;function De(){try{for(let{resolve:e}of he()?.[Y]?.splice(0)??[])e(!1)}catch{}}var ge=Object.freeze({open(e){try{let t=he();if(!t||typeof e!="string")return Promise.resolve(!1);if(t[Re])return t[Re].open(e);if(t[Y]??(t[Y]=[]),t[Y].length<Kr)return new Promise(n=>t[Y].push({slot:e,resolve:n}))}catch{}return Promise.resolve(!1)},show(e){return ge.open(e)},on(e,t){var n;try{let r=he();return!r||!fi.includes(e)||typeof t!="function"?()=>{}:(r[Me]??(r[Me]={}),((n=r[Me])[e]??(n[e]=new Set)).add(t),()=>r[Me][e].delete(t))}catch{return()=>{}}},suppress(e="page"){try{let t=he();if(!t)return;(t[lt]??(t[lt]=new Set)).add(String(e)),t[Re]?.suppress()}catch{}},unsuppress(e){try{let t=he()?.[lt];e===void 0?t?.clear():t?.delete(String(e))}catch{}},ready(){try{let e=he();if(!e)return Promise.resolve([]);if(e[Re])return Promise.resolve(ge.debug());if(e[Y]??(e[Y]=[]),e[Y].length<Kr)return new Promise(t=>e[Y].push({slot:null,resolve:()=>t(ge.debug())}))}catch{}return Promise.resolve([])},debug(){try{return he()?.[Re]?.debug()??[]}catch{return[]}}});function Gr(e){let t=typeof document>"u"?null:document.currentScript?.src;return t?new URL(e,t).href:null}var dt=new Map;function zr(e,t){return window[t]?Promise.resolve(window[t]):e?(dt.has(t)||dt.set(t,new Promise((n,r)=>{let o=document.createElement("script");o.src=e,o.async=!0,o.onload=()=>window[t]?n(window[t]):r(new Error(`${e} did not register`)),o.onerror=()=>r(new Error(`${e} did not load`)),document.head.append(o)}).finally(()=>dt.delete(t))),dt.get(t)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var pi=Gr("onsite.min.js"),un=()=>zr(pi,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module"));var ln=Symbol.for("@thg-agentic/hyper-personalisation-web.bootstrap"),mi=Symbol.for("@thg-agentic/hyper-personalisation-web.drain"),hi=Symbol.for("@thg-agentic/hyper-personalisation-web.carry"),Wr=Symbol.for("@thg-agentic/hyper-personalisation-web.replay"),gi=Symbol.for("@thg-agentic/hyper-personalisation-web.unreachable"),yi=Symbol.for("@thg-agentic/hyper-personalisation-web.assignment"),wi=Symbol.for("@thg-agentic/hyper-personalisation-web.recommendation-context"),mt=e=>e?()=>V(e):()=>null,Xr={didomi:e=>Fn({purposes:e.purposes}),onetrust:e=>qn({groups:e.groups,impliedConsent:e.impliedConsent}),cookie:e=>Kn({name:e.name,categories:e.categories,refusedValue:e.refusedValue,source:e.source,changeEvent:e.changeEvent}),forwarded:e=>Gn({name:e.name}),static:e=>{if(!e.state||typeof e.state!="object")throw new Error('consent.state is required for provider "static"');return zn(e.state)}},Jr=Object.keys(Xr),ye=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),ft=e=>typeof e=="string"&&e!=="",Si=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"),Zr=e=>ye(e)&&typeof e.read=="function";function _i(e,t={}){let n=[];if(!ye(e))return["config must be { writeKey, apiHost? }"];ft(e.writeKey)||n.push("writeKey is required"),oe(e.apiHost)||n.push("apiHost, when given, must be a host or an http(s) origin"),t.propertyId!==void 0&&!ft(t.propertyId)&&n.push("propertyId must be a string");let{consent:r}=t;if(!Zr(r)&&!(ye(r)&&Jr.includes(r.provider))&&n.push(`consent must be a consent adapter or { provider: ${Jr.join(" | ")} }`),t.autocapture!==void 0&&t.autocapture!==!1&&!ye(t.autocapture)&&n.push("autocapture must be false or { promotions, productLists, recommendations }"),t.onsite!==void 0&&typeof t.onsite!="boolean"&&!ye(t.onsite)&&n.push("onsite must be true, false or the onsite options"),t.beforeSend!==void 0&&typeof t.beforeSend!="function"&&n.push("beforeSend must be a function"),t.identityCookies!==void 0)if(!ye(t.identityCookies))n.push("identityCookies must be an object");else for(let o of["anonymousId","sessionId"]){let i=t.identityCookies[o];i!==void 0&&!ft(i)&&n.push(`identityCookies.${o} must be a cookie name`)}for(let o of["getCurrency","getShipToCountry","getLocale"])t[o]!==void 0&&typeof t[o]!="function"&&n.push(`${o} must be a function`);return t.dataLayer!==void 0&&(ye(t.dataLayer)?(t.dataLayer.name!==void 0&&!ft(t.dataLayer.name)&&n.push("dataLayer.name must be a string"),t.dataLayer.ignore!==void 0&&!Si(t.dataLayer.ignore)&&n.push("dataLayer.ignore must be an array of strings")):n.push("dataLayer must be an object")),n}function bi(e,t,n){if(Zr(e))return $t(e,t.consentPurposes);let{provider:r,...o}=e,i=n?.consent?.[r]??Xr[r];return $t(i(o),t.consentPurposes)}var ht=(e,t,n)=>`${e??""}|${t??""}${n?"|v":""}`,Ii=(e,t,n,r)=>e===ht(t,n,!0)||!r&&e===ht(t,n,!1),xi=e=>{if(e.context?.identity_token===void 0)return e;let{identity_token:t,...n}=e.context;return{...e,context:n}},Qr=e=>{try{return sessionStorage.getItem(e)}catch{return null}};function ki(e,t){let n=F(t?.userId),r=ut(t?.emailSha256);if(!n&&!r)return null;let o=Qr($(C("identified"),e));return Ii(o,n,r,n!==null&&ve(t?.token)!==null)?null:{...n?{userId:n}:{},...r?{email_sha256:r}:{}}}async function Ai({writeKey:e,apiHost:t},n){if(n.settings!==void 0)return{settings:Qt(n.settings),revalidated:null};let r=Ar(t,e),o=vr(e);if(o)return{settings:o,revalidated:r,fetched:r};let i=await r;return i?{settings:i,revalidated:r,fetched:r}:{settings:Zt,revalidated:null,fetched:r}}function eo(e,t){let n=t??{},r=typeof window<"u"?window:null;if(r?.[ln])return r[ln];let o=$n(e?.writeKey,()=>{let{analytics:s}=Ce(V(C("consent")));return s===!0||s===null&&n.holdAcrossPages===!0}),i=Oi(e,n,o);if(r){let s=n.extend?.getSessionId??mt(n.identityCookies?.sessionId),c=mt(n.identityCookies?.anonymousId);r[yi]=({slot:u,arm:d}={})=>In({sessionId:Be(s(),c()),slot:u,arm:d}),r[ln]=i,r[hi]=o,r[mi]?.(i)}return i}function vi(){let e=globalThis.performance?.now?.();return new Date(Date.now()-(Number.isFinite(e)?e:0)).toISOString()}function Yr(e,t){if(t===!1)return()=>{};let n={promotions:!0,productLists:!0,recommendations:!0,exposures:!0,...t},r=i=>i&&typeof i=="object"?i:{},o=[];try{n.promotions&&o.push(xt(e,r(n.promotions))),n.productLists&&o.push(It(e,r(n.productLists))),n.recommendations&&o.push(kt(e,r(n.recommendations))),n.exposures&&o.push(bt(e,r(n.exposures)))}catch(i){console.warn("[hp] autocapture not started:",i?.message??i)}return()=>{for(let i of o)i()}}var Ei=1e3;function Ci(e,t,n,r){if(!t)return De();let o=n.onsite?un():null;o?.catch(()=>{}),(r?Promise.race([r.then(s=>s??n),new Promise(s=>setTimeout(()=>s(n),Ei))]):Promise.resolve(n)).then(s=>{let c=s.enabled?s.onsite:null;if(!c)return De();let u=t===!0?{}:t;return(o??un()).then(d=>d.startOnsite(e,{...u,settings:u.settings??c}))}).catch(s=>{De(),console.warn("[hp] onsite not started:",s?.message??s)})}function pt(e){return e.close(),De(),null}async function Oi(e,t,n){try{let r=_i(e,t);if(r.length)return console.warn(`[hp] not started, the configuration is invalid: ${r.join("; ")}`),pt(n);He(t.storageNames),Fe();let{writeKey:o}=e,[{settings:i,revalidated:s,fetched:c},u]=await Promise.all([Ai(e,t),Promise.resolve(t.identity).catch(()=>null)]),d=s?i:null,f=!1,p=()=>f&&d&&Er(o,d);if(s?.then(h=>{h&&(d=h,h.enabled?p():en(o))}),!i.enabled)return t.debug&&console.info("[hp] off: the settings for this write key do not enable it"),pt(n);let g=t.propertyId??i.propertyId??null;if(!g&&i!==Zt)return console.warn("[hp] not started: this write key covers several properties, so propertyId is required"),pt(n);let{preset:A}=t,w=ki(g,u),x=t.debug===!0||i.debug?.enabled===!0||Zn(i.debug?.tokenSha256??null,C("debug")),_=F(u?.userId),k=qr({apiHost:xr(e.apiHost,i.apiHost),servingHost:oe(e.apiHost),onsite:i.onsite??null,writeKey:o,propertyId:g,pageType:Se.has(t.pageType)?t.pageType:void 0,environment:i.environment,queryParamAllowlist:i.queryParamAllowlist??void 0,plan:i.plan,sampleRate:i.sampleRate??1,holdout:i.holdouts?.[g],getCurrency:t.getCurrency,getShipToCountry:t.getShipToCountry,getLocale:t.getLocale,consent:bi(t.consent,i,A),consentCookieDomain:t.consentCookieDomain,storageNames:t.storageNames,holdAcrossPages:t.holdAcrossPages===!0,mintAnonymousId:t.mintAnonymousId,debug:x,anonymousIdSource:i.anonymousId??void 0,getAnonymousId:mt(t.identityCookies?.anonymousId),getSessionId:t.identityCookies?.sessionId?mt(t.identityCookies.sessionId):void 0,getUserId:()=>_,identityToken:u?.token,beforeSend:t.beforeSend,...t.extend,onConsentStatus(h){if(h==="granted"&&(f=!0,p()),h==="denied"){en(o);try{sessionStorage.removeItem($(C("identified"),g))}catch{}}t.extend?.onConsentStatus?.(h)},onEvent(h){if(h.type==="identify"){let y=$(C("identified"),g),O=F(h.userId),N=ut(h.traits?.email_sha256),U=!!h.context?.identity_token||Qr(y)===ht(O,N,!0);try{sessionStorage.setItem(y,ht(O,N,U))}catch{}}t.extend?.onEvent?.(xi(h))}});typeof window<"u"&&(window[wi]=()=>k.recommendationContext()),c?.then(h=>h===null&&k[gi]());for(let[h,y,O]of n.take())try{k[Wr](h,y,O)}catch(N){console.warn(`[hp] carried ${h} failed`,N)}k[Wr]("page",[t.pageType?{type:t.pageType}:{}],{messageId:ne(),timestamp:vi()});let m=Yr(k,t.autocapture),E=k.page;k.page=Ft("page",(...h)=>{let y=E(...h);return m(),m=Yr(k,t.autocapture),y});let S=typeof window<"u"?window:null;if(S?.addEventListener?.("pageshow",h=>{h.persisted&&k.page({navigation_trigger:"back_forward"})}),t.dataLayer&&S){let h=t.dataLayer.name??"dataLayer";S[h]=S[h]||[],Xn(k,{...A,dataLayer:S[h],ignore:[...A?.ignore??[],...t.dataLayer.ignore??[]],onError:y=>x&&console.warn("[hp] dataLayer mapping failed",y)})}return w&&k.identify(w,void 0,Oe),k.onsite=ge,Ci(k,t.onsite,i,s),k}catch(r){return console.warn("[hp] not started:",r?.message??r),pt(n)}}function to(e){e.initialized=!0,eo(e._config,e._options).then(t=>{let n=e.splice(0);if(!t){for(let r of e.methods??[])e[r]=()=>e;return}e.client=t;for(let[r,o]of Object.entries(t))typeof o=="function"&&(e[r]=o);for(let[r,...o]of n)try{t[r]?.(...o)}catch(i){console.warn(`[hp] queued ${r} failed`,i)}})}var B=window.hp=window.hp||[];B.servingHeaders??(B.servingHeaders=()=>({}));B.inHoldout??(B.inHoldout=()=>!0);B.personalisationGroup??(B.personalisationGroup=()=>"excluded");B.recommendationContext??(B.recommendationContext=()=>({}));B.onsite??(B.onsite=ge);B.initialized||(B._config?to(B):B.load=(e,t)=>{B._config=e,B._options=t??{},to(B)});})();
3
+ `)}`;if(n.throwOnInvalid)throw new be(z);console.error(z)}}n.debug&&console.debug("[hp]",T.event??T.type,T);let bt=li(T);return bt>cn?(x(`${T.event??T.type} not sent: ${bt} bytes, over the ${cn}-byte limit for one event`),null):(no(T,I),T)}function R(a){if((a.type==="track"||a.type==="page")&&wt(a),n.onEvent)try{n.onEvent(a)}catch(d){console.warn("[hp] onEvent observer failed",d)}}let j=()=>r&&o?.state?.personalisation===!0,we=()=>mr(M(n.getSessionId,null),n.propertyId),X=!1;function wt(a){try{if(j()){we();let d=Sr(a.event,a.properties,ut(n.propertyId,{sessionId:m()}));a.type==="track"&&ur(Wt(d)),X=!0}else $e()}catch(d){n.debug&&console.warn("[hp] the visit was not recorded",d)}}function $e(a=!1){lr(),(a||X)&&hr(),X=!1}function St(){l.forget(),g.forget(),_t.clear(),c?.forget(),$e(!0),un()}function no(a,d){!r||d||o.admits()?(R(a),_.enqueue(a)):o.hold(a)}let v=(a,d,I)=>ae({type:"track",event:a,properties:d??{}},I),_t=new Set,ro=(a,d,I)=>a==="audiences"?{audiences:d?null:I.audiences??[]}:a==="decisions"?{decisions:(I.decisions??[]).map(P=>({slot:P.slot,decision_id:P.decision_id??null,arm:P.arm??null,...P.variant&&{variant:P.variant}}))}:{recommendation_request_id:I.recommendation_request_id??null};w(A),r&&(o=nr({adapter:n.consent,timeoutMs:n.consentTimeoutMs,cookieDomain:n.consentCookieDomain,debug:n.debug,store:i&&{read:()=>u.items,write:a=>i.write(a,c?.peek()??null)},release(a){a.context&&(a.context.consent=o.stamp()),R(a),_.enqueue(a)},onStatus(a){if(a==="granted"&&(c?.persist(),l.persist(),h&&S(h),g.persist(),_.replayPersisted?.()),a==="denied"){_.clearPersisted?.(),c?.forget(),l.forget();try{sessionStorage.removeItem(k)}catch{}g.forget(),$e(!0)}try{n.onConsentStatus?.(a)}catch(d){console.warn("[hp] onConsentStatus observer failed",d)}if(a==="granted"||a==="denied")for(let d of J)try{d()}catch(I){console.warn("[hp] a consent listener failed",I)}},announce({action:a,state:d,previous:I,withdrawal:P}){d?.personalisation!==!0&&$e(I?.personalisation===!0),P&&(_.discardQueued?.(),un()),ae({type:"track",event:"Consent Updated",properties:{action:a,state:d}},void 0,P),P&&_.flush()}}),o.start(),w());let fn=()=>n.holdout?Gt(n.holdout):null,pn=()=>zt(n.holdout,F(M(n.getAnonymousId,null))).group;function oo(a,d){if(!Array.isArray(a?.decisions))return a;let I=n.holdout?.readoutSlots??[],P=F(M(n.getAnonymousId,null));return{...a,decisions:a.decisions.map(q=>{let T=q?.variant==="bandit"||q?.variant==="default"?q.variant:!d&&q?.holdout!==!0&&I.includes(q?.slot)?sr(q.slot,P):null;return T?T==="default"?{...q,variant:T,decision_id:null}:{...q,variant:T}:q})}}function mn(a,d){if(p)return null;let I=a?.exposure,P=I?.holdout===!0,q=oo(a,P);return g.remember(rr(q)),!I?.token||_t.has(I.token)?null:(_t.add(I.token),v("Personalisation Exposed",{exposure_token:I.token,surface:I.surface,holdout:P,holdout_share:I.holdout_share??fn()?.holdout_share??null,personalised_share:I.personalised_share??fn()?.personalised_share??null,...ro(I.surface,P,q)},d))}function hn(a){return y&&St(),y=null,O=null,N=null,U=null,a}return er({track:(a,d,I)=>a==="Signed Out"?hn(v(a,d,I)):v(a,d,I),page(a,d){a??(a={});let I=n.pageType??null;a.type&&(Se.has(a.type)?(I=a.type,n.pageType=a.type):n.debug&&console.warn(`[hp] ignoring unknown page.type "${a.type}". Allowed: ${[...Se].join(", ")}`));let P=ae({type:"page",properties:{name:a.name??null,navigation_trigger:a.navigation_trigger??En(),previous_message_id:E()}},{page:{type:I},...lt(d)??{}});return P&&S(P.messageId),P},identify(a,d,I){let{userId:P,...q}=a&&typeof a=="object"?a:{},T=ve(lt(d)?.identity_token);if(P!==void 0){let z=F(P);U=z?z===y?T??U:T:null,I===Oe?N=z:O&&z&&z!==O?St():n.debug&&N&&z&&z!==N&&console.warn("[hp] identify names another userId than the identity option; using the new one"),y=z,z&&I!==Oe&&(O=z)}else T&&y&&(U=T);let{identity_token:bt,...Q}=lt(d)??{};return ae({type:"identify",traits:ai(q,n.debug)},U?{...Q,identity_token:U}:Q)},reset(){y&&St(),y=null,O=null,N=null,U=null,S("")},productViewed:(a,d)=>v("Product Viewed",a,d),productListViewed:(a,d)=>v("Product List Viewed",a,d),recommendationsViewed:(a,d)=>v("Recommendations Viewed",a,d),personalisationExposed:(a,d)=>v("Personalisation Exposed",a,d),recordExposure:mn,surfaceViewed({surface:a}={},d){if(!Xs.has(a)||!n.holdout||a!=="decisions"&&!j())return null;let I=F(M(n.getAnonymousId,null)),P=zt(n.holdout,I).group;if(P==="excluded")return null;let q=kn({sessionId:Be(M(n.getSessionId,null),I),surface:a});return q?mn({exposure:{token:q,surface:a,holdout:P==="holdout"}},d):null},inHoldout:()=>pn()!=="personalised",personalisationGroup:pn,productClicked:(a,d)=>v("Product Clicked",a,d),productListFiltered:(a,d)=>v("Product List Filtered",a,d),productsSearched:(a,d)=>v("Products Searched",a,d),searchSuggestionsViewed:(a,d)=>v("Search Suggestions Viewed",a,d),productAdded:(a,d)=>v("Product Added",a,d),productRemoved:(a,d)=>v("Product Removed",a,d),cartUpdated:(a,d)=>v("Cart Updated",ti(a),d),identityLinked:(a,d)=>v("Identity Linked",a,d),slotEngaged:(a,d)=>p?null:v("Slot Engaged",a,d),productVariantSelected:(a,d)=>v("Product Variant Selected",a,d),cartViewed:(a,d)=>v("Cart Viewed",a,d),productAddedToWishlist:(a,d)=>v("Product Added to Wishlist",a,d),productRemovedFromWishlist:(a,d)=>v("Product Removed from Wishlist",a,d),wishlistProductAddedToCart:(a,d)=>v("Wishlist Product Added to Cart",a,d),productShared:(a,d)=>v("Product Shared",a,d),cartShared:(a,d)=>v("Cart Shared",a,d),couponEntered:(a,d)=>v("Coupon Entered",a,d),couponApplied:(a,d)=>v("Coupon Applied",a,d),couponDenied:(a,d)=>v("Coupon Denied",a,d),couponRemoved:(a,d)=>v("Coupon Removed",a,d),checkoutStarted:(a,d)=>v("Checkout Started",a,d),promotionViewed:(a,d)=>v("Promotion Viewed",a,d),promotionClicked:(a,d)=>v("Promotion Clicked",a,d),checkoutStepViewed:(a,d)=>v("Checkout Step Viewed",a,d),checkoutStepCompleted:(a,d)=>v("Checkout Step Completed",a,d),paymentInfoEntered:(a,d)=>v("Payment Info Entered",a,d),checkoutFailed:(a,d)=>v("Checkout Failed",a,d),signedIn:(a,d)=>v("Signed In",a,d),signedUp:(a,d)=>v("Signed Up",a,d),signedOut:a=>hn(v("Signed Out",{},a)),newsletterSubscribed:(a,d)=>v("Newsletter Subscribed",a,d),newsletterUnsubscribed:(a,d)=>v("Newsletter Unsubscribed",a,d),preferencesStated:(a,d)=>v("Preferences Stated",a,d),backInStockSubscribed:(a,d)=>v("Back In Stock Subscribed",a,d),productReviewed:(a,d)=>v("Product Reviewed",a,d),consentUpdated:(a,d)=>v("Consent Updated",a,d),flush:a=>_.flush(a),recommendationContext(){if(!j())return{};try{return we(),Wt(et())}catch{return{}}},get consent(){return o?o.state:null},servingHeaders:()=>Bt(o?.state??null),get lastPageMessageId(){return E()},get anonymousId(){return F(M(n.getAnonymousId,null))},[ei](){return{writeKey:n.writeKey,storageKey:$(C("onsite"),n.propertyId),gatewayHost:n.apiHost,servingHost:n.servingHost??n.apiHost,settings:n.onsite??null,debug:n.debug===!0,preview:p,anonymousId:()=>F(M(n.getAnonymousId,null)),sessionId:()=>F(M(n.getSessionId,null)),identityToken:()=>j()?U:null,analytics:s,personalisation:j,consent:()=>n.getConsent(),headers:()=>Bt(o?.state??null),pageUrl:()=>typeof location>"u"?null:Lt(location.href,n),locale:()=>Nt(M(n.getLocale,n.locale)),campaign:()=>p?A:ut(n.propertyId,{sessionId:m()}),basketValue:()=>{let a=et().basketValue;return K??(Number.isFinite(a)?a:null)},sessionSignals:()=>j()?(we(),{...et(),campaign:ut(n.propertyId,{sessionId:m()})}):null,onBasket:a=>(ie.add(a),()=>ie.delete(a)),consentAnswered:()=>!o||o.status==="granted"||o.status==="denied",onConsentAnswered:a=>(J.add(a),()=>J.delete(a))}},[Qs](){_.markFailing?.()},[Zs](a,d,I){if(typeof this[a]=="function"){G=typeof I?.messageId=="string"&&typeof I?.timestamp=="string"?{messageId:I.messageId,timestamp:I.timestamp}:null;try{this[a](...Array.isArray(d)?d:[])}finally{G=null}}}})}var Re=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),Y=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),Me=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),ft=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),fi=["shown","submitted","apply","closed","held"],Kr=10,he=()=>typeof window>"u"?null:window;function De(){try{for(let{resolve:e}of he()?.[Y]?.splice(0)??[])e(!1)}catch{}}var ge=Object.freeze({open(e){try{let t=he();if(!t||typeof e!="string")return Promise.resolve(!1);if(t[Re])return t[Re].open(e);if(t[Y]??(t[Y]=[]),t[Y].length<Kr)return new Promise(n=>t[Y].push({slot:e,resolve:n}))}catch{}return Promise.resolve(!1)},show(e){return ge.open(e)},on(e,t){var n;try{let r=he();return!r||!fi.includes(e)||typeof t!="function"?()=>{}:(r[Me]??(r[Me]={}),((n=r[Me])[e]??(n[e]=new Set)).add(t),()=>r[Me][e].delete(t))}catch{return()=>{}}},suppress(e="page"){try{let t=he();if(!t)return;(t[ft]??(t[ft]=new Set)).add(String(e)),t[Re]?.suppress()}catch{}},unsuppress(e){try{let t=he()?.[ft];e===void 0?t?.clear():t?.delete(String(e))}catch{}},ready(){try{let e=he();if(!e)return Promise.resolve([]);if(e[Re])return Promise.resolve(ge.debug());if(e[Y]??(e[Y]=[]),e[Y].length<Kr)return new Promise(t=>e[Y].push({slot:null,resolve:()=>t(ge.debug())}))}catch{}return Promise.resolve([])},debug(){try{return he()?.[Re]?.debug()??[]}catch{return[]}}});function Gr(e){let t=typeof document>"u"?null:document.currentScript?.src;return t?new URL(e,t).href:null}var pt=new Map;function zr(e,t){return window[t]?Promise.resolve(window[t]):e?(pt.has(t)||pt.set(t,new Promise((n,r)=>{let o=document.createElement("script");o.src=e,o.async=!0,o.onload=()=>window[t]?n(window[t]):r(new Error(`${e} did not register`)),o.onerror=()=>r(new Error(`${e} did not load`)),document.head.append(o)}).finally(()=>pt.delete(t))),pt.get(t)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var pi=Gr("onsite.min.js"),ln=()=>zr(pi,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module"));var dn=Symbol.for("@thg-agentic/hyper-personalisation-web.bootstrap"),mi=Symbol.for("@thg-agentic/hyper-personalisation-web.drain"),hi=Symbol.for("@thg-agentic/hyper-personalisation-web.carry"),Wr=Symbol.for("@thg-agentic/hyper-personalisation-web.replay"),gi=Symbol.for("@thg-agentic/hyper-personalisation-web.unreachable"),yi=Symbol.for("@thg-agentic/hyper-personalisation-web.assignment"),wi=Symbol.for("@thg-agentic/hyper-personalisation-web.recommendation-context"),gt=e=>e?()=>V(e):()=>null,Xr={didomi:e=>qn({purposes:e.purposes}),onetrust:e=>Kn({groups:e.groups,impliedConsent:e.impliedConsent}),cookie:e=>Gn({name:e.name,categories:e.categories,refusedValue:e.refusedValue,source:e.source,changeEvent:e.changeEvent}),forwarded:e=>zn({name:e.name}),static:e=>{if(!e.state||typeof e.state!="object")throw new Error('consent.state is required for provider "static"');return Wn(e.state)}},Jr=Object.keys(Xr),ye=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),mt=e=>typeof e=="string"&&e!=="",Si=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"),Zr=e=>ye(e)&&typeof e.read=="function";function _i(e,t={}){let n=[];if(!ye(e))return["config must be { writeKey, apiHost? }"];mt(e.writeKey)||n.push("writeKey is required"),oe(e.apiHost)||n.push("apiHost, when given, must be a host or an http(s) origin"),t.propertyId!==void 0&&!mt(t.propertyId)&&n.push("propertyId must be a string");let{consent:r}=t;if(!Zr(r)&&!(ye(r)&&Jr.includes(r.provider))&&n.push(`consent must be a consent adapter or { provider: ${Jr.join(" | ")} }`),t.autocapture!==void 0&&t.autocapture!==!1&&!ye(t.autocapture)&&n.push("autocapture must be false or { promotions, productLists, recommendations }"),t.onsite!==void 0&&typeof t.onsite!="boolean"&&!ye(t.onsite)&&n.push("onsite must be true, false or the onsite options"),t.beforeSend!==void 0&&typeof t.beforeSend!="function"&&n.push("beforeSend must be a function"),t.identityCookies!==void 0)if(!ye(t.identityCookies))n.push("identityCookies must be an object");else for(let o of["anonymousId","sessionId"]){let s=t.identityCookies[o];s!==void 0&&!mt(s)&&n.push(`identityCookies.${o} must be a cookie name`)}for(let o of["getCurrency","getShipToCountry","getLocale"])t[o]!==void 0&&typeof t[o]!="function"&&n.push(`${o} must be a function`);return t.dataLayer!==void 0&&(ye(t.dataLayer)?(t.dataLayer.name!==void 0&&!mt(t.dataLayer.name)&&n.push("dataLayer.name must be a string"),t.dataLayer.ignore!==void 0&&!Si(t.dataLayer.ignore)&&n.push("dataLayer.ignore must be an array of strings")):n.push("dataLayer must be an object")),n}function bi(e,t,n){if(Zr(e))return jt(e,t.consentPurposes);let{provider:r,...o}=e,s=n?.consent?.[r]??Xr[r];return jt(s(o),t.consentPurposes)}var yt=(e,t,n)=>`${e??""}|${t??""}${n?"|v":""}`,Ii=(e,t,n,r)=>e===yt(t,n,!0)||!r&&e===yt(t,n,!1),xi=e=>{if(e.context?.identity_token===void 0)return e;let{identity_token:t,...n}=e.context;return{...e,context:n}},Qr=e=>{try{return sessionStorage.getItem(e)}catch{return null}};function ki(e,t){let n=F(t?.userId),r=dt(t?.emailSha256);if(!n&&!r)return null;let o=Qr($(C("identified"),e));return Ii(o,n,r,n!==null&&ve(t?.token)!==null)?null:{...n?{userId:n}:{},...r?{email_sha256:r}:{}}}async function Ai({writeKey:e,apiHost:t},n){if(n.settings!==void 0)return{settings:en(n.settings),revalidated:null};let r=vr(t,e),o=Er(e);if(o)return{settings:o,revalidated:r,fetched:r};let s=await r;return s?{settings:s,revalidated:r,fetched:r}:{settings:Qt,revalidated:null,fetched:r}}function eo(e,t){let n=t??{},r=typeof window<"u"?window:null;if(r?.[dn])return r[dn];let o=Bn(e?.writeKey,()=>{let{analytics:i}=Ce(V(C("consent")));return i===!0||i===null&&n.holdAcrossPages===!0}),s=Oi(e,n,o);if(r){let i=n.extend?.getSessionId??gt(n.identityCookies?.sessionId),u=gt(n.identityCookies?.anonymousId);r[yi]=({slot:c,arm:l}={})=>xn({sessionId:Be(i(),u()),slot:c,arm:l}),r[dn]=s,r[hi]=o,r[mi]?.(s)}return s}function vi(){let e=globalThis.performance?.now?.();return new Date(Date.now()-(Number.isFinite(e)?e:0)).toISOString()}function Yr(e,t){if(t===!1)return()=>{};let n={promotions:!0,productLists:!0,recommendations:!0,exposures:!0,...t},r=s=>s&&typeof s=="object"?s:{},o=[];try{n.promotions&&o.push(At(e,r(n.promotions))),n.productLists&&o.push(kt(e,r(n.productLists))),n.recommendations&&o.push(vt(e,r(n.recommendations))),n.exposures&&o.push(xt(e,r(n.exposures)))}catch(s){console.warn("[hp] autocapture not started:",s?.message??s)}return()=>{for(let s of o)s()}}var Ei=1e3;function Ci(e,t,n,r){if(!t)return De();let o=n.onsite?ln():null;o?.catch(()=>{}),(r?Promise.race([r.then(i=>i??n),new Promise(i=>setTimeout(()=>i(n),Ei))]):Promise.resolve(n)).then(i=>{let u=i.enabled?i.onsite:null;if(!u)return De();let c=t===!0?{}:t;return(o??ln()).then(l=>l.startOnsite(e,{...c,settings:c.settings??u}))}).catch(i=>{De(),console.warn("[hp] onsite not started:",i?.message??i)})}function ht(e){return e.close(),De(),null}async function Oi(e,t,n){try{let r=_i(e,t);if(r.length)return console.warn(`[hp] not started, the configuration is invalid: ${r.join("; ")}`),ht(n);He(t.storageNames),Fe();let{writeKey:o}=e,[{settings:s,revalidated:i,fetched:u},c]=await Promise.all([Ai(e,t),Promise.resolve(t.identity).catch(()=>null)]),l=i?s:null,f=!1,p=()=>f&&l&&Cr(o,l);if(i?.then(g=>{g&&(l=g,g.enabled?p():tn(o))}),!s.enabled)return t.debug&&console.info("[hp] off: the settings for this write key do not enable it"),ht(n);let m=t.propertyId??s.propertyId??null;if(!m&&s!==Qt)return console.warn("[hp] not started: this write key covers several properties, so propertyId is required"),ht(n);let{preset:A}=t,w=ki(m,c),x=t.debug===!0||s.debug?.enabled===!0||Qn(s.debug?.tokenSha256??null,C("debug")),_=F(c?.userId),k=qr({apiHost:kr(e.apiHost,s.apiHost),servingHost:oe(e.apiHost),onsite:s.onsite??null,writeKey:o,propertyId:m,pageType:Se.has(t.pageType)?t.pageType:void 0,environment:s.environment,queryParamAllowlist:s.queryParamAllowlist??void 0,plan:s.plan,sampleRate:s.sampleRate??1,holdout:s.holdouts?.[m],getCurrency:t.getCurrency,getShipToCountry:t.getShipToCountry,getLocale:t.getLocale,consent:bi(t.consent,s,A),consentCookieDomain:t.consentCookieDomain,storageNames:t.storageNames,holdAcrossPages:t.holdAcrossPages===!0,mintAnonymousId:t.mintAnonymousId,debug:x,anonymousIdSource:s.anonymousId??void 0,getAnonymousId:gt(t.identityCookies?.anonymousId),getSessionId:t.identityCookies?.sessionId?gt(t.identityCookies.sessionId):void 0,getUserId:()=>_,identityToken:c?.token,beforeSend:t.beforeSend,...t.extend,onConsentStatus(g){if(g==="granted"&&(f=!0,p()),g==="denied"){tn(o);try{sessionStorage.removeItem($(C("identified"),m))}catch{}}t.extend?.onConsentStatus?.(g)},onEvent(g){if(g.type==="identify"){let y=$(C("identified"),m),O=F(g.userId),N=dt(g.traits?.email_sha256),U=!!g.context?.identity_token||Qr(y)===yt(O,N,!0);try{sessionStorage.setItem(y,yt(O,N,U))}catch{}}t.extend?.onEvent?.(xi(g))}});typeof window<"u"&&(window[wi]=()=>k.recommendationContext()),u?.then(g=>g===null&&k[gi]());for(let[g,y,O]of n.take())try{k[Wr](g,y,O)}catch(N){console.warn(`[hp] carried ${g} failed`,N)}k[Wr]("page",[t.pageType?{type:t.pageType}:{}],{messageId:ne(),timestamp:vi()});let h=Yr(k,t.autocapture),E=k.page;k.page=Kt("page",(...g)=>{let y=E(...g);return h(),h=Yr(k,t.autocapture),y});let S=typeof window<"u"?window:null;if(S?.addEventListener?.("pageshow",g=>{g.persisted&&k.page({navigation_trigger:"back_forward"})}),t.dataLayer&&S){let g=t.dataLayer.name??"dataLayer";S[g]=S[g]||[],Zn(k,{...A,dataLayer:S[g],ignore:[...A?.ignore??[],...t.dataLayer.ignore??[]],onError:y=>x&&console.warn("[hp] dataLayer mapping failed",y)})}return w&&k.identify(w,void 0,Oe),k.onsite=ge,Ci(k,t.onsite,s,i),k}catch(r){return console.warn("[hp] not started:",r?.message??r),ht(n)}}function to(e){e.initialized=!0,eo(e._config,e._options).then(t=>{let n=e.splice(0);if(!t){for(let r of e.methods??[])e[r]=()=>e;return}e.client=t;for(let[r,o]of Object.entries(t))typeof o=="function"&&(e[r]=o);for(let[r,...o]of n)try{t[r]?.(...o)}catch(s){console.warn(`[hp] queued ${r} failed`,s)}})}var B=window.hp=window.hp||[];B.servingHeaders??(B.servingHeaders=()=>({}));B.inHoldout??(B.inHoldout=()=>!0);B.personalisationGroup??(B.personalisationGroup=()=>"excluded");B.recommendationContext??(B.recommendationContext=()=>({}));B.onsite??(B.onsite=ge);B.initialized||(B._config?to(B):B.load=(e,t)=>{B._config=e,B._options=t??{},to(B)});})();
@@ -1 +1 @@
1
- (()=>{function p(e){return e.trim().toLowerCase().replace(/\s*\/\s*/g,"/").replace(/^\/+|\/+$/g,"")}var w={gte:(e,t)=>e>=t,greater_than_or_equal:(e,t)=>e>=t,">=":(e,t)=>e>=t,lte:(e,t)=>e<=t,less_than_or_equal:(e,t)=>e<=t,"<=":(e,t)=>e<=t,eq:(e,t)=>e===t,equals:(e,t)=>e===t,"=":(e,t)=>e===t},B=new Set([...Object.keys(w),"between"]);function l(e,t){let r=p(t);return r?e.filter(s=>s===r||s.startsWith(`${r}/`)).length:0}function g(e,t){return e.length===0?0:l(e,t)/e.length}var b={categoryViews:(e,t)=>l(e.recentCategories,t),categoryShare:(e,t)=>g(e.recentCategories,t),browseViews:(e,t)=>l(e.recentBrowse,t),browseShare:(e,t)=>g(e.recentBrowse,t)};function x(e,t){let r=e.indexOf(".");if(r>0){let o=b[e.slice(0,r)],i=e.slice(r+1);return o&&i?o(t,i):null}let s=t[e];return typeof s=="number"?s:null}function h(e,t){let r=x(e.field,t);if(r===null)return!1;if(e.operator==="between")return typeof e.value=="number"&&typeof e.value2=="number"&&r>=e.value&&r<=e.value2;let s=w[e.operator];return!s||typeof e.value!="number"?!1:s(r,e.value)}function d(e,t){let r=e.rules??[];if(r.length===0)return!1;let s=new Map;for(let u of r){let n=u.group??0,c=s.get(n);c?c.push(u):s.set(n,[u])}let o=e.groupOperators??[],i=[];for(let[u,n]of s)i.push(o[u]==="OR"?n.some(c=>h(c,t)):n.every(c=>h(c,t)));return e.groupJoin==="OR"?i.some(Boolean):i.every(Boolean)}function m(e,t){if(!Array.isArray(t))return e;let r=new Set(t),s=e.recentBrowseCategories??[],o=(e.recentBrowse??[]).filter((u,n)=>r.has(s[n])),i=Object.entries(e.listViewsByCategory??{}).reduce((u,[n,c])=>r.has(n)?u+c:u,0);return{...e,recentBrowse:o,listViews:i}}var v=100,A=128,y=e=>typeof e=="string"&&e!==""&&e.length<=A,a=new WeakMap;function f(e){if(!a.has(e)){let t=e.datafile().then(r=>r.status===200?r.body:null).catch(()=>null);a.set(e,t),t.then(r=>{!r&&a.get(e)===t&&a.delete(e)})}return a.get(e)}async function S(e,t,r=[],s=[]){let o=await f(e),i=t?.(),u=Array.isArray(o?.session_audiences)?o.session_audiences:[],n=o&&i?O(o,i):[];return _([...n,...s],r,u)}function _(e,t,r){let s=new Map(r.map(n=>[n?.slug,Array.isArray(n?.requires)?n.requires:[]])),o=new Set,i=n=>{if(!o.has(n)){o.add(n);for(let c of s.get(n)??[])i(c)}};for(let n of t)i(n);let u=[...new Set(e.filter(y))];return[...u.filter(n=>o.has(n)),...u.filter(n=>!o.has(n))].slice(0,v)}function O(e,t){let r=Array.isArray(e?.session_audiences)?e.session_audiences:[],s=m(t,e.browse_categories??null);return r.filter(o=>y(o?.slug)&&d(o,s)).map(o=>o.slug)}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences")]={prefetch:f,visitAudiences:S};})();
1
+ (()=>{var y=["source","medium","campaign","content","term"];var h=e=>String(e).trim().toLowerCase();function f(e,t,n){let s=h(e),r=h(n);return t==="is"?s===r:t==="contains"&&r!==""&&s.includes(r)}function d(e){return e.trim().toLowerCase().replace(/\s*\/\s*/g,"/").replace(/^\/+|\/+$/g,"")}var A={gte:(e,t)=>e>=t,greater_than_or_equal:(e,t)=>e>=t,">=":(e,t)=>e>=t,lte:(e,t)=>e<=t,less_than_or_equal:(e,t)=>e<=t,"<=":(e,t)=>e<=t,eq:(e,t)=>e===t,equals:(e,t)=>e===t,"=":(e,t)=>e===t},p=e=>typeof e=="string",u=(e,t)=>p(t)&&f(e,"is",t),x={eq:u,equals:u,"=":u,neq:(e,t)=>p(t)&&!u(e,t),in:(e,t)=>Array.isArray(t)&&t.some(n=>u(e,n)),contains:(e,t)=>p(t)&&f(e,"contains",t)},D=new Set([...Object.keys(A),...Object.keys(x),"between"]);function g(e,t){let n=d(t);return n?e.filter(s=>s===n||s.startsWith(`${n}/`)).length:0}function S(e,t){return e.length===0?0:g(e,t)/e.length}var M={categoryViews:(e,t)=>g(e.recentCategories,t),categoryShare:(e,t)=>S(e.recentCategories,t),browseViews:(e,t)=>g(e.recentBrowse,t),browseShare:(e,t)=>S(e.recentBrowse,t)};function q(e,t){let n=e.indexOf(".");if(n>0){let r=e.slice(0,n),c=e.slice(n+1);if(r==="campaign"){let o=y.includes(c)?t.campaign?.[c]:null;return typeof o=="string"?o:null}let i=M[r];return i&&c?i(t,c):null}let s=t[e];return typeof s=="number"?s:null}function w(e,t){let n=q(e.field,t);if(n===null)return!1;if(typeof n=="string"){let r=x[e.operator];return r?r(n,e.value):!1}if(e.operator==="between")return typeof e.value=="number"&&typeof e.value2=="number"&&n>=e.value&&n<=e.value2;let s=A[e.operator];return!s||typeof e.value!="number"?!1:s(n,e.value)}function v(e,t){let n=e.rules??[];if(n.length===0)return!1;let s=new Map;for(let i of n){let o=i.group??0,a=s.get(o);a?a.push(i):s.set(o,[i])}let r=e.groupOperators??[],c=[];for(let[i,o]of s)c.push(r[i]==="OR"?o.some(a=>w(a,t)):o.every(a=>w(a,t)));return e.groupJoin==="OR"?c.some(Boolean):c.every(Boolean)}function O(e,t){if(!Array.isArray(t))return e;let n=new Set(t),s=e.recentBrowseCategories??[],r=(e.recentBrowse??[]).filter((i,o)=>n.has(s[o])),c=Object.entries(e.listViewsByCategory??{}).reduce((i,[o,a])=>n.has(o)?i+a:i,0);return{...e,recentBrowse:r,listViews:c}}var R=100,C=128,_=e=>typeof e=="string"&&e!==""&&e.length<=C,l=new WeakMap;function m(e){if(!l.has(e)){let t=e.datafile().then(n=>n.status===200?n.body:null).catch(()=>null);l.set(e,t),t.then(n=>{!n&&l.get(e)===t&&l.delete(e)})}return l.get(e)}async function b(e,t,n=[],s=[]){let r=await m(e),c=t?.(),i=Array.isArray(r?.session_audiences)?r.session_audiences:[],o=r&&c?I(r,c):[];return E([...o,...s],n,i)}function E(e,t,n){let s=new Map(n.map(o=>[o?.slug,Array.isArray(o?.requires)?o.requires:[]])),r=new Set,c=o=>{if(!r.has(o)){r.add(o);for(let a of s.get(o)??[])c(a)}};for(let o of t)c(o);let i=[...new Set(e.filter(_))];return[...i.filter(o=>r.has(o)),...i.filter(o=>!r.has(o))].slice(0,R)}function I(e,t){let n=Array.isArray(e?.session_audiences)?e.session_audiences:[],s=O(t,e.browse_categories??null);return n.filter(r=>_(r?.slug)&&v(r,s)).map(r=>r.slug)}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences")]={prefetch:m,visitAudiences:b};})();
@@ -1 +1 @@
1
- (()=>{function T(e){let s=typeof document>"u"?null:document.currentScript?.src;return s?new URL(e,s).href:null}var H=new Map;function I(e,s){return window[s]?Promise.resolve(window[s]):e?(H.has(s)||H.set(s,new Promise((n,r)=>{let d=document.createElement("script");d.src=e,d.async=!0,d.onload=()=>window[s]?n(window[s]):r(new Error(`${e} did not register`)),d.onerror=()=>r(new Error(`${e} did not load`)),document.head.append(d)}).finally(()=>H.delete(s))),H.get(s)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var Ke=T("onsite-answers.min.js"),ae=()=>I(Ke,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.answers"));var Ye="/v1/capture/challenge",He=e=>typeof e=="string"&&/^\/v1\/[\w/-]+$/.test(e)?e:Ye;function ce(e,s={}){let n=s.fetch??globalThis.fetch?.bind(globalThis),r=s.servingHost??e.servingHost,d=s.gatewayHost??e.gatewayHost;async function o(a,{method:p="GET",body:i,consent:l=!1,timeoutMs:c}={}){if(!n)return{status:0,body:null};try{let w=await n(a,{method:p,credentials:"omit",signal:c&&AbortSignal.timeout?.(c),headers:{accept:"application/json",authorization:`Bearer ${e.writeKey}`,...i?{"content-type":"application/json"}:{},...l?e.headers():{}},...i?{body:JSON.stringify(i)}:{}}),b=null;try{b=await w.json()}catch{}return{status:w.status,body:b}}catch{return{status:0,body:null}}}return{decide:(a,p,{visitAudiences:i,visitCampaign:l}={})=>o(`${r}/v1/decisions`,{method:"POST",consent:!0,body:{slots:[p?{key:a,pin:{experiment:p[0],arm:p[1],split:p[2]}}:a],identifier_value:e.anonymousId()??void 0,session_id:e.sessionId()??void 0,identity_token:e.identityToken?.()??void 0,...e.preview?{preview:e.preview}:{},...i?{visit_audiences:i}:{},...l?{visit_campaign:l}:{}}}),datafile:()=>o(`${r}/v1/audiences/datafile`,{timeoutMs:1500}),challenge:()=>o(`${d}${He(s.challenge)}`),capture:a=>o(`${d}/v1/capture`,{method:"POST",body:a}),answers:a=>o(`${d}/v1/capture/answers`,{method:"POST",body:a}),claim:a=>o(`${r}/v1/offers/claim`,{method:"POST",consent:!0,body:a,timeoutMs:8e3})}}var Xe=T("onsite-audiences.min.js"),ue=()=>I(Xe,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences"));function de(e,s){let n={},r=()=>{try{let o=JSON.parse(e().getItem(s));o&&typeof o=="object"&&(n=o)}catch{}return n};return{read:r,write:o=>{let a=r();o(a),n=a;try{e().setItem(s,JSON.stringify(a))}catch{}}}}function pe(e,s=()=>!0){let n=de(()=>sessionStorage,e),r=de(()=>localStorage,e),d=()=>s()?r:n,o=()=>{let i=r.read();(i.sub!==void 0||i.k!==void 0)&&r.write(l=>{delete l.sub,delete l.k})},a=()=>s()?[n.read(),r.read()]:(o(),[n.read()]),p=(i,l)=>{var c;return i.f??(i.f={}),(c=i.f)[l]??(c[l]={}),i.f[l]};return{seen(i){let l=r.read().f?.[i]??{};return{session:n.read().f?.[i]?.n??0,lifetime:l.n??0,closedAt:l.c??null,submitted:l.s===1}},subscribed:()=>a().some(i=>i.sub===1),shown(i){n.write(l=>{let c=p(l,i);c.n=(c.n??0)+1}),r.write(l=>{let c=p(l,i);c.n=(c.n??0)+1})},closed(i,l=Date.now()){r.write(c=>{p(c,i).c=l})},tab(i,l){n.write(c=>{let w=p(c,i);l?w.t=1:delete w.t})},tabOut:i=>n.read().f?.[i]?.t===1,pin(i,l){if(l===void 0)return n.read().f?.[i]?.p??null;n.write(c=>{p(c,i).p=l})},coveredAt:()=>n.read().o??null,covered(i=Date.now()){n.write(l=>{l.o=i})},code(i,l=Date.now()){if(i===void 0){let[c]=a().flatMap(w=>w.k?[w.k]:[]).sort((w,b)=>b.at-w.at);return c&&l-c.at<14*864e5?c.c:null}return d().write(c=>{c.k={c:i,at:l}}),i},submitted(i){r.write(l=>{p(l,i).s=1}),d().write(l=>{l.sub=1})}}}var ze=T("onsite-render.min.js"),fe=()=>I(ze,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render"));var Ve=["source","medium","campaign","content","term"];var he=e=>String(e).trim().toLowerCase();function ge(e,s){return(Array.isArray(e)?e:[]).every(n=>{let r=s?.[n?.field];if(!Ve.includes(n?.field)||typeof r!="string")return!1;let d=he(r);return[].concat(n.values??[]).some(o=>{let a=he(o);return n.match==="is"?d===a:n.match==="contains"&&a!==""&&d.includes(a)})})}var be=["popup","sheet","bar","teaser","inline","fullscreen"],Ge=["entry","exit","scroll","time","idle","inline","manual"],Z=e=>e!=="inline",Se=e=>e==="popup"||e==="sheet"||e==="fullscreen",S=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),k=e=>Array.isArray(e)?e.filter(s=>typeof s=="string"):[],me=e=>Number.isInteger(e)&&e>=0?e:null,Be={field:null,match:null,values:[]},qe=e=>e==null?[]:Array.isArray(e)&&e.every(S)?e:[Be];function _e(e){if(!S(e)||typeof e.slot!="string"||e.slot==="")return null;let s=S(e.trigger)?e.trigger:{};if(!be.includes(e.format)||!Ge.includes(s.type))return null;let n=S(e.caps)?e.caps:{};return{...e,trigger:s,priority:Number.isFinite(e.priority)?e.priority:0,pages:S(e.pages)?e.pages:{},devices:k(e.devices),aliases:k(e.aliases),audiences:k(e.audiences),arrived_from:qe(e.arrived_from),caps:{per_session:me(n.per_session),lifetime:me(n.lifetime),after_close_days:Number.isFinite(n.after_close_days)?n.after_close_days:null},window:S(e.window)?e.window:{},questions:Array.isArray(e.questions)?e.questions.filter(S):[],prizes:Array.isArray(e.prizes)?e.prizes.filter(S):[]}}var Je=/^[a-z][a-z0-9_-]{0,31}$/;function Ae(e){if(!S(e)||e.v!==1||!Array.isArray(e.steps))return null;let s=e.steps.filter(n=>S(n)&&Je.test(n.id)&&Array.isArray(n.blocks));return s.length===0?null:{format:be.includes(e.format)?e.format:null,theme:S(e.theme)?e.theme:{},steps:s}}function we(e,s){let n=String(e).split("*").map(r=>r.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${n}$`,"i").test(s)}function Ze(e,s){let n=k(e?.include);return(!n.length||n.some(r=>we(r,s)))&&!k(e?.exclude).some(r=>we(r,s))}function ve(e){return e.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches===!0||e.innerWidth<768?"mobile":"desktop"}var ye=e=>typeof e=="string"?Date.parse(e):Number.NaN,F=e=>e.trigger.type==="manual";function Q(e,s){let n=[];Ze(e.pages,s.path)||n.push("page not included"),e.devices.length&&!e.devices.includes(s.device)&&n.push(`not on ${s.device}`),ge(e.arrived_from,s.campaign)||n.push("not from its campaign");let r=ye(e.window.starts_at),d=ye(e.window.ends_at);if((s.now<r||s.now>=d)&&n.push("outside its dates"),e.audiences.length&&!s.preview&&(s.personalisation?s.audiences&&!e.audiences.some(p=>s.audiences.includes(p))&&n.push("not in its audiences"):n.push("audiences need personalisation consent")),s.preview||s.asked||F(e))return n;let{seen:o}=s,{caps:a}=e;return o.submitted&&n.push("already submitted"),e.exclude_subscribed===!0&&s.subscribed&&n.push("already subscribed"),a.per_session!==null&&o.session>=a.per_session&&n.push("per_session cap"),a.lifetime!==null&&o.lifetime>=a.lifetime&&n.push("lifetime cap"),a.after_close_days!==null&&o.closedAt&&s.now-o.closedAt<a.after_close_days*864e5&&n.push("closed recently"),n}var Ee=(e,s)=>s.priority-e.priority;var Qe=["mousemove","pointerdown","keydown","scroll","touchstart","wheel"];function et(){let e=[];return{on:(r,d,o,a={passive:!0})=>{r.addEventListener(d,o,a),e.push(()=>r.removeEventListener(d,o,a))},later:(r,d)=>{let o=setTimeout(r,d);e.push(()=>clearTimeout(o))},stop:()=>{for(let r of e.splice(0))r()}}}var xe=(e,s)=>{let n=s.documentElement.scrollHeight||0;return n>0?(e.scrollY+e.innerHeight)/n:0},tt=e=>{let s=e.activeElement;return!!(s&&(/^(INPUT|TEXTAREA|SELECT)$/.test(s.tagName)||s.isContentEditable))};function nt({on:e,later:s},n,r,d,o){let a=!1,p=!1,i=null,l=0;s(()=>{a=!0},r.delay_ms??5e3),e(o,"mousemove",c=>{c.clientY>d.innerHeight*.1&&(p=!0),i!==null&&(l=c.clientY-i),i=c.clientY}),e(o,"mouseout",c=>{a&&p&&!c.relatedTarget&&c.clientY<=0&&l<0&&!tt(o)&&n("exit")})}function st({on:e,later:s},n,r,d,o){let a=!1,p=0,i=d.scrollY,l=Date.now(),c=null,w=null;s(()=>{a=!0},r.delay_ms??5e3),e(d,"scroll",()=>{let b=d.scrollY,_=Date.now();if(p=Math.max(p,xe(d,o)),b<i){(!c||_-c.t>300)&&(c={y:i,t:l});let A=c.y-b;a&&p>=.3&&A>=120&&A/Math.max(1,_-c.t)>=.5&&n("exit_scroll")}else c=null;i=b,l=_}),e(o,"visibilitychange",()=>{o.visibilityState==="hidden"?w=Date.now():w!==null&&Date.now()-w>=1e4&&n("return"),o.visibilityState!=="hidden"&&(w=null)})}function Te(e,s,{device:n,win:r=window,doc:d=document}){let o=et(),a=(e.seconds??30)*1e3;if(e.type==="entry"&&o.later(()=>s("entry"),e.delay_ms??0),e.type==="time"&&o.later(()=>s("time"),a),e.type==="exit"&&(n==="mobile"?st:nt)(o,s,e,r,d),e.type==="scroll"){let p=e.depth??.5;o.on(r,"scroll",()=>xe(r,d)>=p&&s("scroll"))}if(e.type==="idle"){let p=null,i=()=>{clearTimeout(p),p=setTimeout(()=>s("idle"),a)};i();for(let l of Qe)o.on(l==="scroll"?r:d,l,i);return o.on(d,"visibilitychange",i),()=>{clearTimeout(p),o.stop()}}return o.stop}var ot=T("onsite-wheel.min.js"),Ie=()=>I(ot,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.wheel"));var Me=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access"),j=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),it=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),rt=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),Oe=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),Ce={seen:()=>({session:0,lifetime:0,closedAt:null,submitted:!1}),subscribed:()=>!1,shown(){},closed(){},submitted(){},tab(){},tabOut:()=>!1,pin:()=>null,coveredAt:()=>null,covered(){},code:()=>null},lt=1500,at=50,ct=300,ut=()=>{try{return new URLSearchParams(location.search).get("hp_debug")==="onsite"}catch{return!1}};function Pe(e,s={}){if(typeof window>"u"||typeof document>"u")return null;if(window[j])return window[j];let n=typeof e?.[Me]=="function"?e[Me]():null;if(!n)return console.warn("[hp] onsite: startOnsite needs the client bootstrap or createAnalytics made"),null;let r=s.settings??n.settings??{},d=ce(n,{...s,challenge:r.capture?.challenge}),o=n.preview?Ce:pe(n.storageKey,n.personalisation),a=()=>n.campaign?.()??null,p=new Map,i=()=>window[Oe]?.size>0,l=(t,u)=>{for(let f of window[rt]?.[t]??[])try{f(u)}catch(g){console.warn(`[hp] onsite ${t} listener failed:`,g)}},c=ve(window),w=n.debug||s.debug===!0||ut(),b=new Map,_=new Map,A=[];for(let t of Array.isArray(r.forms)?r.forms:[]){let u=_e(t);u?A.push(u):b.set(String(t?.slot??`form ${b.size+1}`),{slot:String(t?.slot??""),state:"invalid",reasons:["not a form this SDK can show"]})}let ee=()=>ue().catch(t=>(console.warn("[hp] onsite audiences not loaded:",t?.message??t),null));n.personalisation()&&A.some(t=>t.audiences.length>0)&&ee().then(t=>t?.prefetch(d));let v=new Map,U=new Map,M=null,te=new Set,$e=t=>{for(let u of v.keys()){let f=p.get(u);if(!t||!f||f.modal?.())return u}return null},W=[],X=Number.isInteger(r.overlay_gap_minutes)?r.overlay_gap_minutes:0,Ne=()=>{let t=o.coveredAt();if(!(X>0)||typeof t!="number")return null;let u=Math.max(0,Math.floor((Date.now()-t)/6e4));return u<X?`a popup showed ${u} min ago; ${X} min between them`:null},N=new Set,K=new Map,m=(t,u,f=[])=>(b.set(t.slot,{slot:t.slot,format:t.format,trigger:t.trigger.type,priority:t.priority,state:u,reasons:f}),w&&console.info(`[hp] onsite ${t.slot}: ${u}${f.length?` (${f.join("; ")})`:""}`),u),ne=()=>{try{let t=s.audiences?.();return Array.isArray(t)?t:null}catch{return null}},se=t=>({path:location.pathname,device:c,campaign:a(),now:Date.now(),seen:o.seen(t.slot),subscribed:o.subscribed()||s.subscribed?.()===!0,personalisation:n.personalisation(),preview:!!n.preview,audiences:ne()}),z=t=>{_.get(t.slot)?.(),_.delete(t.slot)};function R(t,u,f=!1,g=F(t)){return p.has(t.slot)?Promise.resolve("shown"):(U.has(t.slot)||U.set(t.slot,Re(t,u,f,g).finally(()=>U.delete(t.slot))),U.get(t.slot))}async function Re(t,u,f,g){if(i())return m(t,"not shown",[`suppressed: ${[...window[Oe]].join(", ")}`]);let O=Q(t,{...se(t),...f?{seen:Ce.seen()}:{},asked:g});if(O.length)return m(t,"not eligible",O);let E=Se(t.format)&&!f,Y=E&&!g&&Ne();if(Y)return m(t,"not shown",[Y]);if(E&&!n.preview&&n.consentAnswered?.()===!1)return K.set(t,g),m(t,"not shown",["waiting for the consent banner"]);let x=Z(t.format),L=x&&$e(g);if(L)return m(t,"not shown",[`${L} is showing`]);if(x&&M&&!g)return m(t,"not shown",[`${M} already showed on this page view`]);let C=null;if(!x){try{C=document.querySelector(t.trigger.selector??"")}catch{C=null}if(!C)return m(t,"not shown",["no element matches its selector"])}x&&v.set(t.slot,t),z(t),m(t,"asking for a decision",[u]);let ke=fe().catch(h=>(console.warn("[hp] onsite renderer not loaded:",h?.message??h),null)),G=ne()??[],ie=[...new Set([...t.audiences,...G])].filter(h=>G.includes(h)).slice(0,100),Fe=t.audiences.length>0&&!n.preview&&n.personalisation()?await Promise.race([ee().then(h=>h?h.visitAudiences(d,n.sessionSignals,t.audiences,G):ie),new Promise(h=>setTimeout(h,lt,ie))]):null,P=await d.decide(t.slot,o.pin(t.slot),{visitAudiences:Fe,visitCampaign:t.arrived_from.length?a():null}),y=P.status===200?P.body?.decisions?.find(h=>h?.slot===t.slot):null;y?.experiment&&y.arm&&y.split&&o.pin(t.slot,[y.experiment,y.arm,y.split]);let $=y&&y.holdout!==!0?Ae(y.payload):null,re=$?.steps[0].blocks??[],le=y?.offer?.code??(n.preview?"PREVIEW":o.code()),je=n.basketValue?.()??null,B=re.some(h=>h?.t==="code")&&!le&&"no code to remind of"||re.some(h=>h?.t==="progress")&&!(je>0)&&"the basket is empty";if(B)return v.delete(t.slot),B==="the basket is empty"&&N.add(t),m(t,"not shown",[B]);if(N.delete(t),!$)return y?.holdout===!0&&n.analytics()&&e.recordExposure(P.body),v.delete(t.slot),x&&y?.holdout===!0&&(M??(M=t.slot)),y?.holdout===!0&&!g&&l("held",{slot:t.slot,arm:y.arm??null,format:t.format}),m(t,y?.holdout===!0?"held out":"no decision",[P.status===200?"no creative for this visitor":`decisions answered ${P.status}`]);let q=await ke;if(!q)return v.delete(t.slot),m(t,"not shown",["the renderer did not load"]);if(await Promise.race([q.warm?.(t,$,$.steps[0].id,te),new Promise(h=>setTimeout(h,ct))]),i())return v.delete(t.slot),m(t,"not shown",["suppressed"]);f||o.shown(t.slot),E&&o.covered(),x&&(M??(M=t.slot));let J=(h,We={})=>l(h,{slot:t.slot,arm:y.arm??null,format:$.format??t.format,...We}),Ue=q.mountForm({form:t,creative:$,decision:y,access:n,client:e,api:d,counters:o,loadWheel:Ie,loadAnswers:ae,container:C,warmed:te,coupon:le,basket:()=>n.basketValue?.()??null,emit:J,onClose(h){p.delete(t.slot),v.delete(t.slot),m(t,"closed",[h]),J("closed",{reason:h})}});return p.set(t.slot,Ue),n.analytics()&&e.recordExposure(P.body),m(t,"shown",[u]),J("shown"),"shown"}function V(t,u,f=F(t)){if(!Z(t.format))return R(t,u,!1,f);W.push([t,u,f]),!(W.length>1)&&setTimeout(async()=>{let g=W.sort(([O],[E])=>Ee(O,E));W=[];for(let[O,[E,Y,x]]of g.entries()){let L=await R(E,Y,!1,x);if(L==="shown"||L==="held out"){for(let[C]of g.slice(O+1))m(C,"not shown",[`${E.slot} has a higher priority`]);return}}},at)}for(let t of A){if(t.format==="teaser"&&o.tabOut(t.slot)){R(t,"tab kept from an earlier page",!0);continue}let u=Q(t,se(t));if(u.length){m(t,"not eligible",u);continue}let f=t.trigger.type;f==="manual"?m(t,"waiting for hp.onsite.open"):f==="inline"||t.format==="inline"?R(t,"inline"):oe(t)}function oe(t){z(t),_.set(t.slot,Te(t.trigger,u=>{z(t),V(t,u)},{device:c})),m(t,"armed",[`${t.trigger.type} on ${c}`])}let De=n.onConsentAnswered?.(()=>{let t=[...K];K.clear();for(let[u,f]of t)p.has(u.slot)||(f?V(u,"manual",f):oe(u))}),Le=n.onBasket?.(()=>{if(!((n.basketValue?.()??0)>0))return;let t=[...N];N.clear();for(let u of t)p.has(u.slot)||V(u,"the basket changed")}),D=Object.freeze({open(t){let u=A.find(g=>g.slot===t),f=u??A.find(g=>g.aliases.includes(t));return f?p.has(f.slot)?Promise.resolve(!0):R(f,"manual",!1,F(f)||!u).then(g=>g==="shown"):Promise.resolve(!1)},suppress(){for(let[t,u]of p){u.destroy(),p.delete(t),v.delete(t);let f=A.find(g=>g.slot===t);f&&m(f,"closed",["suppressed"])}},debug:()=>[...b.values()].map(t=>({...t,reasons:[...t.reasons]})),stop(){for(let t of _.values())t();_.clear(),Le?.(),De?.(),N.clear(),K.clear(),window[j]===D&&delete window[j]}});window[j]=D;for(let{slot:t,resolve:u}of window[it]?.splice(0)??[])u(D.open(t));return w&&console.table?.(D.debug()),D}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module")]={startOnsite:Pe};})();
1
+ (()=>{function T(e){let s=typeof document>"u"?null:document.currentScript?.src;return s?new URL(e,s).href:null}var H=new Map;function I(e,s){return window[s]?Promise.resolve(window[s]):e?(H.has(s)||H.set(s,new Promise((n,i)=>{let a=document.createElement("script");a.src=e,a.async=!0,a.onload=()=>window[s]?n(window[s]):i(new Error(`${e} did not register`)),a.onerror=()=>i(new Error(`${e} did not load`)),document.head.append(a)}).finally(()=>H.delete(s))),H.get(s)):Promise.reject(new Error("the CDN script\u2019s own URL is unknown"))}var Ke=T("onsite-answers.min.js"),ae=()=>I(Ke,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.answers"));var Ye="/v1/capture/challenge",He=e=>typeof e=="string"&&/^\/v1\/[\w/-]+$/.test(e)?e:Ye;function ce(e,s={}){let n=s.fetch??globalThis.fetch?.bind(globalThis),i=s.servingHost??e.servingHost,a=s.gatewayHost??e.gatewayHost;async function r(d,{method:p="GET",body:o,consent:l=!1,timeoutMs:c}={}){if(!n)return{status:0,body:null};try{let w=await n(d,{method:p,credentials:"omit",signal:c&&AbortSignal.timeout?.(c),headers:{accept:"application/json",authorization:`Bearer ${e.writeKey}`,...o?{"content-type":"application/json"}:{},...l?e.headers():{}},...o?{body:JSON.stringify(o)}:{}}),b=null;try{b=await w.json()}catch{}return{status:w.status,body:b}}catch{return{status:0,body:null}}}return{decide:(d,p,{visitAudiences:o,visitCampaign:l}={})=>r(`${i}/v1/decisions`,{method:"POST",consent:!0,body:{slots:[p?{key:d,pin:{experiment:p[0],arm:p[1],split:p[2]}}:d],identifier_value:e.anonymousId()??void 0,session_id:e.sessionId()??void 0,identity_token:e.identityToken?.()??void 0,...e.preview?{preview:e.preview}:{},...o?{visit_audiences:o}:{},...l?{visit_campaign:l}:{}}}),datafile:()=>r(`${i}/v1/audiences/datafile`,{timeoutMs:1500}),challenge:()=>r(`${a}${He(s.challenge)}`),capture:d=>r(`${a}/v1/capture`,{method:"POST",body:d}),answers:d=>r(`${a}/v1/capture/answers`,{method:"POST",body:d}),claim:d=>r(`${i}/v1/offers/claim`,{method:"POST",consent:!0,body:d,timeoutMs:8e3})}}var Xe=T("onsite-audiences.min.js"),ue=()=>I(Xe,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.audiences"));function de(e,s){let n={},i=()=>{try{let r=JSON.parse(e().getItem(s));r&&typeof r=="object"&&(n=r)}catch{}return n};return{read:i,write:r=>{let d=i();r(d),n=d;try{e().setItem(s,JSON.stringify(d))}catch{}}}}function pe(e,s=()=>!0){let n=de(()=>sessionStorage,e),i=de(()=>localStorage,e),a=()=>s()?i:n,r=()=>{let o=i.read();(o.sub!==void 0||o.k!==void 0)&&i.write(l=>{delete l.sub,delete l.k})},d=()=>s()?[n.read(),i.read()]:(r(),[n.read()]),p=(o,l)=>{var c;return o.f??(o.f={}),(c=o.f)[l]??(c[l]={}),o.f[l]};return{seen(o){let l=i.read().f?.[o]??{};return{session:n.read().f?.[o]?.n??0,lifetime:l.n??0,closedAt:l.c??null,submitted:l.s===1}},subscribed:()=>d().some(o=>o.sub===1),shown(o){n.write(l=>{let c=p(l,o);c.n=(c.n??0)+1}),i.write(l=>{let c=p(l,o);c.n=(c.n??0)+1})},closed(o,l=Date.now()){i.write(c=>{p(c,o).c=l})},tab(o,l){n.write(c=>{let w=p(c,o);l?w.t=1:delete w.t})},tabOut:o=>n.read().f?.[o]?.t===1,pin(o,l){if(l===void 0)return n.read().f?.[o]?.p??null;n.write(c=>{p(c,o).p=l})},coveredAt:()=>n.read().o??null,covered(o=Date.now()){n.write(l=>{l.o=o})},code(o,l=Date.now()){if(o===void 0){let[c]=d().flatMap(w=>w.k?[w.k]:[]).sort((w,b)=>b.at-w.at);return c&&l-c.at<14*864e5?c.c:null}return a().write(c=>{c.k={c:o,at:l}}),o},submitted(o){i.write(l=>{p(l,o).s=1}),a().write(l=>{l.sub=1})}}}var ze=T("onsite-render.min.js"),fe=()=>I(ze,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.render"));var Ve=["source","medium","campaign","content","term"];var he=e=>String(e).trim().toLowerCase();function Ge(e,s,n){let i=he(e),a=he(n);return s==="is"?i===a:s==="contains"&&a!==""&&i.includes(a)}function ge(e,s){return(Array.isArray(e)?e:[]).every(n=>{let i=s?.[n?.field];return!Ve.includes(n?.field)||typeof i!="string"?!1:[].concat(n.values??[]).some(a=>Ge(i,n.match,a))})}var be=["popup","sheet","bar","teaser","inline","fullscreen"],Be=["entry","exit","scroll","time","idle","inline","manual"],Z=e=>e!=="inline",Se=e=>e==="popup"||e==="sheet"||e==="fullscreen",S=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),k=e=>Array.isArray(e)?e.filter(s=>typeof s=="string"):[],me=e=>Number.isInteger(e)&&e>=0?e:null,qe={field:null,match:null,values:[]},Je=e=>e==null?[]:Array.isArray(e)&&e.every(S)?e:[qe];function _e(e){if(!S(e)||typeof e.slot!="string"||e.slot==="")return null;let s=S(e.trigger)?e.trigger:{};if(!be.includes(e.format)||!Be.includes(s.type))return null;let n=S(e.caps)?e.caps:{};return{...e,trigger:s,priority:Number.isFinite(e.priority)?e.priority:0,pages:S(e.pages)?e.pages:{},devices:k(e.devices),aliases:k(e.aliases),audiences:k(e.audiences),arrived_from:Je(e.arrived_from),caps:{per_session:me(n.per_session),lifetime:me(n.lifetime),after_close_days:Number.isFinite(n.after_close_days)?n.after_close_days:null},window:S(e.window)?e.window:{},questions:Array.isArray(e.questions)?e.questions.filter(S):[],prizes:Array.isArray(e.prizes)?e.prizes.filter(S):[]}}var Ze=/^[a-z][a-z0-9_-]{0,31}$/;function Ae(e){if(!S(e)||e.v!==1||!Array.isArray(e.steps))return null;let s=e.steps.filter(n=>S(n)&&Ze.test(n.id)&&Array.isArray(n.blocks));return s.length===0?null:{format:be.includes(e.format)?e.format:null,theme:S(e.theme)?e.theme:{},steps:s}}function we(e,s){let n=String(e).split("*").map(i=>i.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${n}$`,"i").test(s)}function Qe(e,s){let n=k(e?.include);return(!n.length||n.some(i=>we(i,s)))&&!k(e?.exclude).some(i=>we(i,s))}function ve(e){return e.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches===!0||e.innerWidth<768?"mobile":"desktop"}var ye=e=>typeof e=="string"?Date.parse(e):Number.NaN,F=e=>e.trigger.type==="manual";function Q(e,s){let n=[];Qe(e.pages,s.path)||n.push("page not included"),e.devices.length&&!e.devices.includes(s.device)&&n.push(`not on ${s.device}`),ge(e.arrived_from,s.campaign)||n.push("not from its campaign");let i=ye(e.window.starts_at),a=ye(e.window.ends_at);if((s.now<i||s.now>=a)&&n.push("outside its dates"),e.audiences.length&&!s.preview&&(s.personalisation?s.audiences&&!e.audiences.some(p=>s.audiences.includes(p))&&n.push("not in its audiences"):n.push("audiences need personalisation consent")),s.preview||s.asked||F(e))return n;let{seen:r}=s,{caps:d}=e;return r.submitted&&n.push("already submitted"),e.exclude_subscribed===!0&&s.subscribed&&n.push("already subscribed"),d.per_session!==null&&r.session>=d.per_session&&n.push("per_session cap"),d.lifetime!==null&&r.lifetime>=d.lifetime&&n.push("lifetime cap"),d.after_close_days!==null&&r.closedAt&&s.now-r.closedAt<d.after_close_days*864e5&&n.push("closed recently"),n}var Ee=(e,s)=>s.priority-e.priority;var et=["mousemove","pointerdown","keydown","scroll","touchstart","wheel"];function tt(){let e=[];return{on:(i,a,r,d={passive:!0})=>{i.addEventListener(a,r,d),e.push(()=>i.removeEventListener(a,r,d))},later:(i,a)=>{let r=setTimeout(i,a);e.push(()=>clearTimeout(r))},stop:()=>{for(let i of e.splice(0))i()}}}var xe=(e,s)=>{let n=s.documentElement.scrollHeight||0;return n>0?(e.scrollY+e.innerHeight)/n:0},nt=e=>{let s=e.activeElement;return!!(s&&(/^(INPUT|TEXTAREA|SELECT)$/.test(s.tagName)||s.isContentEditable))};function st({on:e,later:s},n,i,a,r){let d=!1,p=!1,o=null,l=0;s(()=>{d=!0},i.delay_ms??5e3),e(r,"mousemove",c=>{c.clientY>a.innerHeight*.1&&(p=!0),o!==null&&(l=c.clientY-o),o=c.clientY}),e(r,"mouseout",c=>{d&&p&&!c.relatedTarget&&c.clientY<=0&&l<0&&!nt(r)&&n("exit")})}function ot({on:e,later:s},n,i,a,r){let d=!1,p=0,o=a.scrollY,l=Date.now(),c=null,w=null;s(()=>{d=!0},i.delay_ms??5e3),e(a,"scroll",()=>{let b=a.scrollY,_=Date.now();if(p=Math.max(p,xe(a,r)),b<o){(!c||_-c.t>300)&&(c={y:o,t:l});let A=c.y-b;d&&p>=.3&&A>=120&&A/Math.max(1,_-c.t)>=.5&&n("exit_scroll")}else c=null;o=b,l=_}),e(r,"visibilitychange",()=>{r.visibilityState==="hidden"?w=Date.now():w!==null&&Date.now()-w>=1e4&&n("return"),r.visibilityState!=="hidden"&&(w=null)})}function Te(e,s,{device:n,win:i=window,doc:a=document}){let r=tt(),d=(e.seconds??30)*1e3;if(e.type==="entry"&&r.later(()=>s("entry"),e.delay_ms??0),e.type==="time"&&r.later(()=>s("time"),d),e.type==="exit"&&(n==="mobile"?ot:st)(r,s,e,i,a),e.type==="scroll"){let p=e.depth??.5;r.on(i,"scroll",()=>xe(i,a)>=p&&s("scroll"))}if(e.type==="idle"){let p=null,o=()=>{clearTimeout(p),p=setTimeout(()=>s("idle"),d)};o();for(let l of et)r.on(l==="scroll"?i:a,l,o);return r.on(a,"visibilitychange",o),()=>{clearTimeout(p),r.stop()}}return r.stop}var it=T("onsite-wheel.min.js"),Ie=()=>I(it,Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.wheel"));var Me=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite-access"),j=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite"),rt=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.pending"),lt=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.listeners"),Oe=Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.suppressed"),Ce={seen:()=>({session:0,lifetime:0,closedAt:null,submitted:!1}),subscribed:()=>!1,shown(){},closed(){},submitted(){},tab(){},tabOut:()=>!1,pin:()=>null,coveredAt:()=>null,covered(){},code:()=>null},at=1500,ct=50,ut=300,dt=()=>{try{return new URLSearchParams(location.search).get("hp_debug")==="onsite"}catch{return!1}};function Pe(e,s={}){if(typeof window>"u"||typeof document>"u")return null;if(window[j])return window[j];let n=typeof e?.[Me]=="function"?e[Me]():null;if(!n)return console.warn("[hp] onsite: startOnsite needs the client bootstrap or createAnalytics made"),null;let i=s.settings??n.settings??{},a=ce(n,{...s,challenge:i.capture?.challenge}),r=n.preview?Ce:pe(n.storageKey,n.personalisation),d=()=>n.campaign?.()??null,p=new Map,o=()=>window[Oe]?.size>0,l=(t,u)=>{for(let f of window[lt]?.[t]??[])try{f(u)}catch(g){console.warn(`[hp] onsite ${t} listener failed:`,g)}},c=ve(window),w=n.debug||s.debug===!0||dt(),b=new Map,_=new Map,A=[];for(let t of Array.isArray(i.forms)?i.forms:[]){let u=_e(t);u?A.push(u):b.set(String(t?.slot??`form ${b.size+1}`),{slot:String(t?.slot??""),state:"invalid",reasons:["not a form this SDK can show"]})}let ee=()=>ue().catch(t=>(console.warn("[hp] onsite audiences not loaded:",t?.message??t),null));n.personalisation()&&A.some(t=>t.audiences.length>0)&&ee().then(t=>t?.prefetch(a));let v=new Map,U=new Map,M=null,te=new Set,$e=t=>{for(let u of v.keys()){let f=p.get(u);if(!t||!f||f.modal?.())return u}return null},W=[],X=Number.isInteger(i.overlay_gap_minutes)?i.overlay_gap_minutes:0,Ne=()=>{let t=r.coveredAt();if(!(X>0)||typeof t!="number")return null;let u=Math.max(0,Math.floor((Date.now()-t)/6e4));return u<X?`a popup showed ${u} min ago; ${X} min between them`:null},N=new Set,K=new Map,m=(t,u,f=[])=>(b.set(t.slot,{slot:t.slot,format:t.format,trigger:t.trigger.type,priority:t.priority,state:u,reasons:f}),w&&console.info(`[hp] onsite ${t.slot}: ${u}${f.length?` (${f.join("; ")})`:""}`),u),ne=()=>{try{let t=s.audiences?.();return Array.isArray(t)?t:null}catch{return null}},se=t=>({path:location.pathname,device:c,campaign:d(),now:Date.now(),seen:r.seen(t.slot),subscribed:r.subscribed()||s.subscribed?.()===!0,personalisation:n.personalisation(),preview:!!n.preview,audiences:ne()}),z=t=>{_.get(t.slot)?.(),_.delete(t.slot)};function R(t,u,f=!1,g=F(t)){return p.has(t.slot)?Promise.resolve("shown"):(U.has(t.slot)||U.set(t.slot,Re(t,u,f,g).finally(()=>U.delete(t.slot))),U.get(t.slot))}async function Re(t,u,f,g){if(o())return m(t,"not shown",[`suppressed: ${[...window[Oe]].join(", ")}`]);let O=Q(t,{...se(t),...f?{seen:Ce.seen()}:{},asked:g});if(O.length)return m(t,"not eligible",O);let E=Se(t.format)&&!f,Y=E&&!g&&Ne();if(Y)return m(t,"not shown",[Y]);if(E&&!n.preview&&n.consentAnswered?.()===!1)return K.set(t,g),m(t,"not shown",["waiting for the consent banner"]);let x=Z(t.format),L=x&&$e(g);if(L)return m(t,"not shown",[`${L} is showing`]);if(x&&M&&!g)return m(t,"not shown",[`${M} already showed on this page view`]);let C=null;if(!x){try{C=document.querySelector(t.trigger.selector??"")}catch{C=null}if(!C)return m(t,"not shown",["no element matches its selector"])}x&&v.set(t.slot,t),z(t),m(t,"asking for a decision",[u]);let ke=fe().catch(h=>(console.warn("[hp] onsite renderer not loaded:",h?.message??h),null)),G=ne()??[],ie=[...new Set([...t.audiences,...G])].filter(h=>G.includes(h)).slice(0,100),Fe=t.audiences.length>0&&!n.preview&&n.personalisation()?await Promise.race([ee().then(h=>h?h.visitAudiences(a,n.sessionSignals,t.audiences,G):ie),new Promise(h=>setTimeout(h,at,ie))]):null,P=await a.decide(t.slot,r.pin(t.slot),{visitAudiences:Fe,visitCampaign:t.arrived_from.length?d():null}),y=P.status===200?P.body?.decisions?.find(h=>h?.slot===t.slot):null;y?.experiment&&y.arm&&y.split&&r.pin(t.slot,[y.experiment,y.arm,y.split]);let $=y&&y.holdout!==!0?Ae(y.payload):null,re=$?.steps[0].blocks??[],le=y?.offer?.code??(n.preview?"PREVIEW":r.code()),je=n.basketValue?.()??null,B=re.some(h=>h?.t==="code")&&!le&&"no code to remind of"||re.some(h=>h?.t==="progress")&&!(je>0)&&"the basket is empty";if(B)return v.delete(t.slot),B==="the basket is empty"&&N.add(t),m(t,"not shown",[B]);if(N.delete(t),!$)return y?.holdout===!0&&n.analytics()&&e.recordExposure(P.body),v.delete(t.slot),x&&y?.holdout===!0&&(M??(M=t.slot)),y?.holdout===!0&&!g&&l("held",{slot:t.slot,arm:y.arm??null,format:t.format}),m(t,y?.holdout===!0?"held out":"no decision",[P.status===200?"no creative for this visitor":`decisions answered ${P.status}`]);let q=await ke;if(!q)return v.delete(t.slot),m(t,"not shown",["the renderer did not load"]);if(await Promise.race([q.warm?.(t,$,$.steps[0].id,te),new Promise(h=>setTimeout(h,ut))]),o())return v.delete(t.slot),m(t,"not shown",["suppressed"]);f||r.shown(t.slot),E&&r.covered(),x&&(M??(M=t.slot));let J=(h,We={})=>l(h,{slot:t.slot,arm:y.arm??null,format:$.format??t.format,...We}),Ue=q.mountForm({form:t,creative:$,decision:y,access:n,client:e,api:a,counters:r,loadWheel:Ie,loadAnswers:ae,container:C,warmed:te,coupon:le,basket:()=>n.basketValue?.()??null,emit:J,onClose(h){p.delete(t.slot),v.delete(t.slot),m(t,"closed",[h]),J("closed",{reason:h})}});return p.set(t.slot,Ue),n.analytics()&&e.recordExposure(P.body),m(t,"shown",[u]),J("shown"),"shown"}function V(t,u,f=F(t)){if(!Z(t.format))return R(t,u,!1,f);W.push([t,u,f]),!(W.length>1)&&setTimeout(async()=>{let g=W.sort(([O],[E])=>Ee(O,E));W=[];for(let[O,[E,Y,x]]of g.entries()){let L=await R(E,Y,!1,x);if(L==="shown"||L==="held out"){for(let[C]of g.slice(O+1))m(C,"not shown",[`${E.slot} has a higher priority`]);return}}},ct)}for(let t of A){if(t.format==="teaser"&&r.tabOut(t.slot)){R(t,"tab kept from an earlier page",!0);continue}let u=Q(t,se(t));if(u.length){m(t,"not eligible",u);continue}let f=t.trigger.type;f==="manual"?m(t,"waiting for hp.onsite.open"):f==="inline"||t.format==="inline"?R(t,"inline"):oe(t)}function oe(t){z(t),_.set(t.slot,Te(t.trigger,u=>{z(t),V(t,u)},{device:c})),m(t,"armed",[`${t.trigger.type} on ${c}`])}let De=n.onConsentAnswered?.(()=>{let t=[...K];K.clear();for(let[u,f]of t)p.has(u.slot)||(f?V(u,"manual",f):oe(u))}),Le=n.onBasket?.(()=>{if(!((n.basketValue?.()??0)>0))return;let t=[...N];N.clear();for(let u of t)p.has(u.slot)||V(u,"the basket changed")}),D=Object.freeze({open(t){let u=A.find(g=>g.slot===t),f=u??A.find(g=>g.aliases.includes(t));return f?p.has(f.slot)?Promise.resolve(!0):R(f,"manual",!1,F(f)||!u).then(g=>g==="shown"):Promise.resolve(!1)},suppress(){for(let[t,u]of p){u.destroy(),p.delete(t),v.delete(t);let f=A.find(g=>g.slot===t);f&&m(f,"closed",["suppressed"])}},debug:()=>[...b.values()].map(t=>({...t,reasons:[...t.reasons]})),stop(){for(let t of _.values())t();_.clear(),Le?.(),De?.(),N.clear(),K.clear(),window[j]===D&&delete window[j]}});window[j]=D;for(let{slot:t,resolve:u}of window[rt]?.splice(0)??[])u(D.open(t));return w&&console.table?.(D.debug()),D}window[Symbol.for("@thg-agentic/hyper-personalisation-web.onsite.module")]={startOnsite:Pe};})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thg-agentic/hyper-personalisation-web",
3
- "version": "3.26.0",
3
+ "version": "3.27.0",
4
4
  "description": "Browser SDK for the THG Hyper-Personalisation event specification: event tracking from a write key and remote settings, strict CMP-agnostic consent, a GA4 dataLayer bridge and in-session audience evaluation. Dependency-free ESM on the Segment wire protocol, a CDN script (dist/hp.min.js), and an optional @segment/analytics-next plugin path.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -641,7 +641,9 @@ export function createAnalytics(options) {
641
641
  }
642
642
 
643
643
  function observe(event) {
644
- if (event.type === 'track') recordVisit(event);
644
+ // A page view folds in no counter, but brings the visit's campaign into the session signals,
645
+ // so a landing page that sends nothing else can resolve an audience on it.
646
+ if (event.type === 'track' || event.type === 'page') recordVisit(event);
645
647
  // Lets a caller fold the event the warehouse will receive into session state. An observer
646
648
  // that throws must not cost the event.
647
649
  if (cfg.onEvent) {
@@ -666,11 +668,15 @@ export function createAnalytics(options) {
666
668
  try {
667
669
  if (personalisationGranted()) {
668
670
  scopeVisit();
669
- keepVisit(
670
- recommendationContextFrom(
671
- recordSessionEvent(event.event, event.properties),
672
- ),
671
+ const signals = recordSessionEvent(
672
+ event.event,
673
+ event.properties,
674
+ // The one visit-campaign store, kept since the landing page whatever the consent then.
675
+ readVisitCampaign(cfg.propertyId, { sessionId: keptSession() }),
673
676
  );
677
+ // A page view changes nothing a rail reads, so it does not extend what is kept for one.
678
+ if (event.type === 'track')
679
+ keepVisit(recommendationContextFrom(signals));
674
680
  visitKept = true;
675
681
  } else {
676
682
  // Not allowed, or withdrawn: what was kept under the permission goes with it.
@@ -1202,11 +1208,19 @@ export function createAnalytics(options) {
1202
1208
  const value = getSessionSignals().basketValue;
1203
1209
  return pageBasket ?? (Number.isFinite(value) ? value : null);
1204
1210
  },
1205
- /** This visit's session signals, kept only under personalisation consent; else null. */
1211
+ /**
1212
+ * This visit's session signals, kept only under personalisation consent; else null. The
1213
+ * campaign is the store's as it stands, so one that has lapsed since the last event is gone.
1214
+ */
1206
1215
  sessionSignals: () => {
1207
1216
  if (!personalisationGranted()) return null;
1208
1217
  scopeVisit();
1209
- return getSessionSignals();
1218
+ return {
1219
+ ...getSessionSignals(),
1220
+ campaign: readVisitCampaign(cfg.propertyId, {
1221
+ sessionId: keptSession(),
1222
+ }),
1223
+ };
1210
1224
  },
1211
1225
  /** Calls `listener` whenever the page reports its basket; answers how to stop. */
1212
1226
  onBasket: (listener) => {
@@ -58,11 +58,16 @@ function countListView(s, category) {
58
58
  * Fold one CDP event into the session signals.
59
59
  *
60
60
  * Driven by the events the SDK already sends, so a session rule is only ever about something the
61
- * warehouse will also see.
61
+ * warehouse will also see. `campaign`, when given, is the visit's campaign (`readVisitCampaign`),
62
+ * mirrored as it stands so the two never disagree; left out, the kept one stays.
62
63
  */
63
- export function recordSessionEvent(eventName, properties) {
64
+ export function recordSessionEvent(eventName, properties, campaign) {
64
65
  const s = readSignals();
65
66
  if (!s.startedAt) s.startedAt = Date.now();
67
+ const arrived =
68
+ campaign !== undefined &&
69
+ JSON.stringify(campaign ?? null) !== JSON.stringify(s.campaign ?? null);
70
+ if (arrived) s.campaign = campaign ?? null;
66
71
 
67
72
  const products = Array.isArray(properties?.products)
68
73
  ? properties.products
@@ -178,6 +183,7 @@ export function recordSessionEvent(eventName, properties) {
178
183
  return s;
179
184
  }
180
185
  default:
186
+ if (arrived) writeSignals(s);
181
187
  return s;
182
188
  }
183
189
 
@@ -1,3 +1,4 @@
1
+ import { CAMPAIGN_FIELDS, tagMatches } from '../visit-campaign.js';
1
2
  import { categoryKey } from './category.js';
2
3
  import { readSignals } from './signals.js';
3
4
 
@@ -17,12 +18,28 @@ const OPERATORS = {
17
18
  '=': (a, b) => a === b,
18
19
  };
19
20
 
21
+ /**
22
+ * Operators on a text field (the visit's campaign tags): `tagMatches`, the matcher a form's
23
+ * "arrived from" rule uses, so the two agree. A value of the wrong shape matches nothing.
24
+ */
25
+ const text = (v) => typeof v === 'string';
26
+ const is = (a, b) => text(b) && tagMatches(a, 'is', b);
27
+ const STRING_OPERATORS = {
28
+ eq: is,
29
+ equals: is,
30
+ '=': is,
31
+ neq: (a, b) => text(b) && !is(a, b),
32
+ in: (a, b) => Array.isArray(b) && b.some((v) => is(a, v)),
33
+ contains: (a, b) => text(b) && tagMatches(a, 'contains', b),
34
+ };
35
+
20
36
  /**
21
37
  * Every operator this evaluator can apply, including `between`. A contract test keeps the session
22
38
  * trait catalogue inside this set, since an unsupported operator fails closed silently.
23
39
  */
24
40
  export const SESSION_OPERATORS = new Set([
25
41
  ...Object.keys(OPERATORS),
42
+ ...Object.keys(STRING_OPERATORS),
26
43
  'between',
27
44
  ]);
28
45
 
@@ -54,14 +71,23 @@ const MEASURES = {
54
71
  /**
55
72
  * What a rule's field is worth right now, or null if this build does not know the field.
56
73
  *
57
- * A field is a counter name or `measure.dimension` (`browseShare.damen/schuhe`). Exported so a
58
- * storefront can explain a personalisation. Unknown fields fail the rule closed.
74
+ * A field is a counter name, `measure.dimension` (`browseShare.damen/schuhe`), or one of the
75
+ * visit's campaign tags (`campaign.source`), which is text and null for a visit that arrived
76
+ * untagged. Exported so a storefront can explain a personalisation. Unknown fields fail the rule
77
+ * closed.
59
78
  */
60
79
  export function measureField(field, signals) {
61
80
  const separator = field.indexOf('.');
62
81
  if (separator > 0) {
63
- const fn = MEASURES[field.slice(0, separator)];
82
+ const name = field.slice(0, separator);
64
83
  const arg = field.slice(separator + 1);
84
+ if (name === 'campaign') {
85
+ const tag = CAMPAIGN_FIELDS.includes(arg)
86
+ ? signals.campaign?.[arg]
87
+ : null;
88
+ return typeof tag === 'string' ? tag : null;
89
+ }
90
+ const fn = MEASURES[name];
65
91
  return fn && arg ? fn(signals, arg) : null;
66
92
  }
67
93
  const value = signals[field];
@@ -71,6 +97,10 @@ export function measureField(field, signals) {
71
97
  export function evaluateSessionRule(rule, signals) {
72
98
  const actual = measureField(rule.field, signals);
73
99
  if (actual === null) return false;
100
+ if (typeof actual === 'string') {
101
+ const compare = STRING_OPERATORS[rule.operator];
102
+ return compare ? compare(actual, rule.value) : false;
103
+ }
74
104
  if (rule.operator === 'between') {
75
105
  // A `between` missing either bound fails closed.
76
106
  return (
@@ -69,7 +69,8 @@ function readUnscoped() {
69
69
  parsed.listViews > 0 ||
70
70
  parsed.basketValue != null ||
71
71
  parsed.recentProducts?.length ||
72
- parsed.recentBrowse?.length);
72
+ parsed.recentBrowse?.length ||
73
+ parsed.campaign);
73
74
  return busy ? parsed : null;
74
75
  } catch {
75
76
  return null;
@@ -101,6 +102,9 @@ function emptySignals() {
101
102
  recentBrowseCategories: [],
102
103
  browsingListing: null,
103
104
  listViewsByCategory: {},
105
+ // The campaign the visit arrived from (`readVisitCampaign`, the first page with utm_* tags).
106
+ // Null for a visit that arrived untagged, so every rule on a campaign tag fails closed.
107
+ campaign: null,
104
108
  startedAt: 0,
105
109
  };
106
110
  }
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.26.0';
1
+ export const VERSION = '3.27.0';
2
2
  export const LIB = '@thg-agentic/hyper-personalisation-web';
@@ -46,6 +46,19 @@ export function visitCampaign(campaign) {
46
46
 
47
47
  const norm = (v) => String(v).trim().toLowerCase();
48
48
 
49
+ /**
50
+ * Whether a campaign tag meets one wanted value, trimmed and in any case: `is` the whole tag,
51
+ * `contains` a part of it that is not empty. The one matcher behind a form's `arrived_from` and a
52
+ * session audience's campaign rules, so the two cannot disagree.
53
+ */
54
+ export function tagMatches(tag, match, want) {
55
+ const have = norm(tag);
56
+ const wanted = norm(want);
57
+ return match === 'is'
58
+ ? have === wanted
59
+ : match === 'contains' && wanted !== '' && have.includes(wanted);
60
+ }
61
+
49
62
  /**
50
63
  * Whether `campaign` (a `visitCampaign`) meets every rule `{ field, match: 'is' | 'contains',
51
64
  * values }`, any value meeting a rule, in any case. No rules: true. No campaign, or a rule this SDK
@@ -56,13 +69,9 @@ export function arrivedFrom(rules, campaign) {
56
69
  const tag = campaign?.[rule?.field];
57
70
  if (!CAMPAIGN_FIELDS.includes(rule?.field) || typeof tag !== 'string')
58
71
  return false;
59
- const have = norm(tag);
60
- return [].concat(rule.values ?? []).some((v) => {
61
- const want = norm(v);
62
- return rule.match === 'is'
63
- ? have === want
64
- : rule.match === 'contains' && want !== '' && have.includes(want);
65
- });
72
+ return []
73
+ .concat(rule.values ?? [])
74
+ .some((v) => tagMatches(tag, rule.match, v));
66
75
  });
67
76
  }
68
77