@elevateab/sdk 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.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/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Lt,b as it,c as w,d as g,e as de,f as ue,g as st,h as ct,i as pe,j as lt,k as dt,l as fe,m as ut,n as
|
|
1
|
+
import{a as Lt,b as it,c as w,d as g,e as de,f as ue,g as st,h as ct,i as pe,j as lt,k as dt,l as fe,m as ut,n as Oe}from"./chunk-E3BNNKGR.js";import{A as Se,B as x,C as xe,D as Ae,E as Ue,F as ht,G as Ie,H as Ve,I as Re,J as Le,c as pt,d as S,e as E,f as k,g as me,h as ft,i as ge,j as J,k as ye,l as mt,m as he,n as gt,o as we,p as yt,q as Ce,r as Ot,s as z,t as ve,u as Te,v as Pe,w as _e,x as be,y as Ee,z as ke}from"./chunk-B2OIRKOZ.js";function Ht(t){let e=k("ABAU")||{};e[t]||(e[t]=!0,S("ABAU",JSON.stringify(e)))}function Bt(t){let e=J("ABAV")||{};e[t]||(e[t]=!0,ft("ABAV",e))}function wt(t){Ht(t),Bt(t)}function He(t){return!!(J("ABAV")||{})[t]}function Be(t){return!!(k("ABAU")||{})[t]}function De(){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 Dt(){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 Nt(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/(instagram)[\/ ]([-\w\.]+)/i.test(t)}function Mt(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||navigator.vendor||window.opera;return/musical_ly/i.test(t)}function zt(){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=Dt(),n=Nt(),i=Mt(),a=zt();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 I={SHOPIFY_LOCALIZATION:"localization",EAB_COUNTRY:"eabCountryCode",EAB_GEO:"eabGeoLocation"};function H(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search).get("country");if(e)return S(I.EAB_COUNTRY,e.toUpperCase()),e.toUpperCase();let r=E(I.SHOPIFY_LOCALIZATION);if(r)return r.toUpperCase();let o=E(I.EAB_COUNTRY);if(o)return o.toUpperCase();if(typeof localStorage<"u"){let n=localStorage.getItem(I.EAB_COUNTRY);if(n)return n.toUpperCase()}return null}function Me(){let t=H(),e=E(I.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 Ft(t){let e=t.toUpperCase();S(I.EAB_COUNTRY,e),typeof localStorage<"u"&&localStorage.setItem(I.EAB_COUNTRY,e)}function ze(t){t.country&&Ft(t.country),S(I.EAB_GEO,JSON.stringify(t))}function qt(t,e){let r=e??H();return r?t.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function $t(t,e){let r=e??H();return r?t.map(n=>n.toUpperCase()).includes(r.toUpperCase()):!1}function Fe(t){let e=H();return!t.includeCountries?.length&&!t.excludeCountries?.length?!0:!e||t.excludeCountries?.length&&$t(t.excludeCountries,e)?!1:t.includeCountries?.length?qt(t.includeCountries,e):!0}var qe={US:"US",CA:"CA",GB:"GB",AU:"AU",DE:"DE",FR:"FR",JP:"JP",MX:"MX",BR:"BR",IN:"IN"},$e={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 Y="eab:navigate",Q=!1,Ct=0,$=null,G=null;function Ge(){typeof window>"u"||(Ct++,!Q&&(Q=!0,$=history.pushState.bind(history),G=history.replaceState.bind(history),history.pushState=function(...t){$(...t),window.dispatchEvent(new Event(Y))},history.replaceState=function(...t){G(...t),window.dispatchEvent(new Event(Y))}))}function We(){typeof window>"u"||(Ct--,!(Ct>0||!Q)&&($&&(history.pushState=$,$=null),G&&(history.replaceState=G,G=null),Q=!1))}function F(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(Y,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(Y,r),window.removeEventListener("popstate",r),We()}}function vt(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 it,c as w,d as g,e as de,f as ue,g as st,h as ct,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 Tt(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 a=new URL(t).pathname,i=new URL(o,t).pathname;if(a===i)return!0}catch{}}return!1}function je(t){return t.data?.redirectBehavior||"redirectAll"}function Wt(t){return!!(k("eabRedirectedTests")||{})[t]}function jt(t){let e=k("eabRedirectedTests")||{};e[t]=!0,S("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&&Tt(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:a,matchedVariation:i,isControlUrl:c}=n,s=a.testId,d=je(a),u=x(s);if(!u)return!1;let p=a.variations.find(y=>y.id===u);if(!p)return!1;let l=p.splitUrlTestLinks||[];if(l.length===0||Tt(r,l))return!1;switch(d){case"redirectOnlyControlUrl":if(!c||p.isControl)return!1;break;case"redirectOnce":if(Wt(s))return!1;jt(s);break;case"redirectOnceControlUrlOnly":if(!c||Wt(s)||p.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 Pt={type:"SPLIT_URL",shouldActivate(t,e){for(let r of t.variations){let o=r.splitUrlTestLinks||[];if(Tt(e.currentUrl,o))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};function E(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},K=new Map,X=new Map,Z=new Map,tt=new Map,M=!1;function A(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 kt(){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 Et(t){return t.nodeType===Qt.ELEMENT_NODE}function _t(t,e){K.has(t)||K.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(a=>A(e,a)):!0);M=kt();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((i,c)=>{if(!i)return;let s=n.applyAll?`${n.selector}-${c}-${i.id||Math.random().toString(36).substr(2,9)}`:n.selector;_t(s,i),tr(i)?i.nodeValue=n.content:Et(i)&&(i.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let a=document.querySelector(n.selector);!a||!Et(a)||(_t(n.selector,a),Object.entries(n.style).forEach(([i,c])=>{let s=Ze(i),d=c.toString().includes("!important"),u=c.toString().replace(/\s*!important\s*$/,"");a.style.setProperty(s,u,d?"important":void 0)}))}),o.filter(n=>n.attributes!==void 0).forEach(n=>{let a=document.querySelector(n.selector);!a||!Et(a)||(_t(n.selector,a),Object.entries(n.attributes).forEach(([i,c])=>{a.setAttribute(i,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=>A(e,n)):!0).forEach(o=>{let n=`${Yt}${o.id}`;if(tt.has(n))return;let a=document.querySelector(o.selector.target);if(!a||a.parentElement?.querySelector(`#${n}`))return;let i=te(o);o.selector.placement==="after"?a.after(i):o.selector.placement==="before"&&a.before(i),tt.set(n,i)})}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 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(i=>A(r,i))?!1:n.pathnames.some(a=>A(r,a)):!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}`;if(X.has(r)||document.getElementById(r))return;let o=document.createElement("style");o.id=r,o.textContent=Kt(e),document.head.appendChild(o),X.set(r,o)}function rr(t,e,r){let o=`js-${t}`;if(Z.has(o)||document.getElementById(o))return;let n=document.createElement("script");n.id=o,r&&n.setAttribute("nonce",r);let a=Kt(e);n.textContent="(function(){try{"+a+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(n),Z.set(o,n)}function ee(){K.forEach((t,e)=>{let r=document.querySelector(e);r&&r.replaceWith(t.cloneNode(!0))})}function re(){X.forEach(t=>t.remove()),X.clear(),Z.forEach(t=>t.remove()),Z.clear(),tt.forEach(t=>t.remove()),tt.clear(),K.clear()}function nr(t,e){let r=[],o=[],n=[];return t.tests.filter(i=>i.type==="CONTENT"&&i.enabled).forEach(i=>{let c=x(i.testId);if(!c)return;let s=i.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 G(t){return t.tests.some(e=>e.type==="CONTENT"&&e.enabled)}function rt(t,e,r){if(typeof window>"u"||!G(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),et(o.customCodes,r))}function bt(t,e,r){if(typeof window>"u")return;let o=kt();o!==M&&(ee(),M=o),rt(t,e,r)}function St(t,e,r,o=!0){if(typeof window>"u")return()=>{};let n=()=>{kt()!==M&&bt(t,e,r)};window.addEventListener("resize",n);let a=()=>{};return o&&(a=N(()=>{bt(t,e,r)})),()=>{window.removeEventListener("resize",n),a(),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 xt(t){C=t}function I(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:b("eabUserPreview")==="true"||new URLSearchParams(window.location.search).get("eabUserPreview")==="true"}function V(t,e,r){if(typeof window>"u"||cr())return null;let o=navigator.userAgent,n=window.location.pathname,a=dt(n,r),{referrer:i,entryPage:c}=yt(),s=lt({referrer:i,entryPage:c,userAgent:o}),d=k("ABTL")||{},u=k("ABAU")||{},p=ir(d),l=sr(u,d),v=st(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",f=b("localization")||"";return{pixel_event_id:`sh-${pt()}`,shop_name:t,timestamp:y,event_type:e,client_id:b("_shopify_y")||void 0,visitor_id:mt(),session_id:gt(),cart_token:ct(v||b("cart")),page_url:window.location.href,page_pathname:n,page_search:window.location.search,referrer_url:i,referrer_source:s?.referrer_source,previous_page:document.referrer,page_entry:c,page_entry_path:s?.page_entry_path,page_type:a,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:ut(o),is_first_visit:h,shopify_country:f,ab_test_assignments:p,ab_test_views:l,is_first_order:null}}async function R(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=I(t);if(!e)return;let r=t.hasLocalizedPaths??C?.hasLocalizedPaths,o=t.workerUrl??C?.workerUrl,n=V(e,"page_viewed",r);if(!n)return;let a={...n,cart_currency:t.currency};await R(a,o)}async function lr(t){let e=I(t);if(!e)return;let{productId:r,productVendor:o,productPrice:n,productSku:a,currency:i}=t,c=t.hasLocalizedPaths??C?.hasLocalizedPaths,s=t.workerUrl??C?.workerUrl,d=V(e,"product_viewed",c);if(!d)return;let u={...d,cart_currency:i,product_id:E(r),product_vendor:w(o),product_price:g(n),product_sku:w(a)};await R(u,s)}async function dr(t){let e=I(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:a,productQuantity:i,productSku:c,currency:s,cartId:d}=t,u=t.hasLocalizedPaths??C?.hasLocalizedPaths,p=t.workerUrl??C?.workerUrl,l=t.storefrontAccessToken??C?.storefrontAccessToken,v=V(e,"product_added_to_cart",u);if(!v)return;let y={...v,cart_currency:s,product_id:E(r),variant_id:E(o),product_vendor:w(n),product_price:g(a),product_quantity:i,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 ur(t){let e=I(t);if(!e)return;let{productId:r,variantId:o,productVendor:n,productPrice:a,productQuantity:i,productSku:c,currency:s}=t,d=t.hasLocalizedPaths??C?.hasLocalizedPaths,u=t.workerUrl??C?.workerUrl,p=V(e,"product_removed_from_cart",d);if(!p)return;let l={...p,cart_currency:s,product_id:E(r),variant_id:E(o),product_vendor:w(n),product_price:g(a),product_quantity:i,product_sku:w(c)};await R(l,u)}async function pr(t){let e=I(t);if(!e)return;let{cartTotalPrice:r,cartTotalQuantity:o,cartItems:n,currency:a}=t,i=t.hasLocalizedPaths??C?.hasLocalizedPaths,c=t.workerUrl??C?.workerUrl,s=V(e,"cart_viewed",i);if(!s)return;let d={...s,cart_currency:a,cart_total_price:g(r),cart_total_quantity:o,cart_items:n?.map(u=>({product_id:E(u.productId),variant_id:E(u.variantId),product_vendor:w(u.productVendor)||"",product_price:g(u.productPrice),product_quantity:u.productQuantity??null,product_sku:w(u.productSku)||""}))};await R(d,c)}async function fr(t){let e=I(t);if(!e)return;let{searchQuery:r,currency:o}=t,n=t.hasLocalizedPaths??C?.hasLocalizedPaths,a=t.workerUrl??C?.workerUrl,i=V(e,"search_submitted",n);if(!i)return;let c={...i,cart_currency:o,search_query:w(r)};await R(c,a)}async function mr(t){let e=I(t);if(!e)return;let{cartTotalPrice:r,cartSubtotalPrice:o,cartShippingPrice:n,cartTaxAmount:a,cartDiscountAmount:i,customerId:c,cartItems:s,currency:d}=t,u=t.hasLocalizedPaths??C?.hasLocalizedPaths,p=t.workerUrl??C?.workerUrl,l=V(e,"checkout_started",u);if(!l)return;let v=0,y=s?.map(f=>{let T=f.productQuantity??0;return v+=T,{product_id:E(f.productId),variant_id:E(f.variantId),product_vendor:w(f.productVendor)||"",vendor:w(f.productVendor)||"",product_price:g(f.productPrice),total_price:g(f.productPrice),product_quantity:T,quantity:T,product_sku:w(f.productSku)||"",sku:w(f.productSku)||"",total_discount:g(f.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(a),cart_discount_amount:g(i),cart_items:y,customer_id:c};await R(h,p)}async function gr(t){let e=I(t);if(!e)return;let{orderId:r,cartTotalPrice:o,cartSubtotalPrice:n,cartShippingPrice:a,cartTaxAmount:i,cartDiscountAmount:c,customerId:s,isFirstOrder:d,noteAttributes:u,cartItems:p,currency:l}=t,v=t.hasLocalizedPaths??C?.hasLocalizedPaths,y=t.ordersWorkerUrl??C?.ordersWorkerUrl??ar,h=V(e,"checkout_completed",v);if(!h)return;let f=0,T=p?.map(m=>{let z=m.productQuantity??0;return f+=z,{product_id:E(m.productId),variant_id:E(m.variantId),product_vendor:w(m.productVendor)||"",vendor:w(m.productVendor)||"",product_price:g(m.productPrice),total_price:g(m.productPrice),product_quantity:z,quantity:z,product_sku:w(m.productSku)||"",sku:w(m.productSku)||"",total_discount:g(m.totalDiscount)}})||[],P={...h,cart_currency:l,cart_total_price:g(o),cart_subtotal_price:g(n),cart_total_quantity:f,cart_shipping_price:g(a),cart_tax_amount:g(i),cart_discount_amount:g(c),cart_items:T,order_id:r,customer_id:s,is_first_order:d??null,note_attributes:u};await R(P,y)}function wr(t){let{storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n,enabled:a=!0,pathname:i}=t,c=yr(null),[s,d]=hr(()=>i||(typeof window<"u"?window.location.pathname:""));ne(()=>{i&&d(i)},[i]),ne(()=>{typeof window>"u"||!a||c.current!==s&&(c.current=s,oe({storeId:e,hasLocalizedPaths:r,currency:o,workerUrl:n}))},[s,e,r,o,n,a])}import H from"react";var nt=new Map;function O(t){nt.set(t.type,t)}function ot(t){return nt.get(t)}function ae(){return Array.from(nt.values())}function ie(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 a=n.price?.[r],i=n.compare?.[r],c=o;if(c?.selectorsV2?.length)for(let s of c.selectorsV2){if(s.price&&a){let d=s.price.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(s.compareAt&&i){let d=s.compareAt.replace("{{variant}}",e);document.querySelectorAll(d).forEach(p=>{let l=new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(parseFloat(i));p.textContent=l})}if(s.saving&&a&&i)for(let d of s.saving){let u=d.selector.replace("{{variant}}",e);document.querySelectorAll(u).forEach(l=>{let v=parseFloat(a),y=parseFloat(i),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 At={type:"PRICE_PLUS",shouldActivate(t,e){let r=t.data;if(!r)return!1;let{productId:o,productHandle:n}=e,a=n||Cr(e.currentUrl),i=o&&r.productIds?.includes(o),c=a&&r.handles?.includes(a);return i||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 a=new URL(e,"https://example.com").pathname;return o.some(i=>A(a,i))}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 a=new URL(e,"https://example.com").pathname;return o.some(i=>A(a,i))}catch{return!1}}var Ut={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}}};O(At);O(Pt);O(at);O(Ut);function Er(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 a,c=new URLSearchParams(window.location.search).get("variant");return c&&(a=c),{currentUrl:e,productHandle:o,variantId:a,selectors:t,currencyCode:"USD"}}function _r(t){let{config:e,previewState:r,selectors:o}=it(),[n,a]=H.useState(null),[i,c]=H.useState(!0),s=H.useMemo(()=>e&&e.tests.find(l=>l.testId===t)||null,[e,t]),d=H.useMemo(()=>r||D(),[r]),u=H.useRef(null),p=H.useRef(null);return H.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=x(t);if(!v){l&&c(!1);return}let y=s.variations.find(P=>P.id===v);if(!y){l&&c(!1);return}let h=ot(s.type),f=Er(o),T={...y};if(h?.shouldActivate(s,f)){let P=`${t}-${y.id}`;h.applyEffect&&p.current!==P&&(p.current=P,h.applyEffect(s,y,f));let m=h.getVariantData(s,y,f);T={...T,...m}}return l&&a(T),d?.isPreview||wt(t),l&&c(!1),()=>{l=!1}},[e,s,t,d,o]),{variant:n,isLoading:i,isControl:n?.isControl??!1,isA:n?.isA??!1,isB:n?.isB??!1,isC:n?.isC??!1,isD:n?.isD??!1}}import _,{useRef as br,useCallback as kr}from"react";function It(t){return t.tests.some(e=>e.type==="CUSTOM_CODE"&&e.enabled)}function se(t,e,r){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",t.tests.map(a=>({id:a.testId,type:a.type,enabled:a.enabled}))),!It(t)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let o=t.tests.filter(a=>a.type==="CUSTOM_CODE"&&a.enabled);console.log("[ElevateAB Custom Code] Found",o.length,"CUSTOM_CODE tests");let n=[];o.forEach(a=>{let i=x(a.testId);if(console.log("[ElevateAB Custom Code] Test",a.testId,"assigned variant:",i),!i)return;let c=a.variations.find(s=>s.id===i);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"),et(n,r)):console.log("[ElevateAB Custom Code] No custom code to apply")}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"?_.useLayoutEffect:_.useEffect;function Ur({storeId:t,storefrontAccessToken:e,preventFlickering:r=!1,flickerTimeout:o=3e3,nonce:n,children:a}){let[i,c]=_.useState(null),[s,d]=_.useState(null),[u,p]=_.useState(null);_.useEffect(()=>{if(typeof window>"u")return;xt({storeId:t,storefrontAccessToken:e});let T=D();d(T);let P=B();p(P)},[t,e]);let l=kr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);_.useEffect(()=>{async function T(){try{let P=typeof window<"u"?D():null,m=null;if(typeof window<"u"&&window.eab_data)m=window.eab_data;else{let j=ce(t);m=await new Promise((Vt,le)=>{let L=document.createElement("script");L.src=j,L.async=!0,L.onload=()=>{let Rt=window.eab_data;L.remove(),Rt?Vt(Rt):le(new Error("Failed to load config: window.eab_data is undefined"))},L.onerror=()=>{L.remove(),Vt({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(L)})}if(!m||!m.allTests||Object.keys(m.allTests).length===0){c({tests:[],selectors:void 0}),l();return}if(m.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${t}. `+(m.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),c({tests:[],selectors:void 0}),l();return}if(!(Object.keys(m.allTests||{}).length>0)){c({tests:[],selectors:void 0}),l();return}let W=Bt(m);if(ht(W,P),W.tests.some(j=>j.type==="SPLIT_URL")&&q(W,P))return;c(W),l()}catch(P){console.error("[ElevateAB] Failed to load config:",P),c({tests:[],selectors:void 0}),l()}}T()},[t,l]),Ar(()=>{if(!i||typeof window>"u")return;let T=()=>{Jt(i)&&q(i,s)||(G(i)&&rt(i,s,n),It(i)&&se(i,s,n))};T();let P=N(()=>{T()}),m=G(i)?St(i,s,n,!1):()=>{};return()=>{P(),m()}},[i,s,n]);let v=_.useMemo(()=>({config:i,storeId:t,storefrontAccessToken:e,isPreviewMode:s?.isPreview??!1,previewTestId:s?.previewTestId??null,previewState:s,selectors:i?.selectors,countryCode:u}),[i,t,e,s,u]),y=br(!1);_.useEffect(()=>{!e&&!y.current&&(y.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[e]);let h=_.useMemo(()=>ce(t),[t]),f=_.useMemo(()=>vt({configUrl:h,timeout:r?o:2e3}),[h,r,o]);return Vr(Lt.Provider,{value:v,children:[Ir("script",{nonce:n,dangerouslySetInnerHTML:{__html:f}}),a]})}var Fn="1.1.2";export{Ie as CART_ATTRIBUTES_UPDATE_MUTATION,$e as COUNTRIES,Be as ElevateAnalytics,Ur as ElevateProvider,qe as REGIONS,Fn as VERSION,Xt as applyContentChanges,Zt as applyContentElements,et as applyCustomCode,ht 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,ct as cleanCartToken,Le as cleanupCartAttributes,re as cleanupContentTests,_e as clearPreviewMode,at as contentHandler,me as deleteCookie,Xe as detectShopifyCurrency,st as extractCartToken,de as extractProductId,ue as extractProductVariantId,E as extractShopifyId,Qe as extractShopifyType,ae as getAllHandlers,x as getAssignedVariant,Ve as getCartAttributesPayload,b as getCookie,B as getCountryCode,De as getDeviceType,Me as getGeoLocation,ot as getHandler,k as getJsonCookie,J as getJsonSessionItem,dt as getPageTypeFromPathname,D as getPreviewState,Te as getPreviewVariation,yt as getReferrerData,gt as getSessionId,ge as getSessionItem,vt as getSplitUrlBlockingScript,ke as getTestList,Ne as getTrafficSource,ut as getUserAgentNoBrowser,mt as getVisitorId,G as hasContentTests,ie as hasHandler,Oe as hasSessionView,He as hasUniqueView,Ce as hashString,xt as initAnalytics,he as initializeSessionId,ye as initializeVisitorId,qt as isCountryExcluded,$t as isCountryIncluded,be as isInPreviewMode,ve as isPreviewTest,Ke as isShopifyGid,Fe as matchesGeoTargeting,A as matchesWildcardPattern,lt as parseAddViewData,rt as processContentTests,q as processSplitUrlTests,O as registerHandler,bt as reprocessContentTests,ee as restoreOriginalElements,g as roundToTwo,w as sanitizeString,Se as saveTestList,S as setCookie,Ft as setCountryCode,ze as setGeoLocation,we as setReferrerData,ft as setSessionItem,St 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,Ht as trackSessionView,Ot as trackUniqueView,wt as trackViews,Re as updateCartAttributes,Ee as updateUrlWithTestParams,it as useElevateConfig,_r as useExperiment,wr as usePageViewTracking,pt as uuidv4};
|
|
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 Tt(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!!(k("eabRedirectedTests")||{})[t]}function jt(t){let e=k("eabRedirectedTests")||{};e[t]=!0,S("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&&Tt(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 W(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=x(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||Tt(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 Pt={type:"SPLIT_URL",shouldActivate(t,e){for(let r of t.variations){let o=r.splitUrlTestLinks||[];if(Tt(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},K=new Map,X=new Map,Z=new Map,tt=new Map,q=!1;function A(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 kt(){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 _t(t){return t.nodeType===Qt.ELEMENT_NODE}function bt(t,e){K.has(t)||K.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=>A(e,i)):!0);q=kt();let o=r.map(n=>({...n,style:n.style?{...n.style.lg,...q&&n.style.sm}:void 0,content:n.content&&q&&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;bt(s,a),tr(a)?a.nodeValue=n.content:_t(a)&&(a.innerHTML=n.content)})}),o.filter(n=>n.style!==void 0).forEach(n=>{let i=document.querySelector(n.selector);!i||!_t(i)||(bt(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||!_t(i)||(bt(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=>A(e,n)):!0).forEach(o=>{let n=`${Yt}${o.id}`;if(tt.has(n))return;let i=document.querySelector(o.selector.target);if(!i||i.parentElement?.querySelector(`#${n}`))return;let a=te(o);o.selector.placement==="after"?i.after(a):o.selector.placement==="before"&&i.before(a),tt.set(n,a)})}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 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=>A(r,a))?!1:n.pathnames.some(i=>A(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}`;if(X.has(r)||document.getElementById(r))return;let o=document.createElement("style");o.id=r,o.textContent=Kt(e),document.head.appendChild(o),X.set(r,o)}function rr(t,e,r){let o=`js-${t}`;if(Z.has(o)||document.getElementById(o))return;let n=document.createElement("script");n.id=o,r&&n.setAttribute("nonce",r);let i=Kt(e);n.textContent="(function(){try{"+i+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(n),Z.set(o,n)}function ee(){K.forEach((t,e)=>{let r=document.querySelector(e);r&&r.replaceWith(t.cloneNode(!0))})}function re(){X.forEach(t=>t.remove()),X.clear(),Z.forEach(t=>t.remove()),Z.clear(),tt.forEach(t=>t.remove()),tt.clear(),K.clear()}function nr(t,e){let r=[],o=[],n=[];return t.tests.filter(a=>a.type==="CONTENT"&&a.enabled).forEach(a=>{let c=x(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 j(t){return t.tests.some(e=>e.type==="CONTENT"&&e.enabled)}function rt(t,e,r){if(typeof window>"u"||!j(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),et(o.customCodes,r))}function Et(t,e,r){if(typeof window>"u")return;let o=kt();o!==q&&(ee(),q=o),rt(t,e,r)}function St(t,e,r,o=!0){if(typeof window>"u")return()=>{};let n=()=>{kt()!==q&&Et(t,e,r)};window.addEventListener("resize",n);let i=()=>{};return o&&(i=F(()=>{Et(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 xt(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:E("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=dt(n,r),{referrer:a,entryPage:c}=yt(),s=lt({referrer:a,entryPage:c,userAgent:o}),d=k("ABTL")||{},u=k("ABAU")||{},f=ir(d),l=sr(u,d),v=st(localStorage.getItem("shopifyCartId")),y=new Date().toISOString(),h=sessionStorage.getItem("eabIsFirstVisit")==="true",m=E("localization")||"";return{pixel_event_id:`sh-${pt()}`,shop_name:t,timestamp:y,event_type:e,client_id:E("_shopify_y")||void 0,visitor_id:mt(),session_id:gt(),cart_token:ct(v||E("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:ut(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 T=m.productQuantity??0;return v+=T,{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:T,quantity:T,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,T=f?.map(p=>{let N=p.productQuantity??0;return m+=N,{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:N,quantity:N,product_sku:w(p.productSku)||"",sku:w(p.productSku)||"",total_discount:g(p.totalDiscount)}})||[],P={...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:T,order_id:r,customer_id:s,is_first_order:d??null,note_attributes:u};await L(P,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 nt=new Map;function B(t){nt.set(t.type,t)}function ot(t){return nt.get(t)}function ae(){return Array.from(nt.values())}function ie(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 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 At={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=>A(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=>A(i,a))}catch{return!1}}var Ut={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(At);B(Pt);B(at);B(Ut);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}=it(),[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||z(),[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=x(t);if(!v){l&&c(!1);return}let y=s.variations.find(P=>P.id===v);if(!y){l&&c(!1);return}let h=ot(s.type),m=_r(o),T={...y};if(h?.shouldActivate(s,m)){let P=`${t}-${y.id}`;h.applyEffect&&f.current!==P&&(f.current=P,h.applyEffect(s,y,m));let p=h.getVariantData(s,y,m);T={...T,...p}}return l&&i(T),d?.isPreview||wt(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 b,{useRef as Er,useCallback as kr}from"react";function It(t){return t.tests.some(e=>e.type==="CUSTOM_CODE"&&e.enabled)}function se(t,e,r){if(typeof window>"u"||!It(t))return;let o=t.tests.filter(i=>i.type==="CUSTOM_CODE"&&i.enabled),n=[];o.forEach(i=>{let a=x(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 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"?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,d]=b.useState(null),[u,f]=b.useState(null);b.useEffect(()=>{if(typeof window>"u")return;xt({storeId:t,storefrontAccessToken:e});let T=z();d(T);let P=H();f(P)},[t,e]);let l=kr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);b.useEffect(()=>{async function T(){try{let P=typeof window<"u"?z():null,p=null;if(typeof window<"u"&&window.eab_data)p=window.eab_data;else{let U=ce(t);p=await new Promise((Vt,le)=>{let O=document.createElement("script");O.src=U,O.async=!0,O.onload=()=>{let Rt=window.eab_data;O.remove(),Rt?Vt(Rt):le(new Error("Failed to load config: window.eab_data is undefined"))},O.onerror=()=>{O.remove(),Vt({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 M=Ot(p);if(ht(M,P),M.tests.some(U=>U.type==="SPLIT_URL")&&W(M,P))return;c(M),l()}catch(P){console.error("[ElevateAB] Failed to load config:",P),c({tests:[],selectors:void 0}),l()}}T()},[t,l]),Ar(()=>{if(!a||typeof window>"u")return;let T=()=>Jt(a)?W(a,s):!1,P=()=>{if(j(a))try{rt(a,s,n)}catch(U){console.error("[ElevateAB] Failed to apply CONTENT tests:",U)}if(It(a))try{se(a,s,n)}catch(U){console.error("[ElevateAB] Failed to apply CUSTOM_CODE tests:",U)}};T()||P();let p=null,N=F(()=>{T()||(P(),p!==null&&window.cancelAnimationFrame(p),p=window.requestAnimationFrame(()=>{P(),p=null}))}),M=j(a)?St(a,s,n,!1):()=>{};return()=>{p!==null&&window.cancelAnimationFrame(p),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:u}),[a,t,e,s,u]),y=Er(!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(()=>ce(t),[t]),m=b.useMemo(()=>vt({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,et as applyCustomCode,ht 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,ct as cleanCartToken,Le as cleanupCartAttributes,re as cleanupContentTests,be as clearPreviewMode,at as contentHandler,me as deleteCookie,Xe as detectShopifyCurrency,st as extractCartToken,de as extractProductId,ue as extractProductVariantId,_ as extractShopifyId,Qe as extractShopifyType,ae as getAllHandlers,x as getAssignedVariant,Ve as getCartAttributesPayload,E as getCookie,H as getCountryCode,De as getDeviceType,Me as getGeoLocation,ot as getHandler,k as getJsonCookie,J as getJsonSessionItem,dt as getPageTypeFromPathname,z as getPreviewState,Te as getPreviewVariation,yt as getReferrerData,gt as getSessionId,ge as getSessionItem,vt as getSplitUrlBlockingScript,ke as getTestList,Ne as getTrafficSource,ut as getUserAgentNoBrowser,mt as getVisitorId,j as hasContentTests,ie as hasHandler,He as hasSessionView,Be as hasUniqueView,Ce as hashString,xt 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,A as matchesWildcardPattern,lt as parseAddViewData,rt as processContentTests,W as processSplitUrlTests,B as registerHandler,Et as reprocessContentTests,ee as restoreOriginalElements,g as roundToTwo,w as sanitizeString,Se as saveTestList,S as setCookie,Ft as setCountryCode,ze as setGeoLocation,we as setReferrerData,ft as setSessionItem,St 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,wt as trackViews,Re as updateCartAttributes,_e as updateUrlWithTestParams,it as useElevateConfig,br as useExperiment,wr as usePageViewTracking,pt as uuidv4};
|
|
30
30
|
//# sourceMappingURL=index.js.map
|