@elevateab/sdk 1.4.6 → 1.4.7
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/cartAttributes-DBBVZUFZ.js +2 -0
- package/dist/cartAttributes-V5XBJEGE.js +3 -0
- package/dist/chunk-5TU25234.js +18 -0
- package/dist/chunk-5TU25234.js.map +1 -0
- package/dist/{chunk-E3BNNKGR.js → chunk-7OUZ2CQ5.js} +2 -2
- package/dist/chunk-GGAESORE.js +19 -0
- package/dist/chunk-GGAESORE.js.map +1 -0
- package/dist/hydrogen.cjs +2 -2
- package/dist/hydrogen.cjs.map +1 -1
- package/dist/hydrogen.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +3 -3
- package/dist/next.cjs.map +1 -1
- package/dist/next.js +2 -2
- package/dist/next.js.map +1 -1
- package/package.json +1 -1
- package/dist/cartAttributes-UOPTEP2Q.js +0 -2
- package/dist/cartAttributes-YUZURH3L.js +0 -3
- package/dist/chunk-B2OIRKOZ.js +0 -18
- package/dist/chunk-B2OIRKOZ.js.map +0 -1
- package/dist/chunk-QIFYO7SY.js +0 -19
- package/dist/chunk-QIFYO7SY.js.map +0 -1
- /package/dist/{cartAttributes-UOPTEP2Q.js.map → cartAttributes-DBBVZUFZ.js.map} +0 -0
- /package/dist/{cartAttributes-YUZURH3L.js.map → cartAttributes-V5XBJEGE.js.map} +0 -0
- /package/dist/{chunk-E3BNNKGR.js.map → chunk-7OUZ2CQ5.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Lt,b as
|
|
1
|
+
import{a as Lt,b as it,c as w,d as g,e as ie,f as se,g as st,h as ct,i as ce,j as lt,k as ut,l as le,m as dt,n as De}from"./chunk-7OUZ2CQ5.js";import{A as be,B as yt,C as ke,D as Se,E as xe,F as Ae,G as S,H as Ue,I as Ie,J as Le,K as ht,L as Re,M as Ve,N as He,O as Oe,c as pt,d as V,e as k,f as H,g as ue,h as de,i as pe,j as fe,k as me,l as ft,m as ge,n as mt,o as ye,p as gt,q as he,r as Rt,s as F,t as we,u as Ce,v as ve,w as Te,x as Pe,y as _e,z as Ee}from"./chunk-5TU25234.js";function Be(){if(typeof navigator>"u")return"desktop";let t=navigator.userAgent||navigator.vendor||window.opera||"",e=t.toLowerCase();return/windows nt.*tablet pc|pixelbook/i.test(t)||/(?:macintosh|windows nt|win(?:95|98)|linux x86_64)/i.test(t)&&!/android|mobile|tablet|ipad|iphone|ipod/i.test(e)?"desktop":/ipad|playbook|tablet|kindle|nexus (7|10)|xoom|sm-t\d+|galaxy tab|tb-\d+|tb\d+[a-z]+|lenovo.*tb|dtab|ideatab|mediapad|matepad|honor.*pad|pad\s+\d+|mi\s+pad|redmi.*pad|xiaomi.*pad|oppo.*pad|oneplus.*pad|opd\d+|tcl.*tab|9\d{3}[a-z]|kobo|archos.*5(?!\d)|ereader|droipad/i.test(t)||/android(?!.*mobile)/i.test(e)&&!/dalvik.*miui|pocophone|mi\s+mix|edge\s+\d+|sm-g9\d+|pixel\s+\d|pixel\s+fold|advan\s+\d{4}/i.test(t)?"tablet":/android.+mobile|iphone|ipod|windows phone|blackberry|mobile|phone|kaios/i.test(e)||/^mobile;/i.test(t)||/dalvik.*miui|pocophone|mi\s+mix|pixel\s+\d|pixel\s+fold/i.test(t)?"mobile":"desktop"}function Vt(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i.test(t)}function Ht(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/(instagram)[\/ ]([-\w\.]+)/i.test(t)}function Ot(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/musical_ly/i.test(t)}function Dt(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/(pinterest)[\/ ]([-\w\.]+)/i.test(t)}function Ne(){if(typeof window>"u")return"direct";let t=(document.referrer||"").toLowerCase(),e=t?new URL(t).hostname.replace("www.",""):"",r=window.location.hostname,o=Vt(),n=Ht(),i=Ot(),a=Dt();return o||["facebook.com","fb.com","fb.me","m.facebook.com","l.facebook.com","lm.facebook.com"].includes(e)?"facebook":n||e.includes("instagram")?"instagram":i||["tiktok.com","pangleglobal.com","ads.tiktok.com"].includes(e)?"tiktok":a||e.includes("pinterest")||e==="pin.it"?"pinterest":e.includes("google")?"google":!t||r===e?"direct":"other"}var A={SHOPIFY_LOCALIZATION:"localization",EAB_COUNTRY:"eabCountryCode",EAB_GEO:"eabGeoLocation"};function O(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search).get("country");if(e)return V(A.EAB_COUNTRY,e.toUpperCase()),e.toUpperCase();let r=k(A.SHOPIFY_LOCALIZATION);if(r)return r.toUpperCase();let o=k(A.EAB_COUNTRY);if(o)return o.toUpperCase();if(typeof localStorage<"u"){let n=localStorage.getItem(A.EAB_COUNTRY);if(n)return n.toUpperCase()}return null}function Me(){let t=O(),e=k(A.EAB_GEO);if(e)try{let r=JSON.parse(e);return{country:r.country||t,region:r.region,city:r.city}}catch{}return{country:t}}function Bt(t){let e=t.toUpperCase();V(A.EAB_COUNTRY,e),typeof localStorage<"u"&&localStorage.setItem(A.EAB_COUNTRY,e)}function ze(t){t.country&&Bt(t.country),V(A.EAB_GEO,JSON.stringify(t))}function Nt(t,e){let r=e??O();return r?t.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function Mt(t,e){let r=e??O();return r?t.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function Fe(t){let e=O();return!t.includeCountries?.length&&!t.excludeCountries?.length?!0:!e||t.excludeCountries?.length&&Mt(t.excludeCountries,e)?!1:t.includeCountries?.length?Nt(t.includeCountries,e):!0}var $e={US:"US",CA:"CA",GB:"GB",AU:"AU",DE:"DE",FR:"FR",JP:"JP",MX:"MX",BR:"BR",IN:"IN"},qe={NORTH_AMERICA:["US","CA","MX"],EUROPE:["GB","DE","FR","IT","ES","NL","BE","AT","CH","PL","SE","NO","DK","FI","IE","PT"],APAC:["AU","NZ","JP","KR","SG","HK","TW","TH","MY","PH","ID","VN","IN"],LATAM:["MX","BR","AR","CL","CO","PE"]};var X="eab:navigate",Z=!1,wt=0,J=null,Y=null;function Ge(){typeof window>"u"||(wt++,!Z&&(Z=!0,J=history.pushState.bind(history),Y=history.replaceState.bind(history),history.pushState=function(...t){J(...t),window.dispatchEvent(new Event(X))},history.replaceState=function(...t){Y(...t),window.dispatchEvent(new Event(X))}))}function We(){typeof window>"u"||(wt--,!(wt>0||!Z)&&(J&&(history.pushState=J,J=null),Y&&(history.replaceState=Y,Y=null),Z=!1))}function $(t){if(typeof window>"u")return()=>{};let e=window.location.href,r=()=>{let o=window.location.href;o!==e&&(e=o,t())};return Ge(),window.addEventListener(X,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(X,r),window.removeEventListener("popstate",r),We()}}function Ct(t){let{configUrl:e,timeout:r=2e3}=t;return`(function(){
|
|
2
2
|
if(new URLSearchParams(location.search).get('abtr')==='true')return;
|
|
3
3
|
|
|
4
4
|
var style=document.createElement('style');
|
|
@@ -26,5 +26,5 @@ import{a as Lt,b as st,c as w,d as g,e as de,f as ue,g as ct,h as lt,i as pe,j a
|
|
|
26
26
|
if(window.__eab_reveal)window.__eab_reveal();
|
|
27
27
|
};
|
|
28
28
|
document.head.appendChild(script);
|
|
29
|
-
})();`}function Gt(t){if(!t?.trim())return"";try{let r=`https://${t.trim().replace(/^https?:\/\//,"")}`,o=new URL(r.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return t.trim().replace(/\/+$/,"")}}function Pt(t,e){let r=Gt(t.split("?")[0]);for(let o of e){let n=Gt(o.split("?")[0]);if(r===n)return!0;try{let i=new URL(t).pathname,a=new URL(o,t).pathname;if(i===a)return!0}catch{}}return!1}function je(t){return t.data?.redirectBehavior||"redirectAll"}function Wt(t){return!!(S("eabRedirectedTests")||{})[t]}function jt(t){let e=S("eabRedirectedTests")||{};e[t]=!0,x("eabRedirectedTests",JSON.stringify(e))}function Je(t,e){for(let r of t.tests)if(!(r.type!=="SPLIT_URL"||!r.enabled))for(let o of r.variations){let n=o.splitUrlTestLinks||[];if(n.length!==0&&Pt(e,n))return{test:r,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function Ye(t){if(typeof window>"u")return;let e=new URL(t,window.location.origin);e.searchParams.set("abtr","true");let r=e.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let n=e.pathname+e.search;o(n);return}catch{}window.location.href=r}function Q(t,e){if(typeof window>"u")return!1;let r=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let n=Je(t,r);if(!n)return!1;let{test:i,matchedVariation:a,isControlUrl:c}=n,s=i.testId,d=je(i),u=A(s);if(!u)return!1;let f=i.variations.find(y=>y.id===u);if(!f)return!1;let l=f.splitUrlTestLinks||[];if(l.length===0||Pt(r,l))return!1;switch(d){case"redirectOnlyControlUrl":if(!c||f.isControl)return!1;break;case"redirectOnce":if(Wt(s))return!1;jt(s);break;case"redirectOnceControlUrlOnly":if(!c||Wt(s)||f.isControl)return!1;jt(s);break;default:break}let v=l[0];return Ye(v),!0}function Jt(t){return t.tests.some(e=>e.type==="SPLIT_URL"&&e.enabled)}var _t={type:"SPLIT_URL",shouldActivate(t,e){for(let r of t.variations){let o=r.splitUrlTestLinks||[];if(Pt(e.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function _(t){return t?t.includes("gid://")&&t.split("/").pop()||t:""}function Qe(t){return!t||!t.includes("gid://")?null:t.split("/")[3]||null}function Ke(t){return!!t&&t.startsWith("gid://shopify/")}function Xe(){if(typeof window>"u")return;let t=window.Shopify;if(t?.currency?.active)return t.currency.active}var Yt="elv-el-",Qt={ELEMENT_NODE:1,TEXT_NODE:3},et=new Map,$=new Map,G=new Map,W=new Map,j=!1;function U(t,e){if(e==="*")return!0;if(e.startsWith("*")&&e.endsWith("*")){let r=e.slice(1,-1);return t.includes(r)}if(e.startsWith("*")){let r=e.slice(1);return t.endsWith(r)}return e===t}function St(){return typeof window>"u"?!1:window.innerWidth<768}function Ze(t){let e="";for(let r=0;r<t.length;r++){let o=t[r];o>="A"&&o<="Z"?(r!==0&&(e+="-"),e+=o.toLowerCase()):e+=o}return e}function tr(t){return t.nodeType===Qt.TEXT_NODE}function bt(t){return t.nodeType===Qt.ELEMENT_NODE}function Et(t,e){et.has(t)||et.set(t,e.cloneNode(!0))}function Kt(t){let e=t;e=e.replace(/`/g,"`").replace(/$/g,"$");try{e=JSON.parse('"'+e+'"')}catch{}return e}function Xt(t){if(typeof window>"u"||t.length===0)return;let e=window.location.pathname,r=t.filter(n=>n.pathnames?.length?n.pathnames.some(i=>U(e,i)):!0);j=St();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...j&&n.style.sm}:void 0,content:n.content&&j&&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 s=n.applyAll?`${n.selector}-${c}-${a.id||Math.random().toString(36).substr(2,9)}`:n.selector;Et(s,a),tr(a)?a.nodeValue=n.content:bt(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let i=document.querySelector(n.selector);!i||!bt(i)||(Et(n.selector,i),Object.entries(n.style).forEach(([a,c])=>{let s=Ze(a),d=c.toString().includes("!important"),u=c.toString().replace(/\s*!important\s*$/,"");i.style.setProperty(s,u,d?"important":void 0)}))}),o.filter(n=>n.attributes!==void 0).forEach(n=>{let i=document.querySelector(n.selector);!i||!bt(i)||(Et(n.selector,i),Object.entries(n.attributes).forEach(([a,c])=>{i.setAttribute(a,c)}))})}function Zt(t){if(typeof window>"u"||t.length===0)return;let e=window.location.pathname;t.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(n=>U(e,n)):!0).forEach(o=>{let n=`${Yt}${o.id}`,i=W.get(n);if(i&&!document.contains(i)&&W.delete(n),W.has(n))return;let a=document.querySelector(o.selector.target);if(!a||a.parentElement?.querySelector(`#${n}`))return;let c=te(o);o.selector.placement==="after"?a.after(c):o.selector.placement==="before"&&a.before(c),W.set(n,c)})}function te(t){let e=document.createElement(t.tagName);return e.id=`${Yt}${t.id}`,t.style&&Object.assign(e.style,t.style),t.attributes&&Object.entries(t.attributes).forEach(([r,o])=>{e.setAttribute(r,o)}),t.kind==="text"&&t.content&&(e.innerText=t.content),t.kind==="container"&&t.childrens&&t.childrens.forEach(r=>{let o=te(r);e.appendChild(o)}),e}function rt(t,e){if(typeof window>"u"||t.length===0)return;let r=window.location.pathname;t.filter(n=>n.pathnames?.length?n.excludePathnames?.length&&n.excludePathnames.some(a=>U(r,a))?!1:n.pathnames.some(i=>U(r,i)):!0).forEach(n=>{n.id&&(n.css&&er(n.id,n.css),n.js&&rr(n.id,n.js,e))})}function er(t,e){let r=`css-${t}`,o=$.get(r);if(o&&!document.contains(o)&&$.delete(r),$.has(r)||document.getElementById(r))return;let n=document.createElement("style");n.id=r,n.textContent=Kt(e),document.head.appendChild(n),$.set(r,n)}function rr(t,e,r){let o=`js-${t}`,n=G.get(o);if(n&&!document.contains(n)&&G.delete(o),G.has(o)||document.getElementById(o))return;let i=document.createElement("script");i.id=o,r&&i.setAttribute("nonce",r);let a=Kt(e);i.textContent="(function(){try{"+a+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(i),G.set(o,i)}function ee(){et.forEach((t,e)=>{let r=document.querySelector(e);r&&r.replaceWith(t.cloneNode(!0))})}function re(){$.forEach(t=>t.remove()),$.clear(),G.forEach(t=>t.remove()),G.clear(),W.forEach(t=>t.remove()),W.clear(),et.clear()}function nr(t,e){let r=[],o=[],n=[];return t.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=A(a.testId);if(!c)return;let s=a.variations.find(d=>d.id===c);s?.content&&(s.content.changes?.length&&r.push(...s.content.changes),s.content.elements?.length&&o.push(...s.content.elements),s.content.customCodes?.length&&n.push(...s.content.customCodes))}),{changes:r,elements:o,blocks:[],customCodes:n}}function K(t){return t.tests.some(e=>e.type==="CONTENT"&&e.enabled)}function nt(t,e,r){if(typeof window>"u"||!K(t))return;let o=nr(t,e);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(Xt(o.changes),Zt(o.elements),rt(o.customCodes,r))}function kt(t,e,r){if(typeof window>"u")return;let o=St();o!==j&&(ee(),j=o),nt(t,e,r)}function xt(t,e,r,o=!0){if(typeof window>"u")return()=>{};let n=()=>{St()!==j&&kt(t,e,r)};window.addEventListener("resize",n);let i=()=>{};return o&&(i=q(()=>{kt(t,e,r)})),()=>{window.removeEventListener("resize",n),i(),re()}}import{useEffect as ne,useRef as yr,useState as hr}from"react";var or="https://bitter-river-9c62.support-67d.workers.dev",ar="https://d339co84ntxcme.cloudfront.net/Prod/orders",C=null;function At(t){C=t}function V(t){let e=t?.storeId||C?.storeId;return e||(console.warn("[ElevateAB] No storeId provided. Call initAnalytics() first or pass storeId to tracking function."),"")}function ir(t){return Object.entries(t).filter(([,e])=>typeof e=="string").map(([e,r])=>({test_id:e,variant_id:r}))}function sr(t,e){return Object.entries(t).filter(([r])=>typeof e[r]=="string").map(([r])=>({test_id:r,variant_id:e[r]}))}function cr(){return typeof window>"u"?!1:k("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function R(t,e,r){if(typeof window>"u"||cr())return null;let o=navigator.userAgent,n=window.location.pathname,i=ut(n,r),{referrer:a,entryPage:c}=ht(),s=dt({referrer:a,entryPage:c,userAgent:o}),d=S("ABTL")||{},u=S("ABAU")||{},f=ir(d),l=sr(u,d),v=ct(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",m=k("localization")||"";return{pixel_event_id:`sh-${ft()}`,shop_name:t,timestamp:y,event_type:e,client_id:k("_shopify_y")||void 0,visitor_id:gt(),session_id:yt(),cart_token:lt(v||k("cart")),page_url:window.location.href,page_pathname:n,page_search:window.location.search,referrer_url:a,referrer_source:s?.referrer_source,previous_page:document.referrer,page_entry:c,page_entry_path:s?.page_entry_path,page_type:i,utm_medium:s?.utm_medium,utm_source:s?.utm_source,utm_campaign:s?.utm_campaign,utm_content:s?.utm_content,utm_term:s?.utm_term,gclid:s?.gclid,fbclid:s?.fbclid,pins_campaign_id:s?.pins_campaign_id,epik:s?.epik,browser_info:s?.browser_info,os_info:s?.os_info,device_type:s?.device_type,language:navigator.language,root_route:localStorage.getItem("eabRootRoute")||"",user_agent:o,user_agent_no_browser:pt(o),is_first_visit:h,shopify_country:m,ab_test_assignments:f,ab_test_views:l,is_first_order:null}}async function L(t,e=or){try{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0});if(!r.ok)throw new Error(`Worker error: ${r.status}`)}catch(r){console.error("[ElevateAB] Error sending analytics:",r)}}async function oe(t={}){let e=V(t);if(!e)return;let r=t.hasLocalizedPaths??C?.hasLocalizedPaths,o=t.workerUrl??C?.workerUrl,n=R(e,"page_viewed",r);if(!n)return;let i={...n,cart_currency:t.currency};await L(i,o)}async function lr(t){let e=V(t);if(!e)return;let{productId:r,productVendor:o,productPrice:n,productSku:i,currency:a}=t,c=t.hasLocalizedPaths??C?.hasLocalizedPaths,s=t.workerUrl??C?.workerUrl,d=R(e,"product_viewed",c);if(!d)return;let u={...d,cart_currency:a,product_id:_(r),product_vendor:w(o),product_price:g(n),product_sku:w(i)};await L(u,s)}async function dr(t){let e=V(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:i,productQuantity:a,productSku:c,currency:s,cartId:d}=t,u=t.hasLocalizedPaths??C?.hasLocalizedPaths,f=t.workerUrl??C?.workerUrl,l=t.storefrontAccessToken??C?.storefrontAccessToken,v=R(e,"product_added_to_cart",u);if(!v)return;let y={...v,cart_currency:s,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:g(i),product_quantity:a,product_sku:w(c)};if(await L(y,f),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 ur(t){let e=V(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:i,productQuantity:a,productSku:c,currency:s}=t,d=t.hasLocalizedPaths??C?.hasLocalizedPaths,u=t.workerUrl??C?.workerUrl,f=R(e,"product_removed_from_cart",d);if(!f)return;let l={...f,cart_currency:s,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:g(i),product_quantity:a,product_sku:w(c)};await L(l,u)}async function pr(t){let e=V(t);if(!e)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:i}=t,a=t.hasLocalizedPaths??C?.hasLocalizedPaths,c=t.workerUrl??C?.workerUrl,s=R(e,"cart_viewed",a);if(!s)return;let d={...s,cart_currency:i,cart_total_price:g(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:g(u.productPrice),product_quantity:u.productQuantity??null,product_sku:w(u.productSku)||""}))};await L(d,c)}async function fr(t){let e=V(t);if(!e)return;let{searchQuery:r,currency:o}=t,n=t.hasLocalizedPaths??C?.hasLocalizedPaths,i=t.workerUrl??C?.workerUrl,a=R(e,"search_submitted",n);if(!a)return;let c={...a,cart_currency:o,search_query:w(r)};await L(c,i)}async function mr(t){let e=V(t);if(!e)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:i,cartDiscountAmount:a,customerId:c,cartItems:s,currency:d}=t,u=t.hasLocalizedPaths??C?.hasLocalizedPaths,f=t.workerUrl??C?.workerUrl,l=R(e,"checkout_started",u);if(!l)return;let v=0,y=s?.map(m=>{let P=m.productQuantity??0;return v+=P,{product_id:_(m.productId),variant_id:_(m.variantId),product_vendor:w(m.productVendor)||"",vendor:w(m.productVendor)||"",product_price:g(m.productPrice),total_price:g(m.productPrice),product_quantity:P,quantity:P,product_sku:w(m.productSku)||"",sku:w(m.productSku)||"",total_discount:g(m.totalDiscount)}})||[],h={...l,cart_currency:d,cart_total_price:g(r),cart_subtotal_price:g(o),cart_total_quantity:v,cart_shipping_price:g(n),cart_tax_amount:g(i),cart_discount_amount:g(a),cart_items:y,customer_id:c};await L(h,f)}async function gr(t){let e=V(t);if(!e)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:i,cartTaxAmount:a,cartDiscountAmount:c,customerId:s,isFirstOrder:d,noteAttributes:u,cartItems:f,currency:l}=t,v=t.hasLocalizedPaths??C?.hasLocalizedPaths,y=t.ordersWorkerUrl??C?.ordersWorkerUrl??ar,h=R(e,"checkout_completed",v);if(!h)return;let m=0,P=f?.map(p=>{let b=p.productQuantity??0;return m+=b,{product_id:_(p.productId),variant_id:_(p.variantId),product_vendor:w(p.productVendor)||"",vendor:w(p.productVendor)||"",product_price:g(p.productPrice),total_price:g(p.productPrice),product_quantity:b,quantity:b,product_sku:w(p.productSku)||"",sku:w(p.productSku)||"",total_discount:g(p.totalDiscount)}})||[],T={...h,cart_currency:l,cart_total_price:g(o),cart_subtotal_price:g(n),cart_total_quantity:m,cart_shipping_price:g(i),cart_tax_amount:g(a),cart_discount_amount:g(c),cart_items:P,order_id:r,customer_id:s,is_first_order:d??null,note_attributes:u};await L(T,y)}function wr(t){let{storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:i=!0,pathname:a}=t,c=yr(null),[s,d]=hr(()=>a||(typeof window<"u"?window.location.pathname:""));ne(()=>{a&&d(a)},[a]),ne(()=>{typeof window>"u"||!i||c.current!==s&&(c.current=s,oe({storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[s,e,r,o,n,i])}import D from"react";var ot=new Map;function B(t){ot.set(t.type,t)}function at(t){return ot.get(t)}function ae(){return Array.from(ot.values())}function ie(t){return ot.has(t)}function Cr(t){try{let o=new URL(t,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function vr(t,e,r,o){if(typeof window>"u"||!t.prices||!e)return;let n=t.prices[e];if(!n)return;let i=n.price?.[r],a=n.compare?.[r],c=o;if(c?.selectorsV2?.length)for(let s of c.selectorsV2){if(s.price&&i){let d=s.price.replace("{{variant}}",e);document.querySelectorAll(d).forEach(f=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(i));f.textContent=l})}if(s.compareAt&&a){let d=s.compareAt.replace("{{variant}}",e);document.querySelectorAll(d).forEach(f=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(a));f.textContent=l})}if(s.saving&&i&&a)for(let d of s.saving){let u=d.selector.replace("{{variant}}",e);document.querySelectorAll(u).forEach(l=>{let v=parseFloat(i),y=parseFloat(a),h=y-v;if(d.isPercentage){let m=Math.round(h/y*100);l.textContent=`${m}%`}else{let m=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(h);l.textContent=m}})}}}var Ut={type:"PRICE_PLUS",shouldActivate(t,e){let r=t.data;if(!r)return!1;let{productId:o,productHandle:n}=e,i=n||Cr(e.currentUrl),a=o&&r.productIds?.includes(o),c=i&&r.handles?.includes(i);return a||c},applyEffect(t,e,r){vr(e,r.variantId,r.currencyCode||"USD",r.selectors)},getVariantData(t,e,r){let o=t.data;return{prices:e.prices,matchedProductId:r.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function Tr(t,e){let o=t.data?.pathnames||[];if(!o.length)return!0;try{let i=new URL(e,"https://example.com").pathname;return o.some(a=>U(i,a))}catch{return!1}}var it={type:"CONTENT",shouldActivate(t,e){return Tr(t,e.currentUrl)},getVariantData(t,e,r){let o=t.data;return{content:e.content,pathnames:o?.pathnames,handlerActivated:!0}}};function Pr(t,e){let o=t.data?.pathnames||[];if(!o.length)return!0;try{let i=new URL(e,"https://example.com").pathname;return o.some(a=>U(i,a))}catch{return!1}}var It={type:"CUSTOM_CODE",shouldActivate(t,e){return Pr(t,e.currentUrl)},getVariantData(t,e,r){let o=t.data;return{customCode:e.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};B(Ut);B(_t);B(it);B(It);function _r(t){if(typeof window>"u")return{currentUrl:"",selectors:t};let e=window.location.href,r=window.location.pathname,o,n=r.match(/\/products\/([^\/\?]+)/);n&&(o=n[1]);let i,c=new URLSearchParams(window.location.search).get("variant");return c&&(i=c),{currentUrl:e,productHandle:o,variantId:i,selectors:t,currencyCode:"USD"}}function br(t){let{config:e,previewState:r,selectors:o}=st(),[n,i]=D.useState(null),[a,c]=D.useState(!0),s=D.useMemo(()=>e&&e.tests.find(l=>l.testId===t)||null,[e,t]),d=D.useMemo(()=>r||F(),[r]),u=D.useRef(null),f=D.useRef(null);return D.useEffect(()=>{let l=!0;if(e===null)return;if(!s){u.current!==t&&(u.current=t,console.warn(`[ElevateAB] Test not found: ${t}`)),l&&c(!1);return}if(!s.enabled&&!d?.isPreview){u.current!==`${t}-disabled`&&(u.current=`${t}-disabled`,console.warn(`[ElevateAB] Test disabled: ${t}`)),l&&c(!1);return}let v=A(t);if(!v){l&&c(!1);return}let y=s.variations.find(T=>T.id===v);if(!y){l&&c(!1);return}let h=at(s.type),m=_r(o),P={...y};if(h?.shouldActivate(s,m)){let T=`${t}-${y.id}`;h.applyEffect&&f.current!==T&&(f.current=T,h.applyEffect(s,y,m));let p=h.getVariantData(s,y,m);P={...P,...p}}return l&&i(P),d?.isPreview||Ct(t),l&&c(!1),()=>{l=!1}},[e,s,t,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 E,{useRef as Er,useCallback as kr}from"react";function Vt(t){return t.tests.some(e=>e.type==="CUSTOM_CODE"&&e.enabled)}function se(t,e,r){if(typeof window>"u"||!Vt(t))return;let o=t.tests.filter(i=>i.type==="CUSTOM_CODE"&&i.enabled),n=[];o.forEach(i=>{let a=A(i.testId);if(!a)return;let c=i.variations.find(s=>s.id===a);c?.customCode&&(c.customCode.js||c.customCode.css)&&n.push(c.customCode)}),n.length>0&&rt(n,r)}import{jsx as Ir,jsxs as Vr}from"react/jsx-runtime";var Sr="https://ds0wlyksfn0sb.cloudfront.net/headless";function xr(t){return t.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function ce(t){return`${Sr}/${xr(t)}.js`}var Ar=typeof window<"u"?E.useLayoutEffect:E.useEffect;function Ur({storeId:t,storefrontAccessToken:e,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:i}){let[a,c]=E.useState(null),[s,d]=E.useState(null),[u,f]=E.useState(null);E.useEffect(()=>{if(typeof window>"u")return;At({storeId:t,storefrontAccessToken:e});let P=F();d(P);let T=H();f(T)},[t,e]);let l=kr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);E.useEffect(()=>{async function P(){try{let T=typeof window<"u"?F():null,p=null;if(typeof window<"u"&&window.eab_data)p=window.eab_data;else{let M=ce(t);p=await new Promise((z,le)=>{let O=document.createElement("script");O.src=M,O.async=!0,O.onload=()=>{let Rt=window.eab_data;O.remove(),Rt?z(Rt):le(new Error("Failed to load config: window.eab_data is undefined"))},O.onerror=()=>{O.remove(),z({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(O)})}if(!p||!p.allTests||Object.keys(p.allTests).length===0){c({tests:[],selectors:void 0}),l();return}if(p.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${t}. `+(p.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),c({tests:[],selectors:void 0}),l();return}if(!(Object.keys(p.allTests||{}).length>0)){c({tests:[],selectors:void 0}),l();return}let N=Ot(p);if(wt(N,T),N.tests.some(M=>M.type==="SPLIT_URL")&&Q(N,T))return;c(N),l()}catch(T){console.error("[ElevateAB] Failed to load config:",T),c({tests:[],selectors:void 0}),l()}}P()},[t,l]),Ar(()=>{if(!a||typeof window>"u")return;let P=()=>Jt(a)?Q(a,s):!1,T=()=>{if(K(a))try{nt(a,s,n)}catch(z){console.error("[ElevateAB] Failed to apply CONTENT tests:",z)}if(Vt(a))try{se(a,s,n)}catch(z){console.error("[ElevateAB] Failed to apply CUSTOM_CODE tests:",z)}};P()||T();let p=null,b=null,N=q(()=>{P()||(T(),p!==null&&window.cancelAnimationFrame(p),b!==null&&window.clearTimeout(b),p=window.requestAnimationFrame(()=>{T(),b=window.setTimeout(()=>{T(),b=null},80),p=null}))}),M=K(a)?xt(a,s,n,!1):()=>{};return()=>{p!==null&&window.cancelAnimationFrame(p),b!==null&&window.clearTimeout(b),N(),M()}},[a,s,n]);let v=E.useMemo(()=>({config:a,storeId:t,storefrontAccessToken:e,isPreviewMode:s?.isPreview??!1,previewTestId:s?.previewTestId??null,previewState:s,selectors:a?.selectors,countryCode:u}),[a,t,e,s,u]),y=Er(!1);E.useEffect(()=>{!e&&!y.current&&(y.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[e]);let h=E.useMemo(()=>ce(t),[t]),m=E.useMemo(()=>Tt({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return Vr(Lt.Provider,{value:v,children:[Ir("script",{nonce:n,dangerouslySetInnerHTML:{__html:m}}),i]})}var Fn="1.1.2";export{Ie as CART_ATTRIBUTES_UPDATE_MUTATION,qe as COUNTRIES,Oe as ElevateAnalytics,Ur as ElevateProvider,$e as REGIONS,Fn as VERSION,Xt as applyContentChanges,Zt as applyContentElements,rt as applyCustomCode,wt as assignAllTests,xe as assignAndPersistVariant,Pe as buildEabTestsParam,Ae as canAssignToTest,Dt as checkFacebookBrowser,pe as checkFacebookInstagramBrowser,Nt as checkInstagramBrowser,zt as checkPinterestBrowser,Mt as checkTikTokBrowser,fe as checkVisitorIdParams,lt as cleanCartToken,Le as cleanupCartAttributes,re as cleanupContentTests,be as clearPreviewMode,it as contentHandler,me as deleteCookie,Xe as detectShopifyCurrency,ct as extractCartToken,de as extractProductId,ue as extractProductVariantId,_ as extractShopifyId,Qe as extractShopifyType,ae as getAllHandlers,A as getAssignedVariant,Ve as getCartAttributesPayload,k as getCookie,H as getCountryCode,De as getDeviceType,Me as getGeoLocation,at as getHandler,S as getJsonCookie,X as getJsonSessionItem,ut as getPageTypeFromPathname,F as getPreviewState,Te as getPreviewVariation,ht as getReferrerData,yt as getSessionId,ge as getSessionItem,Tt as getSplitUrlBlockingScript,ke as getTestList,Ne as getTrafficSource,pt as getUserAgentNoBrowser,gt as getVisitorId,K as hasContentTests,ie as hasHandler,He as hasSessionView,Be as hasUniqueView,Ce as hashString,At as initAnalytics,he as initializeSessionId,ye as initializeVisitorId,$t as isCountryExcluded,qt as isCountryIncluded,Ee as isInPreviewMode,ve as isPreviewTest,Ke as isShopifyGid,Fe as matchesGeoTargeting,U as matchesWildcardPattern,dt as parseAddViewData,nt as processContentTests,Q as processSplitUrlTests,B as registerHandler,kt as reprocessContentTests,ee as restoreOriginalElements,g as roundToTwo,w as sanitizeString,Se as saveTestList,x as setCookie,Ft as setCountryCode,ze as setGeoLocation,we as setReferrerData,mt as setSessionItem,xt as setupContentTestListeners,Ue as shouldShowTest,dr as trackAddToCart,pr as trackCartView,gr as trackCheckoutCompleted,mr as trackCheckoutStarted,oe as trackPageView,lr as trackProductView,ur as trackRemoveFromCart,fr as trackSearchSubmitted,Bt as trackSessionView,Ht as trackUniqueView,Ct as trackViews,Re as updateCartAttributes,_e as updateUrlWithTestParams,st as useElevateConfig,br as useExperiment,wr as usePageViewTracking,ft as uuidv4};
|
|
29
|
+
})();`}function zt(t){if(!t?.trim())return"";try{let r=`https://${t.trim().replace(/^https?:\/\//,"")}`,o=new URL(r.replace(/\/+$/,""));return o.hostname.startsWith("www.")&&(o.hostname=o.hostname.substring(4)),o.toString().replace(/\/+$/,"")}catch{return t.trim().replace(/\/+$/,"")}}function vt(t,e){let r=zt(t.split("?")[0]);for(let o of e){let n=zt(o.split("?")[0]);if(r===n)return!0;try{let i=new URL(t).pathname,a=new URL(o,t).pathname;if(i===a)return!0}catch{}}return!1}function je(t){return t.data?.redirectBehavior||"redirectAll"}function Ft(t){return!!(H("eabRedirectedTests")||{})[t]}function $t(t){let e=H("eabRedirectedTests")||{};e[t]=!0,V("eabRedirectedTests",JSON.stringify(e))}function Je(t,e){for(let r of t.tests)if(!(r.type!=="SPLIT_URL"||!r.enabled))for(let o of r.variations){let n=o.splitUrlTestLinks||[];if(n.length!==0&&vt(e,n))return{test:r,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function Ye(t){if(typeof window>"u")return;let e=new URL(t,window.location.origin);e.searchParams.set("abtr","true");let r=e.toString(),o=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(o&&typeof o=="function")try{let n=e.pathname+e.search;o(n);return}catch{}window.location.href=r}function Q(t,e){if(typeof window>"u")return!1;let r=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let n=Je(t,r);if(!n)return!1;let{test:i,matchedVariation:a,isControlUrl:c}=n,s=i.testId,u=je(i),d=S(s);if(!d)return!1;let f=i.variations.find(y=>y.id===d);if(!f)return!1;let l=f.splitUrlTestLinks||[];if(l.length===0||vt(r,l))return!1;switch(u){case"redirectOnlyControlUrl":if(!c||f.isControl)return!1;break;case"redirectOnce":if(Ft(s))return!1;$t(s);break;case"redirectOnceControlUrlOnly":if(!c||Ft(s)||f.isControl)return!1;$t(s);break;default:break}let v=l[0];return Ye(v),!0}function qt(t){return t.tests.some(e=>e.type==="SPLIT_URL"&&e.enabled)}var Tt={type:"SPLIT_URL",shouldActivate(t,e){for(let r of t.variations){let o=r.splitUrlTestLinks||[];if(vt(e.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function _(t){return t?t.includes("gid://")&&t.split("/").pop()||t:""}function Qe(t){return!t||!t.includes("gid://")?null:t.split("/")[3]||null}function Ke(t){return!!t&&t.startsWith("gid://shopify/")}function Xe(){if(typeof window>"u")return;let t=window.Shopify;if(t?.currency?.active)return t.currency.active}var Gt="elv-el-",Wt={ELEMENT_NODE:1,TEXT_NODE:3},tt=new Map,q=new Map,G=new Map,W=new Map,j=!1;function x(t,e){if(e==="*")return!0;if(e.startsWith("*")&&e.endsWith("*")){let r=e.slice(1,-1);return t.includes(r)}if(e.startsWith("*")){let r=e.slice(1);return t.endsWith(r)}return e===t}function bt(){return typeof window>"u"?!1:window.innerWidth<768}function Ze(t){let e="";for(let r=0;r<t.length;r++){let o=t[r];o>="A"&&o<="Z"?(r!==0&&(e+="-"),e+=o.toLowerCase()):e+=o}return e}function tr(t){return t.nodeType===Wt.TEXT_NODE}function Pt(t){return t.nodeType===Wt.ELEMENT_NODE}function _t(t,e){tt.has(t)||tt.set(t,e.cloneNode(!0))}function jt(t){let e=t;e=e.replace(/`/g,"`").replace(/$/g,"$");try{e=JSON.parse('"'+e+'"')}catch{}return e}function Jt(t){if(typeof window>"u"||t.length===0)return;let e=window.location.pathname,r=t.filter(n=>n.pathnames?.length?n.pathnames.some(i=>x(e,i)):!0);j=bt();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...j&&n.style.sm}:void 0,content:n.content&&j&&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 s=n.applyAll?`${n.selector}-${c}-${a.id||Math.random().toString(36).substr(2,9)}`:n.selector;_t(s,a),tr(a)?a.nodeValue=n.content:Pt(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let i=document.querySelector(n.selector);!i||!Pt(i)||(_t(n.selector,i),Object.entries(n.style).forEach(([a,c])=>{let s=Ze(a),u=c.toString().includes("!important"),d=c.toString().replace(/\s*!important\s*$/,"");i.style.setProperty(s,d,u?"important":void 0)}))}),o.filter(n=>n.attributes!==void 0).forEach(n=>{let i=document.querySelector(n.selector);!i||!Pt(i)||(_t(n.selector,i),Object.entries(n.attributes).forEach(([a,c])=>{i.setAttribute(a,c)}))})}function Yt(t){if(typeof window>"u"||t.length===0)return;let e=window.location.pathname;t.filter(o=>o.selector?.pathnames?.length?o.selector.pathnames.some(n=>x(e,n)):!0).forEach(o=>{let n=`${Gt}${o.id}`,i=W.get(n);if(i&&!document.contains(i)&&W.delete(n),W.has(n))return;let a=document.querySelector(o.selector.target);if(!a||a.parentElement?.querySelector(`#${n}`))return;let c=Qt(o);o.selector.placement==="after"?a.after(c):o.selector.placement==="before"&&a.before(c),W.set(n,c)})}function Qt(t){let e=document.createElement(t.tagName);return e.id=`${Gt}${t.id}`,t.style&&Object.assign(e.style,t.style),t.attributes&&Object.entries(t.attributes).forEach(([r,o])=>{e.setAttribute(r,o)}),t.kind==="text"&&t.content&&(e.innerText=t.content),t.kind==="container"&&t.childrens&&t.childrens.forEach(r=>{let o=Qt(r);e.appendChild(o)}),e}function et(t,e){if(typeof window>"u"||t.length===0)return;let r=window.location.pathname;t.filter(n=>n.pathnames?.length?n.excludePathnames?.length&&n.excludePathnames.some(a=>x(r,a))?!1:n.pathnames.some(i=>x(r,i)):!0).forEach(n=>{n.id&&(n.css&&er(n.id,n.css),n.js&&rr(n.id,n.js,e))})}function er(t,e){let r=`css-${t}`,o=q.get(r);if(o&&!document.contains(o)&&q.delete(r),q.has(r)||document.getElementById(r))return;let n=document.createElement("style");n.id=r,n.textContent=jt(e),document.head.appendChild(n),q.set(r,n)}function rr(t,e,r){let o=`js-${t}`,n=G.get(o);if(n&&!document.contains(n)&&G.delete(o),G.has(o)||document.getElementById(o))return;let i=document.createElement("script");i.id=o,r&&i.setAttribute("nonce",r);let a=jt(e);i.textContent="(function(){try{"+a+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(i),G.set(o,i)}function Kt(){tt.forEach((t,e)=>{let r=document.querySelector(e);r&&r.replaceWith(t.cloneNode(!0))})}function Xt(){q.forEach(t=>t.remove()),q.clear(),G.forEach(t=>t.remove()),G.clear(),W.forEach(t=>t.remove()),W.clear(),tt.clear()}function nr(t,e){let r=[],o=[],n=[];return t.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=S(a.testId);if(!c)return;let s=a.variations.find(u=>u.id===c);s?.content&&(s.content.changes?.length&&r.push(...s.content.changes),s.content.elements?.length&&o.push(...s.content.elements),s.content.customCodes?.length&&n.push(...s.content.customCodes))}),{changes:r,elements:o,blocks:[],customCodes:n}}function K(t){return t.tests.some(e=>e.type==="CONTENT"&&e.enabled)}function rt(t,e,r){if(typeof window>"u"||!K(t))return;let o=nr(t,e);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(Jt(o.changes),Yt(o.elements),et(o.customCodes,r))}function Et(t,e,r){if(typeof window>"u")return;let o=bt();o!==j&&(Kt(),j=o),rt(t,e,r)}function kt(t,e,r,o=!0){if(typeof window>"u")return()=>{};let n=()=>{bt()!==j&&Et(t,e,r)};window.addEventListener("resize",n);let i=()=>{};return o&&(i=$(()=>{Et(t,e,r)})),()=>{window.removeEventListener("resize",n),i(),Xt()}}import{useEffect as Zt,useRef as yr,useState as hr}from"react";var or="https://bitter-river-9c62.support-67d.workers.dev",ar="https://d339co84ntxcme.cloudfront.net/Prod/orders",C=null;function St(t){C=t}function U(t){let e=t?.storeId||C?.storeId;return e||(console.warn("[ElevateAB] No storeId provided. Call initAnalytics() first or pass storeId to tracking function."),"")}function ir(t){return Object.entries(t).filter(([,e])=>typeof e=="string").map(([e,r])=>({test_id:e,variant_id:r}))}function sr(t,e){return Object.entries(t).filter(([r])=>typeof e[r]=="string").map(([r])=>({test_id:r,variant_id:e[r]}))}function cr(){return typeof window>"u"?!1:k("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function I(t,e,r){if(typeof window>"u"||cr())return null;let o=navigator.userAgent,n=window.location.pathname,i=ut(n,r),{referrer:a,entryPage:c}=gt(),s=lt({referrer:a,entryPage:c,userAgent:o}),u=H("ABTL")||{},d=H("ABAU")||{},f=ir(u),l=sr(d,u),v=st(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",m=k("localization")||"";return{pixel_event_id:`sh-${pt()}`,shop_name:t,timestamp:y,event_type:e,client_id:k("_shopify_y")||void 0,visitor_id:ft(),session_id:mt(),cart_token:ct(v||k("cart")),page_url:window.location.href,page_pathname:n,page_search:window.location.search,referrer_url:a,referrer_source:s?.referrer_source,previous_page:document.referrer,page_entry:c,page_entry_path:s?.page_entry_path,page_type:i,utm_medium:s?.utm_medium,utm_source:s?.utm_source,utm_campaign:s?.utm_campaign,utm_content:s?.utm_content,utm_term:s?.utm_term,gclid:s?.gclid,fbclid:s?.fbclid,pins_campaign_id:s?.pins_campaign_id,epik:s?.epik,browser_info:s?.browser_info,os_info:s?.os_info,device_type:s?.device_type,language:navigator.language,root_route:localStorage.getItem("eabRootRoute")||"",user_agent:o,user_agent_no_browser:dt(o),is_first_visit:h,shopify_country:m,ab_test_assignments:f,ab_test_views:l,is_first_order:null}}async function L(t,e=or){try{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0});if(!r.ok)throw new Error(`Worker error: ${r.status}`)}catch(r){console.error("[ElevateAB] Error sending analytics:",r)}}async function te(t={}){let e=U(t);if(!e)return;let r=t.hasLocalizedPaths??C?.hasLocalizedPaths,o=t.workerUrl??C?.workerUrl,n=I(e,"page_viewed",r);if(!n)return;let i={...n,cart_currency:t.currency};await L(i,o)}async function lr(t){let e=U(t);if(!e)return;let{productId:r,productVendor:o,productPrice:n,productSku:i,currency:a}=t,c=t.hasLocalizedPaths??C?.hasLocalizedPaths,s=t.workerUrl??C?.workerUrl,u=I(e,"product_viewed",c);if(!u)return;let d={...u,cart_currency:a,product_id:_(r),product_vendor:w(o),product_price:g(n),product_sku:w(i)};await L(d,s)}async function ur(t){let e=U(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:i,productQuantity:a,productSku:c,currency:s,cartId:u}=t,d=t.hasLocalizedPaths??C?.hasLocalizedPaths,f=t.workerUrl??C?.workerUrl,l=t.storefrontAccessToken??C?.storefrontAccessToken,v=I(e,"product_added_to_cart",d);if(!v)return;let y={...v,cart_currency:s,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:g(i),product_quantity:a,product_sku:w(c)};if(await L(y,f),u&&l)try{let{updateCartAttributes:h}=await import("./cartAttributes-DBBVZUFZ.js");await h(u,{storefrontAccessToken:l})}catch(h){console.error("[ElevateAB] Failed to update cart attributes:",h)}}async function dr(t){let e=U(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:i,productQuantity:a,productSku:c,currency:s}=t,u=t.hasLocalizedPaths??C?.hasLocalizedPaths,d=t.workerUrl??C?.workerUrl,f=I(e,"product_removed_from_cart",u);if(!f)return;let l={...f,cart_currency:s,product_id:_(r),variant_id:_(o),product_vendor:w(n),product_price:g(i),product_quantity:a,product_sku:w(c)};await L(l,d)}async function pr(t){let e=U(t);if(!e)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:i}=t,a=t.hasLocalizedPaths??C?.hasLocalizedPaths,c=t.workerUrl??C?.workerUrl,s=I(e,"cart_viewed",a);if(!s)return;let u={...s,cart_currency:i,cart_total_price:g(r),cart_total_quantity:o,cart_items:n?.map(d=>({product_id:_(d.productId),variant_id:_(d.variantId),product_vendor:w(d.productVendor)||"",product_price:g(d.productPrice),product_quantity:d.productQuantity??null,product_sku:w(d.productSku)||""}))};await L(u,c)}async function fr(t){let e=U(t);if(!e)return;let{searchQuery:r,currency:o}=t,n=t.hasLocalizedPaths??C?.hasLocalizedPaths,i=t.workerUrl??C?.workerUrl,a=I(e,"search_submitted",n);if(!a)return;let c={...a,cart_currency:o,search_query:w(r)};await L(c,i)}async function mr(t){let e=U(t);if(!e)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:i,cartDiscountAmount:a,customerId:c,cartItems:s,currency:u}=t,d=t.hasLocalizedPaths??C?.hasLocalizedPaths,f=t.workerUrl??C?.workerUrl,l=I(e,"checkout_started",d);if(!l)return;let v=0,y=s?.map(m=>{let P=m.productQuantity??0;return v+=P,{product_id:_(m.productId),variant_id:_(m.variantId),product_vendor:w(m.productVendor)||"",vendor:w(m.productVendor)||"",product_price:g(m.productPrice),total_price:g(m.productPrice),product_quantity:P,quantity:P,product_sku:w(m.productSku)||"",sku:w(m.productSku)||"",total_discount:g(m.totalDiscount)}})||[],h={...l,cart_currency:u,cart_total_price:g(r),cart_subtotal_price:g(o),cart_total_quantity:v,cart_shipping_price:g(n),cart_tax_amount:g(i),cart_discount_amount:g(a),cart_items:y,customer_id:c};await L(h,f)}async function gr(t){let e=U(t);if(!e)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:i,cartTaxAmount:a,cartDiscountAmount:c,customerId:s,isFirstOrder:u,noteAttributes:d,cartItems:f,currency:l}=t,v=t.hasLocalizedPaths??C?.hasLocalizedPaths,y=t.ordersWorkerUrl??C?.ordersWorkerUrl??ar,h=I(e,"checkout_completed",v);if(!h)return;let m=0,P=f?.map(p=>{let E=p.productQuantity??0;return m+=E,{product_id:_(p.productId),variant_id:_(p.variantId),product_vendor:w(p.productVendor)||"",vendor:w(p.productVendor)||"",product_price:g(p.productPrice),total_price:g(p.productPrice),product_quantity:E,quantity:E,product_sku:w(p.productSku)||"",sku:w(p.productSku)||"",total_discount:g(p.totalDiscount)}})||[],T={...h,cart_currency:l,cart_total_price:g(o),cart_subtotal_price:g(n),cart_total_quantity:m,cart_shipping_price:g(i),cart_tax_amount:g(a),cart_discount_amount:g(c),cart_items:P,order_id:r,customer_id:s,is_first_order:u??null,note_attributes:d};await L(T,y)}function wr(t){let{storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:i=!0,pathname:a}=t,c=yr(null),[s,u]=hr(()=>a||(typeof window<"u"?window.location.pathname:""));Zt(()=>{a&&u(a)},[a]),Zt(()=>{typeof window>"u"||!i||c.current!==s&&(c.current=s,te({storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[s,e,r,o,n,i])}import B from"react";var nt=new Map;function D(t){nt.set(t.type,t)}function ot(t){return nt.get(t)}function ee(){return Array.from(nt.values())}function re(t){return nt.has(t)}function Cr(t){try{let o=new URL(t,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function vr(t,e,r,o){if(typeof window>"u"||!t.prices||!e)return;let n=t.prices[e];if(!n)return;let i=n.price?.[r],a=n.compare?.[r],c=o;if(c?.selectorsV2?.length)for(let s of c.selectorsV2){if(s.price&&i){let u=s.price.replace("{{variant}}",e);document.querySelectorAll(u).forEach(f=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(i));f.textContent=l})}if(s.compareAt&&a){let u=s.compareAt.replace("{{variant}}",e);document.querySelectorAll(u).forEach(f=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(a));f.textContent=l})}if(s.saving&&i&&a)for(let u of s.saving){let d=u.selector.replace("{{variant}}",e);document.querySelectorAll(d).forEach(l=>{let v=parseFloat(i),y=parseFloat(a),h=y-v;if(u.isPercentage){let m=Math.round(h/y*100);l.textContent=`${m}%`}else{let m=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(h);l.textContent=m}})}}}var xt={type:"PRICE_PLUS",shouldActivate(t,e){let r=t.data;if(!r)return!1;let{productId:o,productHandle:n}=e,i=n||Cr(e.currentUrl),a=o&&r.productIds?.includes(o),c=i&&r.handles?.includes(i);return a||c},applyEffect(t,e,r){vr(e,r.variantId,r.currencyCode||"USD",r.selectors)},getVariantData(t,e,r){let o=t.data;return{prices:e.prices,matchedProductId:r.productId,productIds:o?.productIds,handles:o?.handles,handlerActivated:!0}}};function Tr(t,e){let o=t.data?.pathnames||[];if(!o.length)return!0;try{let i=new URL(e,"https://example.com").pathname;return o.some(a=>x(i,a))}catch{return!1}}var at={type:"CONTENT",shouldActivate(t,e){return Tr(t,e.currentUrl)},getVariantData(t,e,r){let o=t.data;return{content:e.content,pathnames:o?.pathnames,handlerActivated:!0}}};function Pr(t,e){let o=t.data?.pathnames||[];if(!o.length)return!0;try{let i=new URL(e,"https://example.com").pathname;return o.some(a=>x(i,a))}catch{return!1}}var At={type:"CUSTOM_CODE",shouldActivate(t,e){return Pr(t,e.currentUrl)},getVariantData(t,e,r){let o=t.data;return{customCode:e.customCode,pathnames:o?.pathnames,excludePathnames:o?.excludePathnames,handlerActivated:!0}}};D(xt);D(Tt);D(at);D(At);function _r(t){if(typeof window>"u")return{currentUrl:"",selectors:t};let e=window.location.href,r=window.location.pathname,o,n=r.match(/\/products\/([^\/\?]+)/);n&&(o=n[1]);let i,c=new URLSearchParams(window.location.search).get("variant");return c&&(i=c),{currentUrl:e,productHandle:o,variantId:i,selectors:t,currencyCode:"USD"}}function Er(t){let{config:e,previewState:r,selectors:o}=it(),[n,i]=B.useState(null),[a,c]=B.useState(!0),s=B.useMemo(()=>e&&e.tests.find(l=>l.testId===t)||null,[e,t]),u=B.useMemo(()=>r||F(),[r]),d=B.useRef(null),f=B.useRef(null);return B.useEffect(()=>{let l=!0;if(e===null)return;if(!s){d.current!==t&&(d.current=t,console.warn(`[ElevateAB] Test not found: ${t}`)),l&&c(!1);return}if(!s.enabled&&!u?.isPreview){d.current!==`${t}-disabled`&&(d.current=`${t}-disabled`,console.warn(`[ElevateAB] Test disabled: ${t}`)),l&&c(!1);return}let v=S(t);if(!v){l&&c(!1);return}let y=s.variations.find(T=>T.id===v);if(!y){l&&c(!1);return}let h=ot(s.type),m=_r(o),P={...y};if(h?.shouldActivate(s,m)){let T=`${t}-${y.id}`;h.applyEffect&&f.current!==T&&(f.current=T,h.applyEffect(s,y,m));let p=h.getVariantData(s,y,m);P={...P,...p}}return l&&i(P),u?.isPreview||yt(t),l&&c(!1),()=>{l=!1}},[e,s,t,u,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 br,useCallback as kr}from"react";function Ut(t){return t.tests.some(e=>e.type==="CUSTOM_CODE"&&e.enabled)}function ne(t,e,r){if(typeof window>"u"||!Ut(t))return;let o=t.tests.filter(i=>i.type==="CUSTOM_CODE"&&i.enabled),n=[];o.forEach(i=>{let a=S(i.testId);if(!a)return;let c=i.variations.find(s=>s.id===a);c?.customCode&&(c.customCode.js||c.customCode.css)&&n.push(c.customCode)}),n.length>0&&et(n,r)}import{jsx as Ir,jsxs as Lr}from"react/jsx-runtime";var Sr="https://ds0wlyksfn0sb.cloudfront.net/headless";function xr(t){return t.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function oe(t){return`${Sr}/${xr(t)}.js`}var Ar=typeof window<"u"?b.useLayoutEffect:b.useEffect;function Ur({storeId:t,storefrontAccessToken:e,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:i}){let[a,c]=b.useState(null),[s,u]=b.useState(null),[d,f]=b.useState(null);b.useEffect(()=>{if(typeof window>"u")return;St({storeId:t,storefrontAccessToken:e});let P=F();u(P);let T=O();f(T)},[t,e]);let l=kr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);b.useEffect(()=>{async function P(){try{let T=typeof window<"u"?F():null,p=null;if(typeof window<"u"&&window.eab_data)p=window.eab_data;else{let M=oe(t);p=await new Promise((z,ae)=>{let R=document.createElement("script");R.src=M,R.async=!0,R.onload=()=>{let It=window.eab_data;R.remove(),It?z(It):ae(new Error("Failed to load config: window.eab_data is undefined"))},R.onerror=()=>{R.remove(),z({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(R)})}if(!p||!p.allTests||Object.keys(p.allTests).length===0){c({tests:[],selectors:void 0}),l();return}if(p.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${t}. `+(p.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),c({tests:[],selectors:void 0}),l();return}if(!(Object.keys(p.allTests||{}).length>0)){c({tests:[],selectors:void 0}),l();return}let N=Rt(p);if(ht(N,T),N.tests.some(M=>M.type==="SPLIT_URL")&&Q(N,T))return;c(N),l()}catch(T){console.error("[ElevateAB] Failed to load config:",T),c({tests:[],selectors:void 0}),l()}}P()},[t,l]),Ar(()=>{if(!a||typeof window>"u")return;let P=()=>qt(a)?Q(a,s):!1,T=()=>{if(K(a))try{rt(a,s,n)}catch(z){console.error("[ElevateAB] Failed to apply CONTENT tests:",z)}if(Ut(a))try{ne(a,s,n)}catch(z){console.error("[ElevateAB] Failed to apply CUSTOM_CODE tests:",z)}};P()||T();let p=null,E=null,N=$(()=>{P()||(T(),p!==null&&window.cancelAnimationFrame(p),E!==null&&window.clearTimeout(E),p=window.requestAnimationFrame(()=>{T(),E=window.setTimeout(()=>{T(),E=null},80),p=null}))}),M=K(a)?kt(a,s,n,!1):()=>{};return()=>{p!==null&&window.cancelAnimationFrame(p),E!==null&&window.clearTimeout(E),N(),M()}},[a,s,n]);let v=b.useMemo(()=>({config:a,storeId:t,storefrontAccessToken:e,isPreviewMode:s?.isPreview??!1,previewTestId:s?.previewTestId??null,previewState:s,selectors:a?.selectors,countryCode:d}),[a,t,e,s,d]),y=br(!1);b.useEffect(()=>{!e&&!y.current&&(y.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[e]);let h=b.useMemo(()=>oe(t),[t]),m=b.useMemo(()=>Ct({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return Lr(Lt.Provider,{value:v,children:[Ir("script",{nonce:n,dangerouslySetInnerHTML:{__html:m}}),i]})}var Mn="1.1.2";export{Re as CART_ATTRIBUTES_UPDATE_MUTATION,$e as COUNTRIES,De as ElevateAnalytics,Ur as ElevateProvider,qe as REGIONS,Mn as VERSION,Jt as applyContentChanges,Yt as applyContentElements,et as applyCustomCode,ht as assignAllTests,Ue as assignAndPersistVariant,ve as buildEabTestsParam,Ie as canAssignToTest,Vt as checkFacebookBrowser,ce as checkFacebookInstagramBrowser,Ht as checkInstagramBrowser,Dt as checkPinterestBrowser,Ot as checkTikTokBrowser,le as checkVisitorIdParams,ct as cleanCartToken,Oe as cleanupCartAttributes,Xt as cleanupContentTests,Pe as clearPreviewMode,at as contentHandler,ue as deleteCookie,Xe as detectShopifyCurrency,st as extractCartToken,ie as extractProductId,se as extractProductVariantId,_ as extractShopifyId,Qe as extractShopifyType,ee as getAllHandlers,S as getAssignedVariant,Ve as getCartAttributesPayload,k as getCookie,O as getCountryCode,Be as getDeviceType,Me as getGeoLocation,ot as getHandler,H as getJsonCookie,fe as getJsonSessionItem,ut as getPageTypeFromPathname,F as getPreviewState,Ce as getPreviewVariation,gt as getReferrerData,mt as getSessionId,pe as getSessionItem,Ct as getSplitUrlBlockingScript,xe as getTestList,Ne as getTrafficSource,dt as getUserAgentNoBrowser,ft as getVisitorId,K as hasContentTests,re as hasHandler,ke as hasSessionView,Se as hasUniqueView,he as hashString,St as initAnalytics,ge as initializeSessionId,me as initializeVisitorId,Mt as isCountryExcluded,Nt as isCountryIncluded,_e as isInPreviewMode,we as isPreviewTest,Ke as isShopifyGid,Fe as matchesGeoTargeting,x as matchesWildcardPattern,lt as parseAddViewData,rt as processContentTests,Q as processSplitUrlTests,D as registerHandler,Et as reprocessContentTests,Kt as restoreOriginalElements,g as roundToTwo,w as sanitizeString,Ae as saveTestList,V as setCookie,Bt as setCountryCode,ze as setGeoLocation,ye as setReferrerData,de as setSessionItem,kt as setupContentTestListeners,Le as shouldShowTest,ur as trackAddToCart,pr as trackCartView,gr as trackCheckoutCompleted,mr as trackCheckoutStarted,te as trackPageView,lr as trackProductView,dr as trackRemoveFromCart,fr as trackSearchSubmitted,be as trackSessionView,Ee as trackUniqueView,yt as trackViews,He as updateCartAttributes,Te as updateUrlWithTestParams,it as useElevateConfig,Er as useExperiment,wr as usePageViewTracking,pt as uuidv4};
|
|
30
30
|
//# sourceMappingURL=index.js.map
|