@elevateab/sdk 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -96
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.cjs.map +1 -1
- package/dist/next.js +1 -1
- package/dist/next.js.map +1 -1
- package/package.json +1 -1
package/dist/next.js
CHANGED
|
@@ -27,5 +27,5 @@ import{a as fr,b as mr,c as Et,d as be,e as Y,f as D,g as N,h as Qe,i as Ke,j as
|
|
|
27
27
|
if(window.__eab_reveal)window.__eab_reveal();
|
|
28
28
|
};
|
|
29
29
|
document.head.appendChild(script);
|
|
30
|
-
})();`}function Ft(e){if(!e?.trim())return"";try{let o=`https://${e.trim().replace(/^https?:\/\//,"")}`,i=new URL(o.replace(/\/+$/,""));return i.hostname.startsWith("www.")&&(i.hostname=i.hostname.substring(4)),i.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function tt(e,t){let o=Ft(e.split("?")[0]);for(let i of t){let r=Ft(i.split("?")[0]);if(o===r)return!0;try{let l=new URL(e).pathname,u=new URL(i,e).pathname;if(l===u)return!0}catch{}}return!1}function xr(e){return e.data?.redirectBehavior||"redirectAll"}function jt(e){return!!(N("eabRedirectedTests")||{})[e]}function $t(e){let t=N("eabRedirectedTests")||{};t[e]=!0,Y("eabRedirectedTests",JSON.stringify(t))}function Er(e,t){for(let o of e.tests)if(!(o.type!=="SPLIT_URL"||!o.enabled))for(let i of o.variations){let r=i.splitUrlTestLinks||[];if(r.length!==0&&tt(t,r))return{test:o,matchedVariation:i,isControlUrl:!!i.isControl}}return null}function Tr(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let o=t.toString(),i=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(i&&typeof i=="function")try{let r=t.pathname+t.search;i(r);return}catch{}window.location.href=o}function Re(e,t){if(typeof window>"u")return!1;let o=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let r=Er(e,o);if(!r)return!1;let{test:l,matchedVariation:u,isControlUrl:f}=r,p=l.testId,h=xr(l),a=H(p);if(!a)return!1;let c=l.variations.find(d=>d.id===a);if(!c)return!1;let n=c.splitUrlTestLinks||[];if(n.length===0||tt(o,n))return!1;switch(h){case"redirectOnlyControlUrl":if(!f||c.isControl)return!1;break;case"redirectOnce":if(jt(p))return!1;$t(p);break;case"redirectOnceControlUrlOnly":if(!f||jt(p)||c.isControl)return!1;$t(p);break;default:break}let s=n[0];return Tr(s),!0}var rt={type:"SPLIT_URL",shouldActivate(e,t){for(let o of e.variations){let i=o.splitUrlTestLinks||[];if(tt(t.currentUrl,i))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};var Gt="elv-el-",Wt={ELEMENT_NODE:1,TEXT_NODE:3},Oe=new Map,Ve=new Map,Le=new Map,Be=new Map,ee=!1;function z(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let o=t.slice(1,-1);return e.includes(o)}if(t.startsWith("*")){let o=t.slice(1);return e.endsWith(o)}return t===e}function at(){return typeof window>"u"?!1:window.innerWidth<768}function Ar(e){let t="";for(let o=0;o<e.length;o++){let i=e[o];i>="A"&&i<="Z"?(o!==0&&(t+="-"),t+=i.toLowerCase()):t+=i}return t}function Sr(e){return e.nodeType===Wt.TEXT_NODE}function ot(e){return e.nodeType===Wt.ELEMENT_NODE}function nt(e,t){Oe.has(e)||Oe.set(e,t.cloneNode(!0))}function Yt(e){let t=e;t=t.replace(/`/g,"`").replace(/$/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function Jt(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,o=e.filter(r=>r.pathnames?.length?r.pathnames.some(l=>z(t,l)):!0);ee=at();let i=o.map(r=>({...r,style:r.style?{...r.style.lg,...ee&&r.style.sm}:void 0,content:r.content&&ee&&r.content.sm?r.content.sm:r.content?.lg}));i.filter(r=>r.content!==void 0).forEach(r=>{(r.applyAll?Array.from(document.querySelectorAll(r.selector)):[document.querySelector(r.selector)].filter(Boolean)).forEach((u,f)=>{if(!u)return;let p=r.applyAll?`${r.selector}-${f}-${u.id||Math.random().toString(36).substr(2,9)}`:r.selector;nt(p,u),Sr(u)?u.nodeValue=r.content:ot(u)&&(u.innerHTML=r.content)})}),i.filter(r=>r.style!==void 0).forEach(r=>{let l=document.querySelector(r.selector);!l||!ot(l)||(nt(r.selector,l),Object.entries(r.style).forEach(([u,f])=>{let p=Ar(u),h=f.toString().includes("!important"),a=f.toString().replace(/\s*!important\s*$/,"");l.style.setProperty(p,a,h?"important":void 0)}))}),i.filter(r=>r.attributes!==void 0).forEach(r=>{let l=document.querySelector(r.selector);!l||!ot(l)||(nt(r.selector,l),Object.entries(r.attributes).forEach(([u,f])=>{l.setAttribute(u,f)}))})}function Qt(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(i=>i.selector?.pathnames?.length?i.selector.pathnames.some(r=>z(t,r)):!0).forEach(i=>{let r=`${Gt}${i.id}`;if(Be.has(r))return;let l=document.querySelector(i.selector.target);if(!l||l.parentElement?.querySelector(`#${r}`))return;let u=Kt(i);i.selector.placement==="after"?l.after(u):i.selector.placement==="before"&&l.before(u),Be.set(r,u)})}function Kt(e){let t=document.createElement(e.tagName);return t.id=`${Gt}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([o,i])=>{t.setAttribute(o,i)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(o=>{let i=Kt(o);t.appendChild(i)}),t}function De(e,t){if(typeof window>"u"||e.length===0)return;let o=window.location.pathname;e.filter(r=>r.pathnames?.length?r.excludePathnames?.length&&r.excludePathnames.some(u=>z(o,u))?!1:r.pathnames.some(l=>z(o,l)):!0).forEach(r=>{r.id&&(r.css&&Ir(r.id,r.css),r.js&&Ur(r.id,r.js,t))})}function Ir(e,t){let o=`css-${e}`;if(Ve.has(o)||document.getElementById(o))return;let i=document.createElement("style");i.id=o,i.textContent=Yt(t),document.head.appendChild(i),Ve.set(o,i)}function Ur(e,t,o){let i=`js-${e}`;if(Le.has(i)||document.getElementById(i))return;let r=document.createElement("script");r.id=i,o&&r.setAttribute("nonce",o);let l=Yt(t);r.textContent="(function(){try{"+l+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(r),Le.set(i,r)}function Xt(){Oe.forEach((e,t)=>{let o=document.querySelector(t);o&&o.replaceWith(e.cloneNode(!0))})}function Zt(){Ve.forEach(e=>e.remove()),Ve.clear(),Le.forEach(e=>e.remove()),Le.clear(),Be.forEach(e=>e.remove()),Be.clear(),Oe.clear()}function Rr(e,t){let o=[],i=[],r=[];return e.tests.filter(u=>u.type==="CONTENT"&&u.enabled).forEach(u=>{let f=H(u.testId);if(!f)return;let p=u.variations.find(h=>h.id===f);p?.content&&(p.content.changes?.length&&o.push(...p.content.changes),p.content.elements?.length&&i.push(...p.content.elements),p.content.customCodes?.length&&r.push(...p.content.customCodes))}),{changes:o,elements:i,blocks:[],customCodes:r}}function Ne(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function Me(e,t,o){if(typeof window>"u"||!Ne(e))return;let i=Rr(e,t);(i.changes.length>0||i.elements.length>0||i.customCodes.length>0)&&(Jt(i.changes),Qt(i.elements),De(i.customCodes,o))}function it(e,t,o){if(typeof window>"u")return;let i=at();i!==ee&&(Xt(),ee=i),Me(e,t,o)}function st(e,t,o){if(typeof window>"u")return()=>{};let i=()=>{at()!==ee&&it(e,t,o)},r=()=>{it(e,t,o)};return window.addEventListener("resize",i),window.addEventListener("popstate",r),()=>{window.removeEventListener("resize",i),window.removeEventListener("popstate",r),Zt()}}function ct(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function dt(e,t,o){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(l=>({id:l.testId,type:l.type,enabled:l.enabled}))),!ct(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let i=e.tests.filter(l=>l.type==="CUSTOM_CODE"&&l.enabled);console.log("[ElevateAB Custom Code] Found",i.length,"CUSTOM_CODE tests");let r=[];i.forEach(l=>{let u=H(l.testId);if(console.log("[ElevateAB Custom Code] Test",l.testId,"assigned variant:",u),!u)return;let f=l.variations.find(p=>p.id===u);if(console.log("[ElevateAB Custom Code] Variation data:",f),!f?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(f.customCode.js||f.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",f.customCode),r.push(f.customCode))}),r.length>0?(console.log("[ElevateAB Custom Code] Applying",r.length,"custom code blocks"),De(r,o)):console.log("[ElevateAB Custom Code] No custom code to apply")}function Or(e,t,o){typeof window>"u"||dt(e,t,o)}function er(e,t,o){if(typeof window>"u")return()=>{};let i=()=>{Or(e,t,o)};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}}import{jsx as Nr,jsxs as Mr}from"react/jsx-runtime";var Br="https://d19dz5bxptjmv5.cloudfront.net/headless";function Dr(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function tr(e){return`${Br}/${Dr(e)}.js`}function ut({storeId:e,storefrontAccessToken:t,preventFlickering:o=!1,flickerTimeout:i=3e3,nonce:r,children:l}){let[u,f]=R.useState(null),[p,h]=R.useState(null),[a,c]=R.useState(null);R.useEffect(()=>{if(typeof window>"u")return;de({storeId:e,storefrontAccessToken:t});let m=J();h(m);let g=Q();c(g)},[e,t]);let n=Lr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);R.useEffect(()=>{async function m(){try{let g=typeof window<"u"?J():null,y=null;if(typeof window<"u"&&window.eab_data)y=window.eab_data;else{let q=tr(e);y=await new Promise((W,F)=>{let V=document.createElement("script");V.src=q,V.async=!0,V.onload=()=>{let te=window.eab_data;V.remove(),te?W(te):F(new Error("Failed to load config: window.eab_data is undefined"))},V.onerror=()=>{V.remove(),W({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(V)})}if(!y||!y.allTests||Object.keys(y.allTests).length===0){f({tests:[],selectors:void 0}),n();return}if(y.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(y.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),f({tests:[],selectors:void 0}),n();return}if(!(Object.keys(y.allTests||{}).length>0)){f({tests:[],selectors:void 0}),n();return}let O=Et(y);if(Xe(O,g),O.tests.some(q=>q.type==="SPLIT_URL")&&Re(O,g))return;f(O),n()}catch(g){console.error("[ElevateAB] Failed to load config:",g),f({tests:[],selectors:void 0}),n()}}m()},[e,n]),R.useEffect(()=>!u||typeof window>"u"||!Ne(u)?void 0:(Me(u,p,r),st(u,p,r)),[u,p,r]),R.useEffect(()=>!u||typeof window>"u"||!ct(u)?void 0:(dt(u,p,r),er(u,p,r)),[u,p,r]);let s=R.useMemo(()=>({config:u,storeId:e,storefrontAccessToken:t,isPreviewMode:p?.isPreview??!1,previewTestId:p?.previewTestId??null,previewState:p,selectors:u?.selectors,countryCode:a}),[u,e,t,p,a]),d=Vr(!1);R.useEffect(()=>{!t&&!d.current&&(d.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let _=R.useMemo(()=>tr(e),[e]),k=R.useMemo(()=>et({configUrl:_,timeout:o?i:2e3}),[_,o,i]);return Mr(_e.Provider,{value:s,children:[Nr("script",{nonce:r,dangerouslySetInnerHTML:{__html:k}}),l]})}import{usePathname as zr,useSearchParams as qr}from"next/navigation";import{jsx as rr,jsxs as $r}from"react/jsx-runtime";function Fr({currency:e}){let t=zr(),o=qr();return or(()=>{o.get("eabUserPreview")!=="true"&&Se({currency:e})},[t,o,e]),null}function jr({storeId:e,storefrontAccessToken:t,preventFlickering:o=!1,flickerTimeout:i=3e3,currency:r,children:l}){return or(()=>{de({storeId:e,storefrontAccessToken:t})},[e,t]),$r(ut,{storeId:e,storefrontAccessToken:t,preventFlickering:o,flickerTimeout:i,children:[rr(Hr,{fallback:null,children:rr(Fr,{currency:r})}),l]})}import{useEffect as Gr}from"react";function Wr({productId:e,productVendor:t,productPrice:o,productSku:i,currency:r}){return Gr(()=>{e&&Ie({productId:e,productVendor:t,productPrice:o,productSku:i,currency:r})},[e,t,o,i,r]),null}function nr(e){let t=N("ABAU")||{};t[e]||(t[e]=!0,Y("ABAU",JSON.stringify(t)))}function ir(e){let t=Ke("ABAV")||{};t[e]||(t[e]=!0,Qe("ABAV",t))}function lt(e){nr(e),ir(e)}import X from"react";var ar=new Map;function K(e){ar.set(e.type,e)}function He(e){return ar.get(e)}function Yr(e){try{let i=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return i?i[1]:null}catch{return null}}function Jr(e,t,o,i){if(typeof window>"u"||!e.prices||!t)return;let r=e.prices[t];if(!r)return;let l=r.price?.[o],u=r.compare?.[o],f=i;if(f?.selectorsV2?.length)for(let p of f.selectorsV2){if(p.price&&l){let h=p.price.replace("{{variant}}",t);document.querySelectorAll(h).forEach(c=>{let n=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(parseFloat(l));c.textContent=n})}if(p.compareAt&&u){let h=p.compareAt.replace("{{variant}}",t);document.querySelectorAll(h).forEach(c=>{let n=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(parseFloat(u));c.textContent=n})}if(p.saving&&l&&u)for(let h of p.saving){let a=h.selector.replace("{{variant}}",t);document.querySelectorAll(a).forEach(n=>{let s=parseFloat(l),d=parseFloat(u),_=d-s;if(h.isPercentage){let k=Math.round(_/d*100);n.textContent=`${k}%`}else{let k=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(_);n.textContent=k}})}}}var pt={type:"PRICE_PLUS",shouldActivate(e,t){let o=e.data;if(!o)return!1;let{productId:i,productHandle:r}=t,l=r||Yr(t.currentUrl),u=i&&o.productIds?.includes(i),f=l&&o.handles?.includes(l);return u||f},applyEffect(e,t,o){Jr(t,o.variantId,o.currencyCode||"USD",o.selectors)},getVariantData(e,t,o){let i=e.data;return{prices:t.prices,matchedProductId:o.productId,productIds:i?.productIds,handles:i?.handles,handlerActivated:!0}}};function Qr(e,t){let i=e.data?.pathnames||[];if(!i.length)return!0;try{let l=new URL(t,"https://example.com").pathname;return i.some(u=>z(l,u))}catch{return!1}}var ze={type:"CONTENT",shouldActivate(e,t){return Qr(e,t.currentUrl)},getVariantData(e,t,o){let i=e.data;return{content:t.content,pathnames:i?.pathnames,handlerActivated:!0}}};function Kr(e,t){let i=e.data?.pathnames||[];if(!i.length)return!0;try{let l=new URL(t,"https://example.com").pathname;return i.some(u=>z(l,u))}catch{return!1}}var ft={type:"CUSTOM_CODE",shouldActivate(e,t){return Kr(e,t.currentUrl)},getVariantData(e,t,o){let i=e.data;return{customCode:t.customCode,pathnames:i?.pathnames,excludePathnames:i?.excludePathnames,handlerActivated:!0}}};K(pt);K(rt);K(ze);K(ft);function eo(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,o=window.location.pathname,i,r=o.match(/\/products\/([^\/\?]+)/);r&&(i=r[1]);let l,f=new URLSearchParams(window.location.search).get("variant");return f&&(l=f),{currentUrl:t,productHandle:i,variantId:l,selectors:e,currencyCode:"USD"}}function sr(e){let{config:t,previewState:o,selectors:i}=ke(),[r,l]=X.useState(null),[u,f]=X.useState(!0),p=X.useMemo(()=>t&&t.tests.find(n=>n.testId===e)||null,[t,e]),h=X.useMemo(()=>o||J(),[o]),a=X.useRef(null),c=X.useRef(null);return X.useEffect(()=>{let n=!0;if(t===null)return;if(!p){a.current!==e&&(a.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),n&&f(!1);return}if(!p.enabled&&!h?.isPreview){a.current!==`${e}-disabled`&&(a.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),n&&f(!1);return}let s=H(e);if(!s){n&&f(!1);return}let d=p.variations.find(g=>g.id===s);if(!d){n&&f(!1);return}let _=He(p.type),k=eo(i),m={...d};if(_?.shouldActivate(p,k)){let g=`${e}-${d.id}`;_.applyEffect&&c.current!==g&&(c.current=g,_.applyEffect(p,d,k));let y=_.getVariantData(p,d,k);m={...m,...y}}return n&&l(m),h?.isPreview||lt(e),n&&f(!1),()=>{n=!1}},[t,p,e,h,i]),{variant:r,isLoading:u,isControl:r?.isControl??!1,isA:r?.isA??!1,isB:r?.isB??!1,isC:r?.isC??!1,isD:r?.isD??!1}}import{useEffect as Sn,useContext as In,useRef as Un}from"react";export{jr as ElevateNextProvider,Wr as ProductViewTracker,Tt as clearPreviewMode,I as extractShopifyId,It as extractShopifyType,Q as getCountryCode,J as getPreviewState,At as isInPreviewMode,Ut as isShopifyGid,qt as matchesGeoTargeting,Vt as trackAddToCart,Bt as trackCartView,Mt as trackCheckoutCompleted,Nt as trackCheckoutStarted,Se as trackPageView,Ie as trackProductView,Lt as trackRemoveFromCart,Dt as trackSearchSubmitted,ke as useElevateConfig,sr as useExperiment};
|
|
30
|
+
})();`}function Ft(e){if(!e?.trim())return"";try{let o=`https://${e.trim().replace(/^https?:\/\//,"")}`,i=new URL(o.replace(/\/+$/,""));return i.hostname.startsWith("www.")&&(i.hostname=i.hostname.substring(4)),i.toString().replace(/\/+$/,"")}catch{return e.trim().replace(/\/+$/,"")}}function tt(e,t){let o=Ft(e.split("?")[0]);for(let i of t){let r=Ft(i.split("?")[0]);if(o===r)return!0;try{let l=new URL(e).pathname,u=new URL(i,e).pathname;if(l===u)return!0}catch{}}return!1}function xr(e){return e.data?.redirectBehavior||"redirectAll"}function jt(e){return!!(N("eabRedirectedTests")||{})[e]}function $t(e){let t=N("eabRedirectedTests")||{};t[e]=!0,Y("eabRedirectedTests",JSON.stringify(t))}function Er(e,t){for(let o of e.tests)if(!(o.type!=="SPLIT_URL"||!o.enabled))for(let i of o.variations){let r=i.splitUrlTestLinks||[];if(r.length!==0&&tt(t,r))return{test:o,matchedVariation:i,isControlUrl:!!i.isControl}}return null}function Tr(e){if(typeof window>"u")return;let t=new URL(e,window.location.origin);t.searchParams.set("abtr","true");let o=t.toString(),i=window.__remixRouter?.navigate??window.next?.router?.push??window.$nuxt?.$router?.push??window.__navigate;if(i&&typeof i=="function")try{let r=t.pathname+t.search;i(r);return}catch{}window.location.href=o}function Re(e,t){if(typeof window>"u")return!1;let o=window.location.href;if(new URLSearchParams(window.location.search).get("abtr")==="true")return!1;let r=Er(e,o);if(!r)return!1;let{test:l,matchedVariation:u,isControlUrl:f}=r,p=l.testId,h=xr(l),a=H(p);if(!a)return!1;let c=l.variations.find(d=>d.id===a);if(!c)return!1;let n=c.splitUrlTestLinks||[];if(n.length===0||tt(o,n))return!1;switch(h){case"redirectOnlyControlUrl":if(!f||c.isControl)return!1;break;case"redirectOnce":if(jt(p))return!1;$t(p);break;case"redirectOnceControlUrlOnly":if(!f||jt(p)||c.isControl)return!1;$t(p);break;default:break}let s=n[0];return Tr(s),!0}var rt={type:"SPLIT_URL",shouldActivate(e,t){for(let o of e.variations){let i=o.splitUrlTestLinks||[];if(tt(t.currentUrl,i))return!0}return!1},getVariantData(){return{handlerActivated:!0}}};var Gt="elv-el-",Wt={ELEMENT_NODE:1,TEXT_NODE:3},Oe=new Map,Ve=new Map,Le=new Map,Be=new Map,ee=!1;function z(e,t){if(t==="*")return!0;if(t.startsWith("*")&&t.endsWith("*")){let o=t.slice(1,-1);return e.includes(o)}if(t.startsWith("*")){let o=t.slice(1);return e.endsWith(o)}return t===e}function at(){return typeof window>"u"?!1:window.innerWidth<768}function Ar(e){let t="";for(let o=0;o<e.length;o++){let i=e[o];i>="A"&&i<="Z"?(o!==0&&(t+="-"),t+=i.toLowerCase()):t+=i}return t}function Sr(e){return e.nodeType===Wt.TEXT_NODE}function ot(e){return e.nodeType===Wt.ELEMENT_NODE}function nt(e,t){Oe.has(e)||Oe.set(e,t.cloneNode(!0))}function Yt(e){let t=e;t=t.replace(/`/g,"`").replace(/$/g,"$");try{t=JSON.parse('"'+t+'"')}catch{}return t}function Jt(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname,o=e.filter(r=>r.pathnames?.length?r.pathnames.some(l=>z(t,l)):!0);ee=at();let i=o.map(r=>({...r,style:r.style?{...r.style.lg,...ee&&r.style.sm}:void 0,content:r.content&&ee&&r.content.sm?r.content.sm:r.content?.lg}));i.filter(r=>r.content!==void 0).forEach(r=>{(r.applyAll?Array.from(document.querySelectorAll(r.selector)):[document.querySelector(r.selector)].filter(Boolean)).forEach((u,f)=>{if(!u)return;let p=r.applyAll?`${r.selector}-${f}-${u.id||Math.random().toString(36).substr(2,9)}`:r.selector;nt(p,u),Sr(u)?u.nodeValue=r.content:ot(u)&&(u.innerHTML=r.content)})}),i.filter(r=>r.style!==void 0).forEach(r=>{let l=document.querySelector(r.selector);!l||!ot(l)||(nt(r.selector,l),Object.entries(r.style).forEach(([u,f])=>{let p=Ar(u),h=f.toString().includes("!important"),a=f.toString().replace(/\s*!important\s*$/,"");l.style.setProperty(p,a,h?"important":void 0)}))}),i.filter(r=>r.attributes!==void 0).forEach(r=>{let l=document.querySelector(r.selector);!l||!ot(l)||(nt(r.selector,l),Object.entries(r.attributes).forEach(([u,f])=>{l.setAttribute(u,f)}))})}function Qt(e){if(typeof window>"u"||e.length===0)return;let t=window.location.pathname;e.filter(i=>i.selector?.pathnames?.length?i.selector.pathnames.some(r=>z(t,r)):!0).forEach(i=>{let r=`${Gt}${i.id}`;if(Be.has(r))return;let l=document.querySelector(i.selector.target);if(!l||l.parentElement?.querySelector(`#${r}`))return;let u=Kt(i);i.selector.placement==="after"?l.after(u):i.selector.placement==="before"&&l.before(u),Be.set(r,u)})}function Kt(e){let t=document.createElement(e.tagName);return t.id=`${Gt}${e.id}`,e.style&&Object.assign(t.style,e.style),e.attributes&&Object.entries(e.attributes).forEach(([o,i])=>{t.setAttribute(o,i)}),e.kind==="text"&&e.content&&(t.innerText=e.content),e.kind==="container"&&e.childrens&&e.childrens.forEach(o=>{let i=Kt(o);t.appendChild(i)}),t}function De(e,t){if(typeof window>"u"||e.length===0)return;let o=window.location.pathname;e.filter(r=>r.pathnames?.length?r.excludePathnames?.length&&r.excludePathnames.some(u=>z(o,u))?!1:r.pathnames.some(l=>z(o,l)):!0).forEach(r=>{r.id&&(r.css&&Ir(r.id,r.css),r.js&&Ur(r.id,r.js,t))})}function Ir(e,t){let o=`css-${e}`;if(Ve.has(o)||document.getElementById(o))return;let i=document.createElement("style");i.id=o,i.textContent=Yt(t),document.head.appendChild(i),Ve.set(o,i)}function Ur(e,t,o){let i=`js-${e}`;if(Le.has(i)||document.getElementById(i))return;let r=document.createElement("script");r.id=i,o&&r.setAttribute("nonce",o);let l=Yt(t);r.textContent="(function(){try{"+l+"}catch(e){console.error('[ElevateAB] Custom script error:', e)}})();",document.head.appendChild(r),Le.set(i,r)}function Xt(){Oe.forEach((e,t)=>{let o=document.querySelector(t);o&&o.replaceWith(e.cloneNode(!0))})}function Zt(){Ve.forEach(e=>e.remove()),Ve.clear(),Le.forEach(e=>e.remove()),Le.clear(),Be.forEach(e=>e.remove()),Be.clear(),Oe.clear()}function Rr(e,t){let o=[],i=[],r=[];return e.tests.filter(u=>u.type==="CONTENT"&&u.enabled).forEach(u=>{let f=H(u.testId);if(!f)return;let p=u.variations.find(h=>h.id===f);p?.content&&(p.content.changes?.length&&o.push(...p.content.changes),p.content.elements?.length&&i.push(...p.content.elements),p.content.customCodes?.length&&r.push(...p.content.customCodes))}),{changes:o,elements:i,blocks:[],customCodes:r}}function Ne(e){return e.tests.some(t=>t.type==="CONTENT"&&t.enabled)}function Me(e,t,o){if(typeof window>"u"||!Ne(e))return;let i=Rr(e,t);(i.changes.length>0||i.elements.length>0||i.customCodes.length>0)&&(Jt(i.changes),Qt(i.elements),De(i.customCodes,o))}function it(e,t,o){if(typeof window>"u")return;let i=at();i!==ee&&(Xt(),ee=i),Me(e,t,o)}function st(e,t,o){if(typeof window>"u")return()=>{};let i=()=>{at()!==ee&&it(e,t,o)},r=()=>{it(e,t,o)};return window.addEventListener("resize",i),window.addEventListener("popstate",r),()=>{window.removeEventListener("resize",i),window.removeEventListener("popstate",r),Zt()}}function ct(e){return e.tests.some(t=>t.type==="CUSTOM_CODE"&&t.enabled)}function dt(e,t,o){if(typeof window>"u")return;if(console.log("[ElevateAB Custom Code] All tests:",e.tests.map(l=>({id:l.testId,type:l.type,enabled:l.enabled}))),!ct(e)){console.log("[ElevateAB Custom Code] No CUSTOM_CODE tests found");return}let i=e.tests.filter(l=>l.type==="CUSTOM_CODE"&&l.enabled);console.log("[ElevateAB Custom Code] Found",i.length,"CUSTOM_CODE tests");let r=[];i.forEach(l=>{let u=H(l.testId);if(console.log("[ElevateAB Custom Code] Test",l.testId,"assigned variant:",u),!u)return;let f=l.variations.find(p=>p.id===u);if(console.log("[ElevateAB Custom Code] Variation data:",f),!f?.customCode){console.log("[ElevateAB Custom Code] No customCode on variation");return}(f.customCode.js||f.customCode.css)&&(console.log("[ElevateAB Custom Code] Adding custom code:",f.customCode),r.push(f.customCode))}),r.length>0?(console.log("[ElevateAB Custom Code] Applying",r.length,"custom code blocks"),De(r,o)):console.log("[ElevateAB Custom Code] No custom code to apply")}function Or(e,t,o){typeof window>"u"||dt(e,t,o)}function er(e,t,o){if(typeof window>"u")return()=>{};let i=()=>{Or(e,t,o)};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}}import{jsx as Nr,jsxs as Mr}from"react/jsx-runtime";var Br="https://ds0wlyksfn0sb.cloudfront.net/headless";function Dr(e){return e.replace(/^https?:\/\//,"").replace(".myshopify.com","")}function tr(e){return`${Br}/${Dr(e)}.js`}function ut({storeId:e,storefrontAccessToken:t,preventFlickering:o=!1,flickerTimeout:i=3e3,nonce:r,children:l}){let[u,f]=R.useState(null),[p,h]=R.useState(null),[a,c]=R.useState(null);R.useEffect(()=>{if(typeof window>"u")return;de({storeId:e,storefrontAccessToken:t});let m=J();h(m);let g=Q();c(g)},[e,t]);let n=Lr(()=>{typeof window<"u"&&window.__eab_reveal&&window.__eab_reveal()},[]);R.useEffect(()=>{async function m(){try{let g=typeof window<"u"?J():null,y=null;if(typeof window<"u"&&window.eab_data)y=window.eab_data;else{let q=tr(e);y=await new Promise((W,F)=>{let V=document.createElement("script");V.src=q,V.async=!0,V.onload=()=>{let te=window.eab_data;V.remove(),te?W(te):F(new Error("Failed to load config: window.eab_data is undefined"))},V.onerror=()=>{V.remove(),W({allTests:{},selectors:{selectorsV2:[]}})},document.head.appendChild(V)})}if(!y||!y.allTests||Object.keys(y.allTests).length===0){f({tests:[],selectors:void 0}),n();return}if(y.subscriptionPaused){console.error(`[ElevateAB] Subscription is paused or stopped for store: ${e}. `+(y.subscriptionMessage||"A/B tests will not run. Please reactivate your subscription.")),f({tests:[],selectors:void 0}),n();return}if(!(Object.keys(y.allTests||{}).length>0)){f({tests:[],selectors:void 0}),n();return}let O=Et(y);if(Xe(O,g),O.tests.some(q=>q.type==="SPLIT_URL")&&Re(O,g))return;f(O),n()}catch(g){console.error("[ElevateAB] Failed to load config:",g),f({tests:[],selectors:void 0}),n()}}m()},[e,n]),R.useEffect(()=>!u||typeof window>"u"||!Ne(u)?void 0:(Me(u,p,r),st(u,p,r)),[u,p,r]),R.useEffect(()=>!u||typeof window>"u"||!ct(u)?void 0:(dt(u,p,r),er(u,p,r)),[u,p,r]);let s=R.useMemo(()=>({config:u,storeId:e,storefrontAccessToken:t,isPreviewMode:p?.isPreview??!1,previewTestId:p?.previewTestId??null,previewState:p,selectors:u?.selectors,countryCode:a}),[u,e,t,p,a]),d=Vr(!1);R.useEffect(()=>{!t&&!d.current&&(d.current=!0,console.warn("[ElevateAB] No storefrontAccessToken provided. Orders won't be attributed to test variants."))},[t]);let _=R.useMemo(()=>tr(e),[e]),k=R.useMemo(()=>et({configUrl:_,timeout:o?i:2e3}),[_,o,i]);return Mr(_e.Provider,{value:s,children:[Nr("script",{nonce:r,dangerouslySetInnerHTML:{__html:k}}),l]})}import{usePathname as zr,useSearchParams as qr}from"next/navigation";import{jsx as rr,jsxs as $r}from"react/jsx-runtime";function Fr({currency:e}){let t=zr(),o=qr();return or(()=>{o.get("eabUserPreview")!=="true"&&Se({currency:e})},[t,o,e]),null}function jr({storeId:e,storefrontAccessToken:t,preventFlickering:o=!1,flickerTimeout:i=3e3,currency:r,children:l}){return or(()=>{de({storeId:e,storefrontAccessToken:t})},[e,t]),$r(ut,{storeId:e,storefrontAccessToken:t,preventFlickering:o,flickerTimeout:i,children:[rr(Hr,{fallback:null,children:rr(Fr,{currency:r})}),l]})}import{useEffect as Gr}from"react";function Wr({productId:e,productVendor:t,productPrice:o,productSku:i,currency:r}){return Gr(()=>{e&&Ie({productId:e,productVendor:t,productPrice:o,productSku:i,currency:r})},[e,t,o,i,r]),null}function nr(e){let t=N("ABAU")||{};t[e]||(t[e]=!0,Y("ABAU",JSON.stringify(t)))}function ir(e){let t=Ke("ABAV")||{};t[e]||(t[e]=!0,Qe("ABAV",t))}function lt(e){nr(e),ir(e)}import X from"react";var ar=new Map;function K(e){ar.set(e.type,e)}function He(e){return ar.get(e)}function Yr(e){try{let i=new URL(e,"https://example.com").pathname.match(/\/products\/([^\/\?]+)/);return i?i[1]:null}catch{return null}}function Jr(e,t,o,i){if(typeof window>"u"||!e.prices||!t)return;let r=e.prices[t];if(!r)return;let l=r.price?.[o],u=r.compare?.[o],f=i;if(f?.selectorsV2?.length)for(let p of f.selectorsV2){if(p.price&&l){let h=p.price.replace("{{variant}}",t);document.querySelectorAll(h).forEach(c=>{let n=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(parseFloat(l));c.textContent=n})}if(p.compareAt&&u){let h=p.compareAt.replace("{{variant}}",t);document.querySelectorAll(h).forEach(c=>{let n=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(parseFloat(u));c.textContent=n})}if(p.saving&&l&&u)for(let h of p.saving){let a=h.selector.replace("{{variant}}",t);document.querySelectorAll(a).forEach(n=>{let s=parseFloat(l),d=parseFloat(u),_=d-s;if(h.isPercentage){let k=Math.round(_/d*100);n.textContent=`${k}%`}else{let k=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(_);n.textContent=k}})}}}var pt={type:"PRICE_PLUS",shouldActivate(e,t){let o=e.data;if(!o)return!1;let{productId:i,productHandle:r}=t,l=r||Yr(t.currentUrl),u=i&&o.productIds?.includes(i),f=l&&o.handles?.includes(l);return u||f},applyEffect(e,t,o){Jr(t,o.variantId,o.currencyCode||"USD",o.selectors)},getVariantData(e,t,o){let i=e.data;return{prices:t.prices,matchedProductId:o.productId,productIds:i?.productIds,handles:i?.handles,handlerActivated:!0}}};function Qr(e,t){let i=e.data?.pathnames||[];if(!i.length)return!0;try{let l=new URL(t,"https://example.com").pathname;return i.some(u=>z(l,u))}catch{return!1}}var ze={type:"CONTENT",shouldActivate(e,t){return Qr(e,t.currentUrl)},getVariantData(e,t,o){let i=e.data;return{content:t.content,pathnames:i?.pathnames,handlerActivated:!0}}};function Kr(e,t){let i=e.data?.pathnames||[];if(!i.length)return!0;try{let l=new URL(t,"https://example.com").pathname;return i.some(u=>z(l,u))}catch{return!1}}var ft={type:"CUSTOM_CODE",shouldActivate(e,t){return Kr(e,t.currentUrl)},getVariantData(e,t,o){let i=e.data;return{customCode:t.customCode,pathnames:i?.pathnames,excludePathnames:i?.excludePathnames,handlerActivated:!0}}};K(pt);K(rt);K(ze);K(ft);function eo(e){if(typeof window>"u")return{currentUrl:"",selectors:e};let t=window.location.href,o=window.location.pathname,i,r=o.match(/\/products\/([^\/\?]+)/);r&&(i=r[1]);let l,f=new URLSearchParams(window.location.search).get("variant");return f&&(l=f),{currentUrl:t,productHandle:i,variantId:l,selectors:e,currencyCode:"USD"}}function sr(e){let{config:t,previewState:o,selectors:i}=ke(),[r,l]=X.useState(null),[u,f]=X.useState(!0),p=X.useMemo(()=>t&&t.tests.find(n=>n.testId===e)||null,[t,e]),h=X.useMemo(()=>o||J(),[o]),a=X.useRef(null),c=X.useRef(null);return X.useEffect(()=>{let n=!0;if(t===null)return;if(!p){a.current!==e&&(a.current=e,console.warn(`[ElevateAB] Test not found: ${e}`)),n&&f(!1);return}if(!p.enabled&&!h?.isPreview){a.current!==`${e}-disabled`&&(a.current=`${e}-disabled`,console.warn(`[ElevateAB] Test disabled: ${e}`)),n&&f(!1);return}let s=H(e);if(!s){n&&f(!1);return}let d=p.variations.find(g=>g.id===s);if(!d){n&&f(!1);return}let _=He(p.type),k=eo(i),m={...d};if(_?.shouldActivate(p,k)){let g=`${e}-${d.id}`;_.applyEffect&&c.current!==g&&(c.current=g,_.applyEffect(p,d,k));let y=_.getVariantData(p,d,k);m={...m,...y}}return n&&l(m),h?.isPreview||lt(e),n&&f(!1),()=>{n=!1}},[t,p,e,h,i]),{variant:r,isLoading:u,isControl:r?.isControl??!1,isA:r?.isA??!1,isB:r?.isB??!1,isC:r?.isC??!1,isD:r?.isD??!1}}import{useEffect as Sn,useContext as In,useRef as Un}from"react";export{jr as ElevateNextProvider,Wr as ProductViewTracker,Tt as clearPreviewMode,I as extractShopifyId,It as extractShopifyType,Q as getCountryCode,J as getPreviewState,At as isInPreviewMode,Ut as isShopifyGid,qt as matchesGeoTargeting,Vt as trackAddToCart,Bt as trackCartView,Mt as trackCheckoutCompleted,Nt as trackCheckoutStarted,Se as trackPageView,Ie as trackProductView,Lt as trackRemoveFromCart,Dt as trackSearchSubmitted,ke as useElevateConfig,sr as useExperiment};
|
|
31
31
|
//# sourceMappingURL=next.js.map
|