@elevateab/sdk 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -17
- package/dist/cartAttributes-UOPTEP2Q.js +2 -0
- package/dist/cartAttributes-YUZURH3L.js +3 -0
- package/dist/chunk-B2OIRKOZ.js +18 -0
- package/dist/chunk-B2OIRKOZ.js.map +1 -0
- package/dist/{chunk-NDGAU23Z.js → chunk-E3BNNKGR.js} +2 -2
- package/dist/chunk-QIFYO7SY.js +19 -0
- package/dist/chunk-QIFYO7SY.js.map +1 -0
- package/dist/hydrogen.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +3 -3
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +2 -0
- package/dist/next.d.ts +2 -0
- package/dist/next.js +3 -3
- package/dist/next.js.map +1 -1
- package/package.json +2 -8
- package/dist/cartAttributes-APUF5Y5N.js +0 -3
- package/dist/cartAttributes-OFPJ33X2.js +0 -2
- package/dist/chunk-5JX7O5JL.js +0 -18
- package/dist/chunk-5JX7O5JL.js.map +0 -1
- package/dist/chunk-U2FG4EEA.js +0 -19
- package/dist/chunk-U2FG4EEA.js.map +0 -1
- package/dist/vite.cjs +0 -2
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -28
- package/dist/vite.d.ts +0 -28
- package/dist/vite.js +0 -2
- package/dist/vite.js.map +0 -1
- /package/dist/{cartAttributes-APUF5Y5N.js.map → cartAttributes-UOPTEP2Q.js.map} +0 -0
- /package/dist/{cartAttributes-OFPJ33X2.js.map → cartAttributes-YUZURH3L.js.map} +0 -0
- /package/dist/{chunk-NDGAU23Z.js.map → chunk-E3BNNKGR.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -225,6 +225,8 @@ interface Variation {
|
|
|
225
225
|
splitUrlTestLinks?: string[];
|
|
226
226
|
/** Content test data for CONTENT tests */
|
|
227
227
|
content?: ContentTestData;
|
|
228
|
+
/** Custom code for CUSTOM_CODE tests (CSS/JS injection) */
|
|
229
|
+
customCode?: ContentCustomCode;
|
|
228
230
|
/** Convenience flag: true if this is variation A (index 0) */
|
|
229
231
|
isA?: boolean;
|
|
230
232
|
/** Convenience flag: true if this is variation B (index 1) */
|
package/dist/index.d.ts
CHANGED
|
@@ -225,6 +225,8 @@ interface Variation {
|
|
|
225
225
|
splitUrlTestLinks?: string[];
|
|
226
226
|
/** Content test data for CONTENT tests */
|
|
227
227
|
content?: ContentTestData;
|
|
228
|
+
/** Custom code for CUSTOM_CODE tests (CSS/JS injection) */
|
|
229
|
+
customCode?: ContentCustomCode;
|
|
228
230
|
/** Convenience flag: true if this is variation A (index 0) */
|
|
229
231
|
isA?: boolean;
|
|
230
232
|
/** Convenience flag: true if this is variation B (index 1) */
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
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 as oe,k as ae,l as it,m as se,n as At}from"./chunk-E3BNNKGR.js";import{A as Tt,B as S,C as Pt,D as _t,E as bt,F as pe,G as Et,H as kt,I as xt,J as St,c as ie,d as x,e as E,f as k,g as ct,h as ce,i as lt,j as $,k as dt,l as le,m as ut,n as de,o as pt,p as ue,q as ft,r as Ue,s as D,t as mt,u as gt,v as yt,w as ht,x as wt,y as Ct,z as vt}from"./chunk-B2OIRKOZ.js";function Ie(e){let t=k("ABAU")||{};t[e]||(t[e]=!0,x("ABAU",JSON.stringify(t)))}function Ve(e){let t=$("ABAV")||{};t[e]||(t[e]=!0,ce("ABAV",t))}function fe(e){Ie(e),Ve(e)}function Ut(e){return!!($("ABAV")||{})[e]}function It(e){return!!(k("ABAU")||{})[e]}function Vt(){if(typeof navigator>"u")return"desktop";let e=navigator.userAgent||navigator.vendor||window.opera||"",t=e.toLowerCase();return/windows nt.*tablet pc|pixelbook/i.test(e)||/(?:macintosh|windows nt|win(?:95|98)|linux x86_64)/i.test(e)&&!/android|mobile|tablet|ipad|iphone|ipod/i.test(t)?"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(e)||/android(?!.*mobile)/i.test(t)&&!/dalvik.*miui|pocophone|mi\s+mix|edge\s+\d+|sm-g9\d+|pixel\s+\d|pixel\s+fold|advan\s+\d{4}/i.test(e)?"tablet":/android.+mobile|iphone|ipod|windows phone|blackberry|mobile|phone|kaios/i.test(t)||/^mobile;/i.test(e)||/dalvik.*miui|pocophone|mi\s+mix|pixel\s+\d|pixel\s+fold/i.test(e)?"mobile":"desktop"}function Re(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||navigator.vendor||window.opera;return/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i.test(e)}function Le(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||navigator.vendor||window.opera;return/(instagram)[\/ ]([-\w\.]+)/i.test(e)}function Be(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||navigator.vendor||window.opera;return/musical_ly/i.test(e)}function Oe(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||navigator.vendor||window.opera;return/(pinterest)[\/ ]([-\w\.]+)/i.test(e)}function Rt(){if(typeof window>"u")return"direct";let e=(document.referrer||"").toLowerCase(),t=e?new URL(e).hostname.replace("www.",""):"",r=window.location.hostname,o=Re(),n=Le(),s=Be(),a=Oe();return o||["facebook.com","fb.com","fb.me","m.facebook.com","l.facebook.com","lm.facebook.com"].includes(t)?"facebook":n||t.includes("instagram")?"instagram":s||["tiktok.com","pangleglobal.com","ads.tiktok.com"].includes(t)?"tiktok":a||t.includes("pinterest")||t==="pin.it"?"pinterest":t.includes("google")?"google":!e||r===t?"direct":"other"}var U={SHOPIFY_LOCALIZATION:"localization",EAB_COUNTRY:"eabCountryCode",EAB_GEO:"eabGeoLocation"};function B(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search).get("country");if(t)return x(U.EAB_COUNTRY,t.toUpperCase()),t.toUpperCase();let r=E(U.SHOPIFY_LOCALIZATION);if(r)return r.toUpperCase();let o=E(U.EAB_COUNTRY);if(o)return o.toUpperCase();if(typeof localStorage<"u"){let n=localStorage.getItem(U.EAB_COUNTRY);if(n)return n.toUpperCase()}return null}function Lt(){let e=B(),t=E(U.EAB_GEO);if(t)try{let r=JSON.parse(t);return{country:r.country||e,region:r.region,city:r.city}}catch{}return{country:e}}function He(e){let t=e.toUpperCase();x(U.EAB_COUNTRY,t),typeof localStorage<"u"&&localStorage.setItem(U.EAB_COUNTRY,t)}function Bt(e){e.country&&He(e.country),x(U.EAB_GEO,JSON.stringify(e))}function De(e,t){let r=t??B();return r?e.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function Me(e,t){let r=t??B();return r?e.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function Ot(e){let t=B();return!e.includeCountries?.length&&!e.excludeCountries?.length?!0:!t||e.excludeCountries?.length&&Me(e.excludeCountries,t)?!1:e.includeCountries?.length?De(e.includeCountries,t):!0}var Ht={US:"US",CA:"CA",GB:"GB",AU:"AU",DE:"DE",FR:"FR",JP:"JP",MX:"MX",BR:"BR",IN:"IN"},Dt={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"]};function me(e){let{configUrl:t,timeout:r=2e3}=e;return`(function(){
|
|
2
2
|
if(new URLSearchParams(location.search).get('abtr')==='true')return;
|
|
3
3
|
|
|
4
4
|
var style=document.createElement('style');
|
|
@@ -21,10 +21,10 @@ import{a as kt,b as tt,c as w,d as m,e as te,f as ee,g as et,h as rt,i as re,j a
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
var script=document.createElement('script');
|
|
24
|
-
script.src='${
|
|
24
|
+
script.src='${t}';
|
|
25
25
|
script.onerror=function(){
|
|
26
26
|
if(window.__eab_reveal)window.__eab_reveal();
|
|
27
27
|
};
|
|
28
28
|
document.head.appendChild(script);
|
|
29
|
-
})();`}function Ot(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 mt(t,e){let r=Ot(t.split("?")[0]);for(let o of e){let n=Ot(o.split("?")[0]);if(r===n)return!0;try{let s=new URL(t).pathname,a=new URL(o,t).pathname;if(s===a)return!0}catch{}}return!1}function Be(t){return t.data?.redirectBehavior||"redirectAll"}function Ht(t){return!!(k("eabRedirectedTests")||{})[t]}function Dt(t){let e=k("eabRedirectedTests")||{};e[t]=!0,x("eabRedirectedTests",JSON.stringify(e))}function Oe(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&&mt(e,n))return{test:r,matchedVariation:o,isControlUrl:!!o.isControl}}return null}function He(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=Oe(t,r);if(!n)return!1;let{test:s,matchedVariation:a,isControlUrl:c}=n,i=s.testId,d=Be(s),u=V(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||mt(r,l))return!1;switch(d){case"redirectOnlyControlUrl":if(!c||p.isControl)return!1;break;case"redirectOnce":if(Ht(i))return!1;Dt(i);break;case"redirectOnceControlUrlOnly":if(!c||Ht(i)||p.isControl)return!1;Dt(i);break;default:break}let C=l[0];return He(C),!0}var gt={type:"SPLIT_URL",shouldActivate(t,e){for(let r of t.variations){let o=r.splitUrlTestLinks||[];if(mt(e.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function _(t){return t?t.includes("gid://")&&t.split("/").pop()||t:""}function De(t){return!t||!t.includes("gid://")?null:t.split("/")[3]||null}function Ne(t){return!!t&&t.startsWith("gid://shopify/")}function Me(){if(typeof window>"u")return;let t=window.Shopify;if(t?.currency?.active)return t.currency.active}var Nt="elv-el-",Mt={ELEMENT_NODE:1,TEXT_NODE:3},G=new Map,j=new Map,W=new Map,J=new Map,D=!1;function B(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 vt(){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 Fe(t){return t.nodeType===Mt.TEXT_NODE}function yt(t){return t.nodeType===Mt.ELEMENT_NODE}function ht(t,e){G.has(t)||G.set(t,e.cloneNode(!0))}function zt(t){let e=t;e=e.replace(/`/g,"`").replace(/$/g,"$");try{e=JSON.parse('"'+e+'"')}catch{}return e}function Ft(t){if(typeof window>"u"||t.length===0)return;let e=window.location.pathname,r=t.filter(n=>n.pathnames?.length?n.pathnames.some(s=>B(e,s)):!0);D=vt();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...D&&n.style.sm}:void 0,content:n.content&&D&&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;ht(i,a),Fe(a)?a.nodeValue=n.content:yt(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let s=document.querySelector(n.selector);!s||!yt(s)||(ht(n.selector,s),Object.entries(n.style).forEach(([a,c])=>{let i=ze(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||!yt(s)||(ht(n.selector,s),Object.entries(n.attributes).forEach(([a,c])=>{s.setAttribute(a,c)}))})}function $t(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=>B(e,n)):!0).forEach(o=>{let n=`${Nt}${o.id}`;if(J.has(n))return;let s=document.querySelector(o.selector.target);if(!s||s.parentElement?.querySelector(`#${n}`))return;let a=qt(o);o.selector.placement==="after"?s.after(a):o.selector.placement==="before"&&s.before(a),J.set(n,a)})}function qt(t){let e=document.createElement(t.tagName);return e.id=`${Nt}${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 Gt(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=>B(r,a))?!1:n.pathnames.some(s=>B(r,s)):!0).forEach(n=>{n.id&&(n.css&&$e(n.id,n.css),n.js&&qe(n.id,n.js,e))})}function $e(t,e){let r=`css-${t}`;if(j.has(r)||document.getElementById(r))return;let o=document.createElement("style");o.id=r,o.textContent=zt(e),document.head.appendChild(o),j.set(r,o)}function qe(t,e,r){let o=`js-${t}`;if(W.has(o)||document.getElementById(o))return;let n=document.createElement("script");n.id=o,r&&n.setAttribute("nonce",r);let s=zt(e);n.textContent="(function(){try{"+s+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(n),W.set(o,n)}function jt(){G.forEach((t,e)=>{let r=document.querySelector(e);r&&r.replaceWith(t.cloneNode(!0))})}function Wt(){j.forEach(t=>t.remove()),j.clear(),W.forEach(t=>t.remove()),W.clear(),J.forEach(t=>t.remove()),J.clear(),G.clear()}function Ge(t,e){let r=[],o=[],n=[];return t.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=V(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 Y(t){return t.tests.some(e=>e.type==="CONTENT"&&e.enabled)}function Q(t,e,r){if(typeof window>"u"||!Y(t))return;let o=Ge(t,e);(o.changes.length>0||o.elements.length>0||o.customCodes.length>0)&&(Ft(o.changes),$t(o.elements),Gt(o.customCodes,r))}function wt(t,e,r){if(typeof window>"u")return;let o=vt();o!==D&&(jt(),D=o),Q(t,e,r)}function Ct(t,e,r){if(typeof window>"u")return()=>{};let o=()=>{vt()!==D&&wt(t,e,r)},n=()=>{wt(t,e,r)};return window.addEventListener("resize",o),window.addEventListener("popstate",n),()=>{window.removeEventListener("resize",o),window.removeEventListener("popstate",n),Wt()}}import{useEffect as Jt,useRef as or,useState as ar}from"react";var je="https://bitter-river-9c62.support-67d.workers.dev",We="https://d339co84ntxcme.cloudfront.net/Prod/orders",v=null;function Pt(t){v=t}function A(t){let e=t?.storeId||v?.storeId;return e||(console.warn("[ElevateAB] No storeId provided. Call initAnalytics() first or pass storeId to tracking function."),"")}function Je(t){return Object.entries(t).filter(([,e])=>typeof e=="string").map(([e,r])=>({test_id:e,variant_id:r}))}function Ye(t,e){return Object.entries(t).filter(([r])=>typeof e[r]=="string").map(([r])=>({test_id:r,variant_id:e[r]}))}function Qe(){return typeof window>"u"?!1:b("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function U(t,e,r){if(typeof window>"u"||Qe())return null;let o=navigator.userAgent,n=window.location.pathname,s=ot(n,r),{referrer:a,entryPage:c}=dt(),i=nt({referrer:a,entryPage:c,userAgent:o}),d=k("ABTL")||{},u=k("ABAU")||{},p=Je(d),l=Ye(u,d),C=et(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",f=b("localization")||"";return{pixel_event_id:`sh-${it()}`,shop_name:t,timestamp:y,event_type:e,client_id:b("_shopify_y")||void 0,visitor_id:ct(),session_id:lt(),cart_token:rt(C||b("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:at(o),is_first_visit:h,shopify_country:f,ab_test_assignments:p,ab_test_views:l,is_first_order:null}}async function I(t,e=je){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 Yt(t={}){let e=A(t);if(!e)return;let r=t.hasLocalizedPaths??v?.hasLocalizedPaths,o=t.workerUrl??v?.workerUrl,n=U(e,"page_viewed",r);if(!n)return;let s={...n,cart_currency:t.currency};await I(s,o)}async function Ke(t){let e=A(t);if(!e)return;let{productId:r,productVendor:o,productPrice:n,productSku:s,currency:a}=t,c=t.hasLocalizedPaths??v?.hasLocalizedPaths,i=t.workerUrl??v?.workerUrl,d=U(e,"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 I(u,i)}async function Xe(t){let e=A(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i,cartId:d}=t,u=t.hasLocalizedPaths??v?.hasLocalizedPaths,p=t.workerUrl??v?.workerUrl,l=t.storefrontAccessToken??v?.storefrontAccessToken,C=U(e,"product_added_to_cart",u);if(!C)return;let y={...C,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 I(y,p),d&&l)try{let{updateCartAttributes:h}=await import("./cartAttributes-OFPJ33X2.js");await h(d,{storefrontAccessToken:l})}catch(h){console.error("[ElevateAB] Failed to update cart attributes:",h)}}async function Ze(t){let e=A(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:s,productQuantity:a,productSku:c,currency:i}=t,d=t.hasLocalizedPaths??v?.hasLocalizedPaths,u=t.workerUrl??v?.workerUrl,p=U(e,"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 I(l,u)}async function tr(t){let e=A(t);if(!e)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:s}=t,a=t.hasLocalizedPaths??v?.hasLocalizedPaths,c=t.workerUrl??v?.workerUrl,i=U(e,"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 I(d,c)}async function er(t){let e=A(t);if(!e)return;let{searchQuery:r,currency:o}=t,n=t.hasLocalizedPaths??v?.hasLocalizedPaths,s=t.workerUrl??v?.workerUrl,a=U(e,"search_submitted",n);if(!a)return;let c={...a,cart_currency:o,search_query:w(r)};await I(c,s)}async function rr(t){let e=A(t);if(!e)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:s,cartDiscountAmount:a,customerId:c,cartItems:i,currency:d}=t,u=t.hasLocalizedPaths??v?.hasLocalizedPaths,p=t.workerUrl??v?.workerUrl,l=U(e,"checkout_started",u);if(!l)return;let C=0,y=i?.map(f=>{let P=f.productQuantity??0;return C+=P,{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:P,quantity:P,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:C,cart_shipping_price:m(n),cart_tax_amount:m(s),cart_discount_amount:m(a),cart_items:y,customer_id:c};await I(h,p)}async function nr(t){let e=A(t);if(!e)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:s,cartTaxAmount:a,cartDiscountAmount:c,customerId:i,isFirstOrder:d,noteAttributes:u,cartItems:p,currency:l}=t,C=t.hasLocalizedPaths??v?.hasLocalizedPaths,y=t.ordersWorkerUrl??v?.ordersWorkerUrl??We,h=U(e,"checkout_completed",C);if(!h)return;let f=0,P=p?.map(g=>{let M=g.productQuantity??0;return f+=M,{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:M,quantity:M,product_sku:w(g.productSku)||"",sku:w(g.productSku)||"",total_discount:m(g.totalDiscount)}})||[],T={...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:P,order_id:r,customer_id:i,is_first_order:d??null,note_attributes:u};await I(T,y)}function ir(t){let{storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:s=!0,pathname:a}=t,c=or(null),[i,d]=ar(()=>a||(typeof window<"u"?window.location.pathname:""));Jt(()=>{a&&d(a)},[a]),Jt(()=>{typeof window>"u"||!s||c.current!==i&&(c.current=i,Yt({storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[i,e,r,o,n,s])}import O from"react";var K=new Map;function N(t){K.set(t.type,t)}function X(t){return K.get(t)}function Qt(){return Array.from(K.values())}function Kt(t){return K.has(t)}function sr(t){try{let o=new URL(t,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return o?o[1]:null}catch{return null}}function cr(t,e,r,o){if(typeof window>"u"||!t.prices||!e)return;let n=t.prices[e];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}}",e);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}}",e);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}}",e);document.querySelectorAll(u).forEach(l=>{let C=parseFloat(s),y=parseFloat(a),h=y-C;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 Tt={type:"PRICE_PLUS",shouldActivate(t,e){let r=t.data;if(!r)return!1;let{productId:o,productHandle:n}=e,s=n||sr(e.currentUrl),a=o&&r.productIds?.includes(o),c=s&&r.handles?.includes(s);return a||c},applyEffect(t,e,r){cr(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 lr(t,e){let o=t.data?.pathnames||[];if(!o.length)return!0;try{let s=new URL(e,"https://example.com").pathname;return o.some(a=>B(s,a))}catch{return!1}}var Z={type:"CONTENT",shouldActivate(t,e){return lr(t,e.currentUrl)},getVariantData(t,e,r){let o=t.data;return{content:e.content,pathnames:o?.pathnames,handlerActivated:!0}}};N(Tt);N(gt);N(Z);function dr(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 s,c=new URLSearchParams(window.location.search).get("variant");return c&&(s=c),{currentUrl:e,productHandle:o,variantId:s,selectors:t,currencyCode:"USD"}}function ur(t){let{config:e,previewState:r,selectors:o}=tt(),[n,s]=O.useState(null),[a,c]=O.useState(!0),i=O.useMemo(()=>e&&e.tests.find(l=>l.testId===t)||null,[e,t]),d=O.useMemo(()=>r||H(),[r]),u=O.useRef(null),p=O.useRef(null);return O.useEffect(()=>{let l=!0;if(e===null)return;if(!i){u.current!==t&&(u.current=t,console.warn(`[ElevateAB] Test not found: ${t}`)),l&&c(!1);return}if(!i.enabled&&!d?.isPreview){u.current!==`${t}-disabled`&&(u.current=`${t}-disabled`,console.warn(`[ElevateAB] Test disabled: ${t}`)),l&&c(!1);return}let C=V(t);if(!C){l&&c(!1);return}let y=i.variations.find(T=>T.id===C);if(!y){l&&c(!1);return}let h=X(i.type),f=dr(o),P={...y};if(h?.shouldActivate(i,f)){let T=`${t}-${y.id}`;h.applyEffect&&p.current!==T&&(p.current=T,h.applyEffect(i,y,f));let g=h.getVariantData(i,y,f);P={...P,...g}}return l&&s(P),d?.isPreview||pt(t),l&&c(!1),()=>{l=!1}},[e,i,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 pr,useCallback as fr}from"react";import{jsx as hr,jsxs as wr}from"react/jsx-runtime";var mr="https://d19dz5bxptjmv5.cloudfront.net/headless";function gr(t){return t.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function Xt(t){return`${mr}/${gr(t)}.js`}function yr({storeId:t,storefrontAccessToken:e,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:s}){let[a,c]=E.useState(null),[i,d]=E.useState(null),[u,p]=E.useState(null);E.useEffect(()=>{if(typeof window>"u")return;Pt({storeId:t,storefrontAccessToken:e});let P=H();d(P);let T=L();p(T)},[t,e]);let l=fr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);E.useEffect(()=>{async function P(){try{let T=typeof window<"u"?H():null,g=null;if(typeof window<"u"&&window.eab_data)g=window.eab_data;else{let F=Xt(t);g=await new Promise((_t,Zt)=>{let R=document.createElement("script");R.src=F,R.async=!0,R.onload=()=>{let bt=window.eab_data;R.remove(),bt?_t(bt):Zt(new Error("Failed to load config: window.eab_data is undefined"))},R.onerror=()=>{R.remove(),_t({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(R)})}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: ${t}. `+(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=Et(g);if(ut(z,T),z.tests.some(F=>F.type==="SPLIT_URL")&&q(z,T))return;c(z),l()}catch(T){console.error("[ElevateAB] Failed to load config:",T),c({tests:[],selectors:void 0}),l()}}P()},[t,l]),E.useEffect(()=>!a||typeof window>"u"||!Y(a)?void 0:(Q(a,i,n),Ct(a,i,n)),[a,i,n]);let C=E.useMemo(()=>({config:a,storeId:t,storefrontAccessToken:e,isPreviewMode:i?.isPreview??!1,previewTestId:i?.previewTestId??null,previewState:i,selectors:a?.selectors,countryCode:u}),[a,t,e,i,u]),y=pr(!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(()=>Xt(t),[t]),f=E.useMemo(()=>ft({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return wr(kt.Provider,{value:C,children:[hr("script",{nonce:n,dangerouslySetInnerHTML:{__html:f}}),s]})}var gn="1.1.2";export{Pe as CART_ATTRIBUTES_UPDATE_MUTATION,Ve as COUNTRIES,ke as ElevateAnalytics,yr as ElevateProvider,Le as REGIONS,gn as VERSION,Ft as applyContentChanges,$t as applyContentElements,Gt as applyCustomCode,ut as assignAllTests,we as assignAndPersistVariant,pe as buildEabTestsParam,ve as canAssignToTest,At as checkFacebookBrowser,re as checkFacebookInstagramBrowser,Ut as checkInstagramBrowser,Rt as checkPinterestBrowser,It as checkTikTokBrowser,ne as checkVisitorIdParams,rt as cleanCartToken,be as cleanupCartAttributes,Wt as cleanupContentTests,me as clearPreviewMode,Z as contentHandler,oe as deleteCookie,Me as detectShopifyCurrency,et as extractCartToken,te as extractProductId,ee as extractProductVariantId,_ as extractShopifyId,De as extractShopifyType,Qt as getAllHandlers,V as getAssignedVariant,Te as getCartAttributesPayload,b as getCookie,L as getCountryCode,Se as getDeviceType,Ue as getGeoLocation,X as getHandler,k as getJsonCookie,$ as getJsonSessionItem,ot as getPageTypeFromPathname,H as getPreviewState,ue as getPreviewVariation,dt as getReferrerData,lt as getSessionId,ae as getSessionItem,ft as getSplitUrlBlockingScript,ye as getTestList,Ae as getTrafficSource,at as getUserAgentNoBrowser,ct as getVisitorId,Y as hasContentTests,Kt as hasHandler,Ee as hasSessionView,xe as hasUniqueView,le as hashString,Pt as initAnalytics,se as initializeSessionId,ie as initializeVisitorId,Bt as isCountryExcluded,Lt as isCountryIncluded,ge as isInPreviewMode,de as isPreviewTest,Ne as isShopifyGid,Re as matchesGeoTargeting,B as matchesWildcardPattern,nt as parseAddViewData,Q as processContentTests,q as processSplitUrlTests,N as registerHandler,wt as reprocessContentTests,jt as restoreOriginalElements,m as roundToTwo,w as sanitizeString,he as saveTestList,x as setCookie,Vt as setCountryCode,Ie as setGeoLocation,ce as setReferrerData,st as setSessionItem,Ct as setupContentTestListeners,Ce as shouldShowTest,Xe as trackAddToCart,tr as trackCartView,nr as trackCheckoutCompleted,rr as trackCheckoutStarted,Yt as trackPageView,Ke as trackProductView,Ze as trackRemoveFromCart,er as trackSearchSubmitted,St as trackSessionView,xt as trackUniqueView,pt as trackViews,_e as updateCartAttributes,fe as updateUrlWithTestParams,tt as useElevateConfig,ur as useExperiment,ir as usePageViewTracking,it 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,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(/`/g,"`").replace(/$/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};
|
|
30
30
|
//# sourceMappingURL=index.js.map
|