@elevateab/sdk 1.4.0 → 1.4.2

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/dist/index.js CHANGED
@@ -26,5 +26,5 @@ import{a as Ae,b as te,c as w,d as m,e as ot,f as at,g as re,h as ne,i as st,j a
26
26
  if(window.__eab_reveal)window.__eab_reveal();
27
27
  };
28
28
  document.head.appendChild(script);
29
- })();`}function Ne(e){if(!e?.trim())return"";try{let r=`https://${e.trim().replace(/^https?:\/\//,"")}`,o=new URL(r.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function ge(e,t){let r=Ne(e.split("?")[0]);for(let o of t){let n=Ne(o.split("?")[0]);if(r===n)return!0;try{let s=new URL(e).pathname,a=new URL(o,e).pathname;if(s===a)return!0}catch{}}return!1}function Mt(e){return e.data?.redirectBehavior||"redirectAll"}function ze(e){return!!(k("eabRedirectedTests")||{})[e]}function Fe(e){let t=k("eabRedirectedTests")||{};t[e]=!0,x("eabRedirectedTests",JSON.stringify(t))}function Nt(e,t){for(let r of e.tests)if(!(r.type!=="SPLIT_URL"||!r.enabled))for(let o of r.variations){let n=o.splitUrlTestLinks||[];if(n.length!==0&&ge(t,n))return{test:r,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function zt(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let r=t.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let n=t.pathname+t.search;o(n);return}catch{}window.location.href=r}function q(e,t){if(typeof window>"u")return!1;let r=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let n=Nt(e,r);if(!n)return!1;let{test:s,matchedVariation:a,isControlUrl:c}=n,i=s.testId,d=Mt(s),u=S(i);if(!u)return!1;let p=s.variations.find(y=>y.id===u);if(!p)return!1;let l=p.splitUrlTestLinks||[];if(l.length===0||ge(r,l))return!1;switch(d){case"redirectOnlyControlUrl":if(!c||p.isControl)return!1;break;case"redirectOnce":if(ze(i))return!1;Fe(i);break;case"redirectOnceControlUrlOnly":if(!c||ze(i)||p.isControl)return!1;Fe(i);break;default:break}let v=l[0];return zt(v),!0}var ye={type:"SPLIT_URL",shouldActivate(e,t){for(let r of e.variations){let o=r.splitUrlTestLinks||[];if(ge(t.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function _(e){return e?e.includes("gid://")&&e.split("/").pop()||e:""}function Ft(e){return!e||!e.includes("gid://")?null:e.split("/")[3]||null}function $t(e){return!!e&&e.startsWith("gid://shopify/")}function qt(){if(typeof window>"u")return;let e=window.Shopify;if(e?.currency?.active)return e.currency.active}var $e="elv-el-",qe={ELEMENT_NODE:1,TEXT_NODE:3},G=new Map,j=new Map,W=new Map,J=new Map,M=!1;function A(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let r=t.slice(1,-1);return e.includes(r)}if(t.startsWith("*")){let r=t.slice(1);return e.endsWith(r)}return t===e}function ve(){return typeof window>"u"?!1:window.innerWidth<768}function Gt(e){let t="";for(let r=0;r<e.length;r++){let o=e[r];o>="A"&&o<="Z"?(r!==0&&(t+="-"),t+=o.toLowerCase()):t+=o}return t}function jt(e){return e.nodeType===qe.TEXT_NODE}function he(e){return e.nodeType===qe.ELEMENT_NODE}function we(e,t){G.has(e)||G.set(e,t.cloneNode(!0))}function Ge(e){let t=e;t=t.replace(/&#96;/g,"`").replace(/&#36;/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function je(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,r=e.filter(n=>n.pathnames?.length?n.pathnames.some(s=>A(t,s)):!0);M=ve();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...M&&n.style.sm}:void 0,content:n.content&&M&&n.content.sm?n.content.sm:n.content?.lg}));o.filter(n=>n.content!==void 0).forEach(n=>{(n.applyAll?Array.from(document.querySelectorAll(n.selector)):[document.querySelector(n.selector)].filter(Boolean)).forEach((a,c)=>{if(!a)return;let i=n.applyAll?`${n.selector}-${c}-${a.id||Math.random().toString(36).substr(2,9)}`:n.selector;we(i,a),jt(a)?a.nodeValue=n.content:he(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let s=document.querySelector(n.selector);!s||!he(s)||(we(n.selector,s),Object.entries(n.style).forEach(([a,c])=>{let i=Gt(a),d=c.toString().includes("!important"),u=c.toString().replace(/\s*!important\s*$/,"");s.style.setProperty(i,u,d?"important":void 0)}))}),o.filter(n=>n.attributes!==void 0).forEach(n=>{let s=document.querySelector(n.selector);!s||!he(s)||(we(n.selector,s),Object.entries(n.attributes).forEach(([a,c])=>{s.setAttribute(a,c)}))})}function We(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(n=>A(t,n)):!0).forEach(o=>{let n=`${$e}${o.id}`;if(J.has(n))return;let s=document.querySelector(o.selector.target);if(!s||s.parentElement?.querySelector(`#${n}`))return;let a=Je(o);o.selector.placement==="after"?s.after(a):o.selector.placement==="before"&&s.before(a),J.set(n,a)})}function Je(e){let t=document.createElement(e.tagName);return t.id=`${$e}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([r,o])=>{t.setAttribute(r,o)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(r=>{let o=Je(r);t.appendChild(o)}),t}function Y(e,t){if(typeof window>"u"||e.length===0)return;let r=window.location.pathname;e.filter(n=>n.pathnames?.length?n.excludePathnames?.length&&n.excludePathnames.some(a=>A(r,a))?!1:n.pathnames.some(s=>A(r,s)):!0).forEach(n=>{n.id&&(n.css&&Wt(n.id,n.css),n.js&&Jt(n.id,n.js,t))})}function Wt(e,t){let r=`css-${e}`;if(j.has(r)||document.getElementById(r))return;let o=document.createElement("style");o.id=r,o.textContent=Ge(t),document.head.appendChild(o),j.set(r,o)}function Jt(e,t,r){let o=`js-${e}`;if(W.has(o)||document.getElementById(o))return;let n=document.createElement("script");n.id=o,r&&n.setAttribute("nonce",r);let s=Ge(t);n.textContent="(function(){try{"+s+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(n),W.set(o,n)}function Ye(){G.forEach((e,t)=>{let r=document.querySelector(t);r&&r.replaceWith(e.cloneNode(!0))})}function Qe(){j.forEach(e=>e.remove()),j.clear(),W.forEach(e=>e.remove()),W.clear(),J.forEach(e=>e.remove()),J.clear(),G.clear()}function Yt(e,t){let r=[],o=[],n=[];return e.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=S(a.testId);if(!c)return;let i=a.variations.find(d=>d.id===c);i?.content&&(i.content.changes?.length&&r.push(...i.content.changes),i.content.elements?.length&&o.push(...i.content.elements),i.content.customCodes?.length&&n.push(...i.content.customCodes))}),{changes:r,elements:o,blocks:[],customCodes:n}}function Q(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function K(e,t,r){if(typeof window>"u"||!Q(e))return;let o=Yt(e,t);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(je(o.changes),We(o.elements),Y(o.customCodes,r))}function Ce(e,t,r){if(typeof window>"u")return;let o=ve();o!==M&&(Ye(),M=o),K(e,t,r)}function Te(e,t,r){if(typeof window>"u")return()=>{};let o=()=>{ve()!==M&&Ce(e,t,r)},n=()=>{Ce(e,t,r)};return window.addEventListener("resize",o),window.addEventListener("popstate",n),()=>{window.removeEventListener("resize",o),window.removeEventListener("popstate",n),Qe()}}import{useEffect as Ke,useRef as cr,useState as lr}from"react";var Qt="https://bitter-river-9c62.support-67d.workers.dev",Kt="https://d339co84ntxcme.cloudfront.net/Prod/orders",C=null;function Pe(e){C=e}function I(e){let t=e?.storeId||C?.storeId;return t||(console.warn("[ElevateAB] No storeId provided. Call initAnalytics() first or pass storeId to tracking function."),"")}function Xt(e){return Object.entries(e).filter(([,t])=>typeof t=="string").map(([t,r])=>({test_id:t,variant_id:r}))}function Zt(e,t){return Object.entries(e).filter(([r])=>typeof t[r]=="string").map(([r])=>({test_id:r,variant_id:t[r]}))}function er(){return typeof window>"u"?!1:E("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function V(e,t,r){if(typeof window>"u"||er())return null;let o=navigator.userAgent,n=window.location.pathname,s=ae(n,r),{referrer:a,entryPage:c}=ue(),i=oe({referrer:a,entryPage:c,userAgent:o}),d=k("ABTL")||{},u=k("ABAU")||{},p=Xt(d),l=Zt(u,d),v=re(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",f=E("localization")||"";return{pixel_event_id:`sh-${ie()}`,shop_name:e,timestamp:y,event_type:t,client_id:E("_shopify_y")||void 0,visitor_id:le(),session_id:de(),cart_token:ne(v||E("cart")),page_url:window.location.href,page_pathname:n,page_search:window.location.search,referrer_url:a,referrer_source:i?.referrer_source,previous_page:document.referrer,page_entry:c,page_entry_path:i?.page_entry_path,page_type:s,utm_medium:i?.utm_medium,utm_source:i?.utm_source,utm_campaign:i?.utm_campaign,utm_content:i?.utm_content,utm_term:i?.utm_term,gclid:i?.gclid,fbclid:i?.fbclid,pins_campaign_id:i?.pins_campaign_id,epik:i?.epik,browser_info:i?.browser_info,os_info:i?.os_info,device_type:i?.device_type,language:navigator.language,root_route:localStorage.getItem("eabRootRoute")||"",user_agent:o,user_agent_no_browser:se(o),is_first_visit:h,shopify_country:f,ab_test_assignments:p,ab_test_views:l,is_first_order:null}}async function R(e,t=Qt){try{let r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0});if(!r.ok)throw new Error(`Worker error: ${r.status}`)}catch(r){console.error("[ElevateAB] Error sending analytics:",r)}}async function Xe(e={}){let t=I(e);if(!t)return;let r=e.hasLocalizedPaths??C?.hasLocalizedPaths,o=e.workerUrl??C?.workerUrl,n=V(t,"page_viewed",r);if(!n)return;let s={...n,cart_currency:e.currency};await R(s,o)}async function tr(e){let t=I(e);if(!t)return;let{productId:r,productVendor:o,productPrice:n,productSku:s,currency:a}=e,c=e.hasLocalizedPaths??C?.hasLocalizedPaths,i=e.workerUrl??C?.workerUrl,d=V(t,"product_viewed",c);if(!d)return;let u={...d,cart_currency:a,product_id:_(r),product_vendor:w(o),product_price:m(n),product_sku:w(s)};await R(u,i)}async function rr(e){let t=I(e);if(!t)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i,cartId:d}=e,u=e.hasLocalizedPaths??C?.hasLocalizedPaths,p=e.workerUrl??C?.workerUrl,l=e.storefrontAccessToken??C?.storefrontAccessToken,v=V(t,"product_added_to_cart",u);if(!v)return;let y={...v,cart_currency:i,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:m(s),product_quantity:a,product_sku:w(c)};if(await R(y,p),d&&l)try{let{updateCartAttributes:h}=await import("./cartAttributes-UOPTEP2Q.js");await h(d,{storefrontAccessToken:l})}catch(h){console.error("[ElevateAB] Failed to update cart attributes:",h)}}async function nr(e){let t=I(e);if(!t)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i}=e,d=e.hasLocalizedPaths??C?.hasLocalizedPaths,u=e.workerUrl??C?.workerUrl,p=V(t,"product_removed_from_cart",d);if(!p)return;let l={...p,cart_currency:i,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:m(s),product_quantity:a,product_sku:w(c)};await R(l,u)}async function or(e){let t=I(e);if(!t)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:s}=e,a=e.hasLocalizedPaths??C?.hasLocalizedPaths,c=e.workerUrl??C?.workerUrl,i=V(t,"cart_viewed",a);if(!i)return;let d={...i,cart_currency:s,cart_total_price:m(r),cart_total_quantity:o,cart_items:n?.map(u=>({product_id:_(u.productId),variant_id:_(u.variantId),product_vendor:w(u.productVendor)||"",product_price:m(u.productPrice),product_quantity:u.productQuantity??null,product_sku:w(u.productSku)||""}))};await R(d,c)}async function ar(e){let t=I(e);if(!t)return;let{searchQuery:r,currency:o}=e,n=e.hasLocalizedPaths??C?.hasLocalizedPaths,s=e.workerUrl??C?.workerUrl,a=V(t,"search_submitted",n);if(!a)return;let c={...a,cart_currency:o,search_query:w(r)};await R(c,s)}async function sr(e){let t=I(e);if(!t)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:s,cartDiscountAmount:a,customerId:c,cartItems:i,currency:d}=e,u=e.hasLocalizedPaths??C?.hasLocalizedPaths,p=e.workerUrl??C?.workerUrl,l=V(t,"checkout_started",u);if(!l)return;let v=0,y=i?.map(f=>{let T=f.productQuantity??0;return v+=T,{product_id:_(f.productId),variant_id:_(f.variantId),product_vendor:w(f.productVendor)||"",vendor:w(f.productVendor)||"",product_price:m(f.productPrice),total_price:m(f.productPrice),product_quantity:T,quantity:T,product_sku:w(f.productSku)||"",sku:w(f.productSku)||"",total_discount:m(f.totalDiscount)}})||[],h={...l,cart_currency:d,cart_total_price:m(r),cart_subtotal_price:m(o),cart_total_quantity:v,cart_shipping_price:m(n),cart_tax_amount:m(s),cart_discount_amount:m(a),cart_items:y,customer_id:c};await R(h,p)}async function ir(e){let t=I(e);if(!t)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:s,cartTaxAmount:a,cartDiscountAmount:c,customerId:i,isFirstOrder:d,noteAttributes:u,cartItems:p,currency:l}=e,v=e.hasLocalizedPaths??C?.hasLocalizedPaths,y=e.ordersWorkerUrl??C?.ordersWorkerUrl??Kt,h=V(t,"checkout_completed",v);if(!h)return;let f=0,T=p?.map(g=>{let N=g.productQuantity??0;return f+=N,{product_id:_(g.productId),variant_id:_(g.variantId),product_vendor:w(g.productVendor)||"",vendor:w(g.productVendor)||"",product_price:m(g.productPrice),total_price:m(g.productPrice),product_quantity:N,quantity:N,product_sku:w(g.productSku)||"",sku:w(g.productSku)||"",total_discount:m(g.totalDiscount)}})||[],P={...h,cart_currency:l,cart_total_price:m(o),cart_subtotal_price:m(n),cart_total_quantity:f,cart_shipping_price:m(s),cart_tax_amount:m(a),cart_discount_amount:m(c),cart_items:T,order_id:r,customer_id:i,is_first_order:d??null,note_attributes:u};await R(P,y)}function dr(e){let{storeId:t,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:s=!0,pathname:a}=e,c=cr(null),[i,d]=lr(()=>a||(typeof window<"u"?window.location.pathname:""));Ke(()=>{a&&d(a)},[a]),Ke(()=>{typeof window>"u"||!s||c.current!==i&&(c.current=i,Xe({storeId:t,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[i,t,r,o,n,s])}import H from"react";var X=new Map;function O(e){X.set(e.type,e)}function Z(e){return X.get(e)}function Ze(){return Array.from(X.values())}function et(e){return X.has(e)}function ur(e){try{let o=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function pr(e,t,r,o){if(typeof window>"u"||!e.prices||!t)return;let n=e.prices[t];if(!n)return;let s=n.price?.[r],a=n.compare?.[r],c=o;if(c?.selectorsV2?.length)for(let i of c.selectorsV2){if(i.price&&s){let d=i.price.replace("{{variant}}",t);document.querySelectorAll(d).forEach(p=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(s));p.textContent=l})}if(i.compareAt&&a){let d=i.compareAt.replace("{{variant}}",t);document.querySelectorAll(d).forEach(p=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(a));p.textContent=l})}if(i.saving&&s&&a)for(let d of i.saving){let u=d.selector.replace("{{variant}}",t);document.querySelectorAll(u).forEach(l=>{let v=parseFloat(s),y=parseFloat(a),h=y-v;if(d.isPercentage){let f=Math.round(h/y*100);l.textContent=`${f}%`}else{let f=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(h);l.textContent=f}})}}}var _e={type:"PRICE_PLUS",shouldActivate(e,t){let r=e.data;if(!r)return!1;let{productId:o,productHandle:n}=t,s=n||ur(t.currentUrl),a=o&&r.productIds?.includes(o),c=s&&r.handles?.includes(s);return a||c},applyEffect(e,t,r){pr(t,r.variantId,r.currencyCode||"USD",r.selectors)},getVariantData(e,t,r){let o=e.data;return{prices:t.prices,matchedProductId:r.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function fr(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let s=new URL(t,"https://example.com").pathname;return o.some(a=>A(s,a))}catch{return!1}}var ee={type:"CONTENT",shouldActivate(e,t){return fr(e,t.currentUrl)},getVariantData(e,t,r){let o=e.data;return{content:t.content,pathnames:o?.pathnames,handlerActivated:!0}}};function mr(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let s=new URL(t,"https://example.com").pathname;return o.some(a=>A(s,a))}catch{return!1}}var be={type:"CUSTOM_CODE",shouldActivate(e,t){return mr(e,t.currentUrl)},getVariantData(e,t,r){let o=e.data;return{customCode:t.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};O(_e);O(ye);O(ee);O(be);function gr(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,r=window.location.pathname,o,n=r.match(/\/products\/([^\/\?]+)/);n&&(o=n[1]);let s,c=new URLSearchParams(window.location.search).get("variant");return c&&(s=c),{currentUrl:t,productHandle:o,variantId:s,selectors:e,currencyCode:"USD"}}function yr(e){let{config:t,previewState:r,selectors:o}=te(),[n,s]=H.useState(null),[a,c]=H.useState(!0),i=H.useMemo(()=>t&&t.tests.find(l=>l.testId===e)||null,[t,e]),d=H.useMemo(()=>r||D(),[r]),u=H.useRef(null),p=H.useRef(null);return H.useEffect(()=>{let l=!0;if(t===null)return;if(!i){u.current!==e&&(u.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),l&&c(!1);return}if(!i.enabled&&!d?.isPreview){u.current!==`${e}-disabled`&&(u.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),l&&c(!1);return}let v=S(e);if(!v){l&&c(!1);return}let y=i.variations.find(P=>P.id===v);if(!y){l&&c(!1);return}let h=Z(i.type),f=gr(o),T={...y};if(h?.shouldActivate(i,f)){let P=`${e}-${y.id}`;h.applyEffect&&p.current!==P&&(p.current=P,h.applyEffect(i,y,f));let g=h.getVariantData(i,y,f);T={...T,...g}}return l&&s(T),d?.isPreview||fe(e),l&&c(!1),()=>{l=!1}},[t,i,e,d,o]),{variant:n,isLoading:a,isControl:n?.isControl??!1,isA:n?.isA??!1,isB:n?.isB??!1,isC:n?.isC??!1,isD:n?.isD??!1}}import b,{useRef as wr,useCallback as Cr}from"react";function Ee(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function ke(e,t,r){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(s=>({id:s.testId,type:s.type,enabled:s.enabled}))),!Ee(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let o=e.tests.filter(s=>s.type==="CUSTOM_CODE"&&s.enabled);console.log("[ElevateAB Custom Code] Found",o.length,"CUSTOM_CODE tests");let n=[];o.forEach(s=>{let a=S(s.testId);if(console.log("[ElevateAB Custom Code] Test",s.testId,"assigned variant:",a),!a)return;let c=s.variations.find(i=>i.id===a);if(console.log("[ElevateAB Custom Code] Variation data:",c),!c?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(c.customCode.js||c.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",c.customCode),n.push(c.customCode))}),n.length>0?(console.log("[ElevateAB Custom Code] Applying",n.length,"custom code blocks"),Y(n,r)):console.log("[ElevateAB Custom Code] No custom code to apply")}function hr(e,t,r){typeof window>"u"||ke(e,t,r)}function tt(e,t,r){if(typeof window>"u")return()=>{};let o=()=>{hr(e,t,r)};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}}import{jsx as _r,jsxs as br}from"react/jsx-runtime";var vr="https://d19dz5bxptjmv5.cloudfront.net/headless";function Tr(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function rt(e){return`${vr}/${Tr(e)}.js`}function Pr({storeId:e,storefrontAccessToken:t,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:s}){let[a,c]=b.useState(null),[i,d]=b.useState(null),[u,p]=b.useState(null);b.useEffect(()=>{if(typeof window>"u")return;Pe({storeId:e,storefrontAccessToken:t});let T=D();d(T);let P=B();p(P)},[e,t]);let l=Cr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);b.useEffect(()=>{async function T(){try{let P=typeof window<"u"?D():null,g=null;if(typeof window<"u"&&window.eab_data)g=window.eab_data;else{let F=rt(e);g=await new Promise((xe,nt)=>{let L=document.createElement("script");L.src=F,L.async=!0,L.onload=()=>{let Se=window.eab_data;L.remove(),Se?xe(Se):nt(new Error("Failed to load config: window.eab_data is undefined"))},L.onerror=()=>{L.remove(),xe({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(L)})}if(!g||!g.allTests||Object.keys(g.allTests).length===0){c({tests:[],selectors:void 0}),l();return}if(g.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(g.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),c({tests:[],selectors:void 0}),l();return}if(!(Object.keys(g.allTests||{}).length>0)){c({tests:[],selectors:void 0}),l();return}let z=Ue(g);if(pe(z,P),z.tests.some(F=>F.type==="SPLIT_URL")&&q(z,P))return;c(z),l()}catch(P){console.error("[ElevateAB] Failed to load config:",P),c({tests:[],selectors:void 0}),l()}}T()},[e,l]),b.useEffect(()=>!a||typeof window>"u"||!Q(a)?void 0:(K(a,i,n),Te(a,i,n)),[a,i,n]),b.useEffect(()=>!a||typeof window>"u"||!Ee(a)?void 0:(ke(a,i,n),tt(a,i,n)),[a,i,n]);let v=b.useMemo(()=>({config:a,storeId:e,storefrontAccessToken:t,isPreviewMode:i?.isPreview??!1,previewTestId:i?.previewTestId??null,previewState:i,selectors:a?.selectors,countryCode:u}),[a,e,t,i,u]),y=wr(!1);b.useEffect(()=>{!t&&!y.current&&(y.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let h=b.useMemo(()=>rt(e),[e]),f=b.useMemo(()=>me({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return br(Ae.Provider,{value:v,children:[_r("script",{nonce:n,dangerouslySetInnerHTML:{__html:f}}),s]})}var An="1.1.2";export{Et as CART_ATTRIBUTES_UPDATE_MUTATION,Ht as COUNTRIES,At as ElevateAnalytics,Pr as ElevateProvider,Dt as REGIONS,An as VERSION,je as applyContentChanges,We as applyContentElements,Y as applyCustomCode,pe as assignAllTests,Pt as assignAndPersistVariant,yt as buildEabTestsParam,_t as canAssignToTest,Re as checkFacebookBrowser,st as checkFacebookInstagramBrowser,Le as checkInstagramBrowser,Oe as checkPinterestBrowser,Be as checkTikTokBrowser,it as checkVisitorIdParams,ne as cleanCartToken,St as cleanupCartAttributes,Qe as cleanupContentTests,wt as clearPreviewMode,ee as contentHandler,ct as deleteCookie,qt as detectShopifyCurrency,re as extractCartToken,ot as extractProductId,at as extractProductVariantId,_ as extractShopifyId,Ft as extractShopifyType,Ze as getAllHandlers,S as getAssignedVariant,kt as getCartAttributesPayload,E as getCookie,B as getCountryCode,Vt as getDeviceType,Lt as getGeoLocation,Z as getHandler,k as getJsonCookie,$ as getJsonSessionItem,ae as getPageTypeFromPathname,D as getPreviewState,gt as getPreviewVariation,ue as getReferrerData,de as getSessionId,lt as getSessionItem,me as getSplitUrlBlockingScript,vt as getTestList,Rt as getTrafficSource,se as getUserAgentNoBrowser,le as getVisitorId,Q as hasContentTests,et as hasHandler,Ut as hasSessionView,It as hasUniqueView,ft as hashString,Pe as initAnalytics,ut as initializeSessionId,dt as initializeVisitorId,Me as isCountryExcluded,De as isCountryIncluded,Ct as isInPreviewMode,mt as isPreviewTest,$t as isShopifyGid,Ot as matchesGeoTargeting,A as matchesWildcardPattern,oe as parseAddViewData,K as processContentTests,q as processSplitUrlTests,O as registerHandler,Ce as reprocessContentTests,Ye as restoreOriginalElements,m as roundToTwo,w as sanitizeString,Tt as saveTestList,x as setCookie,He as setCountryCode,Bt as setGeoLocation,pt as setReferrerData,ce as setSessionItem,Te as setupContentTestListeners,bt as shouldShowTest,rr as trackAddToCart,or as trackCartView,ir as trackCheckoutCompleted,sr as trackCheckoutStarted,Xe as trackPageView,tr as trackProductView,nr as trackRemoveFromCart,ar as trackSearchSubmitted,Ve as trackSessionView,Ie as trackUniqueView,fe as trackViews,xt as updateCartAttributes,ht as updateUrlWithTestParams,te as useElevateConfig,yr as useExperiment,dr as usePageViewTracking,ie as uuidv4};
29
+ })();`}function Ne(e){if(!e?.trim())return"";try{let r=`https://${e.trim().replace(/^https?:\/\//,"")}`,o=new URL(r.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function ge(e,t){let r=Ne(e.split("?")[0]);for(let o of t){let n=Ne(o.split("?")[0]);if(r===n)return!0;try{let s=new URL(e).pathname,a=new URL(o,e).pathname;if(s===a)return!0}catch{}}return!1}function Mt(e){return e.data?.redirectBehavior||"redirectAll"}function ze(e){return!!(k("eabRedirectedTests")||{})[e]}function Fe(e){let t=k("eabRedirectedTests")||{};t[e]=!0,x("eabRedirectedTests",JSON.stringify(t))}function Nt(e,t){for(let r of e.tests)if(!(r.type!=="SPLIT_URL"||!r.enabled))for(let o of r.variations){let n=o.splitUrlTestLinks||[];if(n.length!==0&&ge(t,n))return{test:r,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function zt(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let r=t.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let n=t.pathname+t.search;o(n);return}catch{}window.location.href=r}function q(e,t){if(typeof window>"u")return!1;let r=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let n=Nt(e,r);if(!n)return!1;let{test:s,matchedVariation:a,isControlUrl:c}=n,i=s.testId,d=Mt(s),u=S(i);if(!u)return!1;let p=s.variations.find(y=>y.id===u);if(!p)return!1;let l=p.splitUrlTestLinks||[];if(l.length===0||ge(r,l))return!1;switch(d){case"redirectOnlyControlUrl":if(!c||p.isControl)return!1;break;case"redirectOnce":if(ze(i))return!1;Fe(i);break;case"redirectOnceControlUrlOnly":if(!c||ze(i)||p.isControl)return!1;Fe(i);break;default:break}let v=l[0];return zt(v),!0}var ye={type:"SPLIT_URL",shouldActivate(e,t){for(let r of e.variations){let o=r.splitUrlTestLinks||[];if(ge(t.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function _(e){return e?e.includes("gid://")&&e.split("/").pop()||e:""}function Ft(e){return!e||!e.includes("gid://")?null:e.split("/")[3]||null}function $t(e){return!!e&&e.startsWith("gid://shopify/")}function qt(){if(typeof window>"u")return;let e=window.Shopify;if(e?.currency?.active)return e.currency.active}var $e="elv-el-",qe={ELEMENT_NODE:1,TEXT_NODE:3},G=new Map,W=new Map,j=new Map,J=new Map,M=!1;function A(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let r=t.slice(1,-1);return e.includes(r)}if(t.startsWith("*")){let r=t.slice(1);return e.endsWith(r)}return t===e}function ve(){return typeof window>"u"?!1:window.innerWidth<768}function Gt(e){let t="";for(let r=0;r<e.length;r++){let o=e[r];o>="A"&&o<="Z"?(r!==0&&(t+="-"),t+=o.toLowerCase()):t+=o}return t}function Wt(e){return e.nodeType===qe.TEXT_NODE}function he(e){return e.nodeType===qe.ELEMENT_NODE}function we(e,t){G.has(e)||G.set(e,t.cloneNode(!0))}function Ge(e){let t=e;t=t.replace(/&#96;/g,"`").replace(/&#36;/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function We(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,r=e.filter(n=>n.pathnames?.length?n.pathnames.some(s=>A(t,s)):!0);M=ve();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...M&&n.style.sm}:void 0,content:n.content&&M&&n.content.sm?n.content.sm:n.content?.lg}));o.filter(n=>n.content!==void 0).forEach(n=>{(n.applyAll?Array.from(document.querySelectorAll(n.selector)):[document.querySelector(n.selector)].filter(Boolean)).forEach((a,c)=>{if(!a)return;let i=n.applyAll?`${n.selector}-${c}-${a.id||Math.random().toString(36).substr(2,9)}`:n.selector;we(i,a),Wt(a)?a.nodeValue=n.content:he(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let s=document.querySelector(n.selector);!s||!he(s)||(we(n.selector,s),Object.entries(n.style).forEach(([a,c])=>{let i=Gt(a),d=c.toString().includes("!important"),u=c.toString().replace(/\s*!important\s*$/,"");s.style.setProperty(i,u,d?"important":void 0)}))}),o.filter(n=>n.attributes!==void 0).forEach(n=>{let s=document.querySelector(n.selector);!s||!he(s)||(we(n.selector,s),Object.entries(n.attributes).forEach(([a,c])=>{s.setAttribute(a,c)}))})}function je(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(n=>A(t,n)):!0).forEach(o=>{let n=`${$e}${o.id}`;if(J.has(n))return;let s=document.querySelector(o.selector.target);if(!s||s.parentElement?.querySelector(`#${n}`))return;let a=Je(o);o.selector.placement==="after"?s.after(a):o.selector.placement==="before"&&s.before(a),J.set(n,a)})}function Je(e){let t=document.createElement(e.tagName);return t.id=`${$e}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([r,o])=>{t.setAttribute(r,o)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(r=>{let o=Je(r);t.appendChild(o)}),t}function Y(e,t){if(typeof window>"u"||e.length===0)return;let r=window.location.pathname;e.filter(n=>n.pathnames?.length?n.excludePathnames?.length&&n.excludePathnames.some(a=>A(r,a))?!1:n.pathnames.some(s=>A(r,s)):!0).forEach(n=>{n.id&&(n.css&&jt(n.id,n.css),n.js&&Jt(n.id,n.js,t))})}function jt(e,t){let r=`css-${e}`;if(W.has(r)||document.getElementById(r))return;let o=document.createElement("style");o.id=r,o.textContent=Ge(t),document.head.appendChild(o),W.set(r,o)}function Jt(e,t,r){let o=`js-${e}`;if(j.has(o)||document.getElementById(o))return;let n=document.createElement("script");n.id=o,r&&n.setAttribute("nonce",r);let s=Ge(t);n.textContent="(function(){try{"+s+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(n),j.set(o,n)}function Ye(){G.forEach((e,t)=>{let r=document.querySelector(t);r&&r.replaceWith(e.cloneNode(!0))})}function Qe(){W.forEach(e=>e.remove()),W.clear(),j.forEach(e=>e.remove()),j.clear(),J.forEach(e=>e.remove()),J.clear(),G.clear()}function Yt(e,t){let r=[],o=[],n=[];return e.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=S(a.testId);if(!c)return;let i=a.variations.find(d=>d.id===c);i?.content&&(i.content.changes?.length&&r.push(...i.content.changes),i.content.elements?.length&&o.push(...i.content.elements),i.content.customCodes?.length&&n.push(...i.content.customCodes))}),{changes:r,elements:o,blocks:[],customCodes:n}}function Q(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function K(e,t,r){if(typeof window>"u"||!Q(e))return;let o=Yt(e,t);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(We(o.changes),je(o.elements),Y(o.customCodes,r))}function Ce(e,t,r){if(typeof window>"u")return;let o=ve();o!==M&&(Ye(),M=o),K(e,t,r)}function Te(e,t,r){if(typeof window>"u")return()=>{};let o=()=>{ve()!==M&&Ce(e,t,r)},n=()=>{Ce(e,t,r)};return window.addEventListener("resize",o),window.addEventListener("popstate",n),()=>{window.removeEventListener("resize",o),window.removeEventListener("popstate",n),Qe()}}import{useEffect as Ke,useRef as cr,useState as lr}from"react";var Qt="https://bitter-river-9c62.support-67d.workers.dev",Kt="https://d339co84ntxcme.cloudfront.net/Prod/orders",C=null;function Pe(e){C=e}function I(e){let t=e?.storeId||C?.storeId;return t||(console.warn("[ElevateAB] No storeId provided. Call initAnalytics() first or pass storeId to tracking function."),"")}function Xt(e){return Object.entries(e).filter(([,t])=>typeof t=="string").map(([t,r])=>({test_id:t,variant_id:r}))}function Zt(e,t){return Object.entries(e).filter(([r])=>typeof t[r]=="string").map(([r])=>({test_id:r,variant_id:t[r]}))}function er(){return typeof window>"u"?!1:E("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function V(e,t,r){if(typeof window>"u"||er())return null;let o=navigator.userAgent,n=window.location.pathname,s=ae(n,r),{referrer:a,entryPage:c}=ue(),i=oe({referrer:a,entryPage:c,userAgent:o}),d=k("ABTL")||{},u=k("ABAU")||{},p=Xt(d),l=Zt(u,d),v=re(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",f=E("localization")||"";return{pixel_event_id:`sh-${ie()}`,shop_name:e,timestamp:y,event_type:t,client_id:E("_shopify_y")||void 0,visitor_id:le(),session_id:de(),cart_token:ne(v||E("cart")),page_url:window.location.href,page_pathname:n,page_search:window.location.search,referrer_url:a,referrer_source:i?.referrer_source,previous_page:document.referrer,page_entry:c,page_entry_path:i?.page_entry_path,page_type:s,utm_medium:i?.utm_medium,utm_source:i?.utm_source,utm_campaign:i?.utm_campaign,utm_content:i?.utm_content,utm_term:i?.utm_term,gclid:i?.gclid,fbclid:i?.fbclid,pins_campaign_id:i?.pins_campaign_id,epik:i?.epik,browser_info:i?.browser_info,os_info:i?.os_info,device_type:i?.device_type,language:navigator.language,root_route:localStorage.getItem("eabRootRoute")||"",user_agent:o,user_agent_no_browser:se(o),is_first_visit:h,shopify_country:f,ab_test_assignments:p,ab_test_views:l,is_first_order:null}}async function R(e,t=Qt){try{let r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0});if(!r.ok)throw new Error(`Worker error: ${r.status}`)}catch(r){console.error("[ElevateAB] Error sending analytics:",r)}}async function Xe(e={}){let t=I(e);if(!t)return;let r=e.hasLocalizedPaths??C?.hasLocalizedPaths,o=e.workerUrl??C?.workerUrl,n=V(t,"page_viewed",r);if(!n)return;let s={...n,cart_currency:e.currency};await R(s,o)}async function tr(e){let t=I(e);if(!t)return;let{productId:r,productVendor:o,productPrice:n,productSku:s,currency:a}=e,c=e.hasLocalizedPaths??C?.hasLocalizedPaths,i=e.workerUrl??C?.workerUrl,d=V(t,"product_viewed",c);if(!d)return;let u={...d,cart_currency:a,product_id:_(r),product_vendor:w(o),product_price:m(n),product_sku:w(s)};await R(u,i)}async function rr(e){let t=I(e);if(!t)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i,cartId:d}=e,u=e.hasLocalizedPaths??C?.hasLocalizedPaths,p=e.workerUrl??C?.workerUrl,l=e.storefrontAccessToken??C?.storefrontAccessToken,v=V(t,"product_added_to_cart",u);if(!v)return;let y={...v,cart_currency:i,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:m(s),product_quantity:a,product_sku:w(c)};if(await R(y,p),d&&l)try{let{updateCartAttributes:h}=await import("./cartAttributes-UOPTEP2Q.js");await h(d,{storefrontAccessToken:l})}catch(h){console.error("[ElevateAB] Failed to update cart attributes:",h)}}async function nr(e){let t=I(e);if(!t)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i}=e,d=e.hasLocalizedPaths??C?.hasLocalizedPaths,u=e.workerUrl??C?.workerUrl,p=V(t,"product_removed_from_cart",d);if(!p)return;let l={...p,cart_currency:i,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:m(s),product_quantity:a,product_sku:w(c)};await R(l,u)}async function or(e){let t=I(e);if(!t)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:s}=e,a=e.hasLocalizedPaths??C?.hasLocalizedPaths,c=e.workerUrl??C?.workerUrl,i=V(t,"cart_viewed",a);if(!i)return;let d={...i,cart_currency:s,cart_total_price:m(r),cart_total_quantity:o,cart_items:n?.map(u=>({product_id:_(u.productId),variant_id:_(u.variantId),product_vendor:w(u.productVendor)||"",product_price:m(u.productPrice),product_quantity:u.productQuantity??null,product_sku:w(u.productSku)||""}))};await R(d,c)}async function ar(e){let t=I(e);if(!t)return;let{searchQuery:r,currency:o}=e,n=e.hasLocalizedPaths??C?.hasLocalizedPaths,s=e.workerUrl??C?.workerUrl,a=V(t,"search_submitted",n);if(!a)return;let c={...a,cart_currency:o,search_query:w(r)};await R(c,s)}async function sr(e){let t=I(e);if(!t)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:s,cartDiscountAmount:a,customerId:c,cartItems:i,currency:d}=e,u=e.hasLocalizedPaths??C?.hasLocalizedPaths,p=e.workerUrl??C?.workerUrl,l=V(t,"checkout_started",u);if(!l)return;let v=0,y=i?.map(f=>{let T=f.productQuantity??0;return v+=T,{product_id:_(f.productId),variant_id:_(f.variantId),product_vendor:w(f.productVendor)||"",vendor:w(f.productVendor)||"",product_price:m(f.productPrice),total_price:m(f.productPrice),product_quantity:T,quantity:T,product_sku:w(f.productSku)||"",sku:w(f.productSku)||"",total_discount:m(f.totalDiscount)}})||[],h={...l,cart_currency:d,cart_total_price:m(r),cart_subtotal_price:m(o),cart_total_quantity:v,cart_shipping_price:m(n),cart_tax_amount:m(s),cart_discount_amount:m(a),cart_items:y,customer_id:c};await R(h,p)}async function ir(e){let t=I(e);if(!t)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:s,cartTaxAmount:a,cartDiscountAmount:c,customerId:i,isFirstOrder:d,noteAttributes:u,cartItems:p,currency:l}=e,v=e.hasLocalizedPaths??C?.hasLocalizedPaths,y=e.ordersWorkerUrl??C?.ordersWorkerUrl??Kt,h=V(t,"checkout_completed",v);if(!h)return;let f=0,T=p?.map(g=>{let N=g.productQuantity??0;return f+=N,{product_id:_(g.productId),variant_id:_(g.variantId),product_vendor:w(g.productVendor)||"",vendor:w(g.productVendor)||"",product_price:m(g.productPrice),total_price:m(g.productPrice),product_quantity:N,quantity:N,product_sku:w(g.productSku)||"",sku:w(g.productSku)||"",total_discount:m(g.totalDiscount)}})||[],P={...h,cart_currency:l,cart_total_price:m(o),cart_subtotal_price:m(n),cart_total_quantity:f,cart_shipping_price:m(s),cart_tax_amount:m(a),cart_discount_amount:m(c),cart_items:T,order_id:r,customer_id:i,is_first_order:d??null,note_attributes:u};await R(P,y)}function dr(e){let{storeId:t,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:s=!0,pathname:a}=e,c=cr(null),[i,d]=lr(()=>a||(typeof window<"u"?window.location.pathname:""));Ke(()=>{a&&d(a)},[a]),Ke(()=>{typeof window>"u"||!s||c.current!==i&&(c.current=i,Xe({storeId:t,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[i,t,r,o,n,s])}import H from"react";var X=new Map;function O(e){X.set(e.type,e)}function Z(e){return X.get(e)}function Ze(){return Array.from(X.values())}function et(e){return X.has(e)}function ur(e){try{let o=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function pr(e,t,r,o){if(typeof window>"u"||!e.prices||!t)return;let n=e.prices[t];if(!n)return;let s=n.price?.[r],a=n.compare?.[r],c=o;if(c?.selectorsV2?.length)for(let i of c.selectorsV2){if(i.price&&s){let d=i.price.replace("{{variant}}",t);document.querySelectorAll(d).forEach(p=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(s));p.textContent=l})}if(i.compareAt&&a){let d=i.compareAt.replace("{{variant}}",t);document.querySelectorAll(d).forEach(p=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(a));p.textContent=l})}if(i.saving&&s&&a)for(let d of i.saving){let u=d.selector.replace("{{variant}}",t);document.querySelectorAll(u).forEach(l=>{let v=parseFloat(s),y=parseFloat(a),h=y-v;if(d.isPercentage){let f=Math.round(h/y*100);l.textContent=`${f}%`}else{let f=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(h);l.textContent=f}})}}}var _e={type:"PRICE_PLUS",shouldActivate(e,t){let r=e.data;if(!r)return!1;let{productId:o,productHandle:n}=t,s=n||ur(t.currentUrl),a=o&&r.productIds?.includes(o),c=s&&r.handles?.includes(s);return a||c},applyEffect(e,t,r){pr(t,r.variantId,r.currencyCode||"USD",r.selectors)},getVariantData(e,t,r){let o=e.data;return{prices:t.prices,matchedProductId:r.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function fr(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let s=new URL(t,"https://example.com").pathname;return o.some(a=>A(s,a))}catch{return!1}}var ee={type:"CONTENT",shouldActivate(e,t){return fr(e,t.currentUrl)},getVariantData(e,t,r){let o=e.data;return{content:t.content,pathnames:o?.pathnames,handlerActivated:!0}}};function mr(e,t){let o=e.data?.pathnames||[];if(!o.length)return!0;try{let s=new URL(t,"https://example.com").pathname;return o.some(a=>A(s,a))}catch{return!1}}var be={type:"CUSTOM_CODE",shouldActivate(e,t){return mr(e,t.currentUrl)},getVariantData(e,t,r){let o=e.data;return{customCode:t.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};O(_e);O(ye);O(ee);O(be);function gr(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,r=window.location.pathname,o,n=r.match(/\/products\/([^\/\?]+)/);n&&(o=n[1]);let s,c=new URLSearchParams(window.location.search).get("variant");return c&&(s=c),{currentUrl:t,productHandle:o,variantId:s,selectors:e,currencyCode:"USD"}}function yr(e){let{config:t,previewState:r,selectors:o}=te(),[n,s]=H.useState(null),[a,c]=H.useState(!0),i=H.useMemo(()=>t&&t.tests.find(l=>l.testId===e)||null,[t,e]),d=H.useMemo(()=>r||D(),[r]),u=H.useRef(null),p=H.useRef(null);return H.useEffect(()=>{let l=!0;if(t===null)return;if(!i){u.current!==e&&(u.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),l&&c(!1);return}if(!i.enabled&&!d?.isPreview){u.current!==`${e}-disabled`&&(u.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),l&&c(!1);return}let v=S(e);if(!v){l&&c(!1);return}let y=i.variations.find(P=>P.id===v);if(!y){l&&c(!1);return}let h=Z(i.type),f=gr(o),T={...y};if(h?.shouldActivate(i,f)){let P=`${e}-${y.id}`;h.applyEffect&&p.current!==P&&(p.current=P,h.applyEffect(i,y,f));let g=h.getVariantData(i,y,f);T={...T,...g}}return l&&s(T),d?.isPreview||fe(e),l&&c(!1),()=>{l=!1}},[t,i,e,d,o]),{variant:n,isLoading:a,isControl:n?.isControl??!1,isA:n?.isA??!1,isB:n?.isB??!1,isC:n?.isC??!1,isD:n?.isD??!1}}import b,{useRef as wr,useCallback as Cr}from"react";function Ee(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function ke(e,t,r){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(s=>({id:s.testId,type:s.type,enabled:s.enabled}))),!Ee(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let o=e.tests.filter(s=>s.type==="CUSTOM_CODE"&&s.enabled);console.log("[ElevateAB Custom Code] Found",o.length,"CUSTOM_CODE tests");let n=[];o.forEach(s=>{let a=S(s.testId);if(console.log("[ElevateAB Custom Code] Test",s.testId,"assigned variant:",a),!a)return;let c=s.variations.find(i=>i.id===a);if(console.log("[ElevateAB Custom Code] Variation data:",c),!c?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(c.customCode.js||c.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",c.customCode),n.push(c.customCode))}),n.length>0?(console.log("[ElevateAB Custom Code] Applying",n.length,"custom code blocks"),Y(n,r)):console.log("[ElevateAB Custom Code] No custom code to apply")}function hr(e,t,r){typeof window>"u"||ke(e,t,r)}function tt(e,t,r){if(typeof window>"u")return()=>{};let o=()=>{hr(e,t,r)};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}}import{jsx as _r,jsxs as br}from"react/jsx-runtime";var vr="https://ds0wlyksfn0sb.cloudfront.net/headless";function Tr(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function rt(e){return`${vr}/${Tr(e)}.js`}function Pr({storeId:e,storefrontAccessToken:t,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:s}){let[a,c]=b.useState(null),[i,d]=b.useState(null),[u,p]=b.useState(null);b.useEffect(()=>{if(typeof window>"u")return;Pe({storeId:e,storefrontAccessToken:t});let T=D();d(T);let P=B();p(P)},[e,t]);let l=Cr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);b.useEffect(()=>{async function T(){try{let P=typeof window<"u"?D():null,g=null;if(typeof window<"u"&&window.eab_data)g=window.eab_data;else{let F=rt(e);g=await new Promise((xe,nt)=>{let L=document.createElement("script");L.src=F,L.async=!0,L.onload=()=>{let Se=window.eab_data;L.remove(),Se?xe(Se):nt(new Error("Failed to load config: window.eab_data is undefined"))},L.onerror=()=>{L.remove(),xe({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(L)})}if(!g||!g.allTests||Object.keys(g.allTests).length===0){c({tests:[],selectors:void 0}),l();return}if(g.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(g.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),c({tests:[],selectors:void 0}),l();return}if(!(Object.keys(g.allTests||{}).length>0)){c({tests:[],selectors:void 0}),l();return}let z=Ue(g);if(pe(z,P),z.tests.some(F=>F.type==="SPLIT_URL")&&q(z,P))return;c(z),l()}catch(P){console.error("[ElevateAB] Failed to load config:",P),c({tests:[],selectors:void 0}),l()}}T()},[e,l]),b.useEffect(()=>!a||typeof window>"u"||!Q(a)?void 0:(K(a,i,n),Te(a,i,n)),[a,i,n]),b.useEffect(()=>!a||typeof window>"u"||!Ee(a)?void 0:(ke(a,i,n),tt(a,i,n)),[a,i,n]);let v=b.useMemo(()=>({config:a,storeId:e,storefrontAccessToken:t,isPreviewMode:i?.isPreview??!1,previewTestId:i?.previewTestId??null,previewState:i,selectors:a?.selectors,countryCode:u}),[a,e,t,i,u]),y=wr(!1);b.useEffect(()=>{!t&&!y.current&&(y.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let h=b.useMemo(()=>rt(e),[e]),f=b.useMemo(()=>me({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return br(Ae.Provider,{value:v,children:[_r("script",{nonce:n,dangerouslySetInnerHTML:{__html:f}}),s]})}var An="1.1.2";export{Et as CART_ATTRIBUTES_UPDATE_MUTATION,Ht as COUNTRIES,At as ElevateAnalytics,Pr as ElevateProvider,Dt as REGIONS,An as VERSION,We as applyContentChanges,je as applyContentElements,Y as applyCustomCode,pe as assignAllTests,Pt as assignAndPersistVariant,yt as buildEabTestsParam,_t as canAssignToTest,Re as checkFacebookBrowser,st as checkFacebookInstagramBrowser,Le as checkInstagramBrowser,Oe as checkPinterestBrowser,Be as checkTikTokBrowser,it as checkVisitorIdParams,ne as cleanCartToken,St as cleanupCartAttributes,Qe as cleanupContentTests,wt as clearPreviewMode,ee as contentHandler,ct as deleteCookie,qt as detectShopifyCurrency,re as extractCartToken,ot as extractProductId,at as extractProductVariantId,_ as extractShopifyId,Ft as extractShopifyType,Ze as getAllHandlers,S as getAssignedVariant,kt as getCartAttributesPayload,E as getCookie,B as getCountryCode,Vt as getDeviceType,Lt as getGeoLocation,Z as getHandler,k as getJsonCookie,$ as getJsonSessionItem,ae as getPageTypeFromPathname,D as getPreviewState,gt as getPreviewVariation,ue as getReferrerData,de as getSessionId,lt as getSessionItem,me as getSplitUrlBlockingScript,vt as getTestList,Rt as getTrafficSource,se as getUserAgentNoBrowser,le as getVisitorId,Q as hasContentTests,et as hasHandler,Ut as hasSessionView,It as hasUniqueView,ft as hashString,Pe as initAnalytics,ut as initializeSessionId,dt as initializeVisitorId,Me as isCountryExcluded,De as isCountryIncluded,Ct as isInPreviewMode,mt as isPreviewTest,$t as isShopifyGid,Ot as matchesGeoTargeting,A as matchesWildcardPattern,oe as parseAddViewData,K as processContentTests,q as processSplitUrlTests,O as registerHandler,Ce as reprocessContentTests,Ye as restoreOriginalElements,m as roundToTwo,w as sanitizeString,Tt as saveTestList,x as setCookie,He as setCountryCode,Bt as setGeoLocation,pt as setReferrerData,ce as setSessionItem,Te as setupContentTestListeners,bt as shouldShowTest,rr as trackAddToCart,or as trackCartView,ir as trackCheckoutCompleted,sr as trackCheckoutStarted,Xe as trackPageView,tr as trackProductView,nr as trackRemoveFromCart,ar as trackSearchSubmitted,Ve as trackSessionView,Ie as trackUniqueView,fe as trackViews,xt as updateCartAttributes,ht as updateUrlWithTestParams,te as useElevateConfig,yr as useExperiment,dr as usePageViewTracking,ie as uuidv4};
30
30
  //# sourceMappingURL=index.js.map