1var I=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);import{c as b}from"./purchase-checks-C0tMMzGP.js";import"./helpers-DvhljvoO.js";var k=I((P,y)=>{const S={traits:{},customerTraits:{},email:"",isInitialized:!1,_hasIdentified:!1,pendingEvents:[],maxRetries:50,retryDelay:50,productsData:[],init(){if(this.isInitialized=!0,window.__pvolveCustomer){const{email:t,traits:e}=window.__pvolveCustomer;t&&(this.setEmail(t),this.customerTraits={...this.customerTraits,...e}),delete window.__pvolveCustomer}console.log("[SegmentUser] Initialized",this.email?`(user: ${this.email})`:"(anonymous)"),this.processPendingEvents(),this.setIpAddress()},setCustomerData(t,e={}){t&&(this.setEmail(t),this.customerTraits={...this.customerTraits,...e})},getCookie(t){const n=`; ${document.cookie}`.split(`; ${t}=`);return n.length===2?n.pop().split(";").shift():""},normalizeSegmentStoredId(t){if(t==null)return"";let e=String(t).trim();for(let n=0;n<32;n+=1){if(!e)return"";const s=e.toLowerCase();if(s==="null"||s==="undefined")return"";try{const o=JSON.parse(e);if(o==null||typeof o!="string")return"";if(o===e)break;e=o.trim()}catch{break}}return!e||e.length>512||/^["'\\]+$/.test(e)?"":e},getSegmentStoredId(t){try{const e=window.localStorage.getItem(t),n=this.normalizeSegmentStoredId(e);return!n&&e&&window.localStorage.removeItem(t),n}catch{return""}},async getUserId(){try{let t=this.email;return t||(t=this.getSegmentStoredId("ajs_user_id")),t}catch(t){return console.error("[SegmentUser] Error getting user ID:",t),""}}
1,getUserIdSync(){try{return this.email||this.getSegmentStoredId("ajs_user_id")}catch{return this.email||""}},async setIpAddress(){const t=window.sessionStorage.getItem("ipAddress");if(t)try{return JSON.parse(t)}catch{}try{const n=await(await fetch("https://api.lightboxcdn.com/")).json();return window.sessionStorage.setItem("ipAddress",JSON.stringify(n.geo.ip)),n.geo.ip}catch{return""}},getIpAddressSync(){const t=window.sessionStorage.getItem("ipAddress");if(t)try{return JSON.parse(t)}catch{}return this.setIpAddress(),""},getConsentMetadata(t={}){const n={...window.__pvolveConsent&&typeof window.__pvolveConsent=="object"?window.__pvolveConsent:{},...t};return{policy:n.policy||"none",policyRegion:n.policyRegion||"unknown",consentVersion:n.consentVersion||n.version||"unknown"}},getConsentContext(t,e={}){try{if(typeof window.pvolveSegmentConsentContext=="function")return window.pvolveSegmentConsentContext(t,e);const n=t||window.__pvolveConsent&&window.__pvolveConsent.categories||{},s=this.getConsentMetadata(e);let o=typeof n.dataSharing=="boolean"?n.dataSharing:s.policy!=="gdpr"||s.policyRegion==="CA";try{const i=window.Shopify&&window.Shopify.customerPrivacy&&typeof window.Shopify.customerPrivacy.currentVisitorConsent=="function"?window.Shopify.customerPrivacy.currentVisitorConsent():null;typeof n.dataSharing!="boolean"&&i&&(typeof i.sale_of_data=="boolean"?o=i.sale_of_data:typeof i.sale_of_data=="str
1ing"&&i.sale_of_data!==""&&(o=/^(yes|true|1|allowed)$/i.test(i.sale_of_data)))}catch{}return{consent:{categoryPreferences:{Functional:!!n.functional,Analytics:!!n.performance,Advertising:!!n.marketing,DataSharing:o},policy:s.policy,policyRegion:s.policyRegion,consentVersion:s.consentVersion}}}catch{return{consent:{categoryPreferences:{},policy:"none",policyRegion:"unknown",consentVersion:"unknown"}}}},async sendAcknowledgedSegmentEvent(t,e){if(!e||!e.eventName)throw new Error("A Segment event is required.");const n=window._segmentWriteKey||typeof analytics=="object"&&analytics._writeKey;if(!n)throw new Error("Segment write key is unavailable. Please try again.");const s=this.getUserIdSync(),o=this.getSegmentStoredId("ajs_anonymous_id"),i=this.getIpAddressSync(),h=this.getCookie("_fbp")||"",m=this.getCookie("_fbc")||"",_=e.__consentCategories?this.getConsentContext(e.__consentCategories,e.__consentMetadata):this.getConsentContext(),a={page:{path:window.location.pathname,url:window.location.href,search:window.location.search,title:document.title,referrer:document.referrer},..._},{eventName:f,__consentCategories:r,__consentMetadata:l,...u}=e,c=[];if(t!=null&&s){const g={...this.customerTraits,...t,sent_from:"Pvolve Web Script",fbp:h,fbc:m,anonymousId:o,ip:i};delete g.email,c.push({type:"identify",userId:s,anonymousId:o||void 0,traits:g,context:a,timestamp:new Date().toISOString()})}c.push({type:"track",event:f,userId:s||void 0,anonymousId:o||void 0,properties:u,context:a,timestamp:new Date().toISOString()});const d=await fetch("https://api.segment.io/v1/batch",{method:"POST",headers:{Authorization:"Basic "+btoa(n+":"),"Content-Type":"application/json"},body:JSON.stringify({batch:c})});if(!d.ok)throw new Error("Segment rejected the privacy request with status "+d.status+".");return!0},async sendSegmentEvent(t,e){const n={path:window.location.pathname,url:window.location.href,search:window.location.search,title:document.title,referrer:document.referrer};if(typeof analytics=="object")try{const s=this.getCookie("_fbp")||"",o=this.getCookie("_fbc")||"",i=this.getSegmentStoredId("ajs_anonymous_id"),h=e!=null&&e.is_page_view,m=e!=null&&e.eventName==="Form Submitted"&&e.form_name==="Do Not Sell My Info",_=e!=null&&(/^Cookie Banner /.test(e.eventName||"")||m),w=e&&e.__consentCategories?this.getConsentContext(e.__consentCategories,e.__consentMetadata):null;if(_){const r=this.getUserIdSync(),l=this.getIpAddressSync(),u=w||this.getConsentContext();if(t!=null&&r){const v={...this.customerTraits,...t,sent_from:"Pvolve Web Script",fbp:s,fbc:o,anonymousId:i,ip:l};delete v.email,analytics.identify(r,v,{context:u}),this._hasIdentified=!0}const{eventName:c,__consentCategories:d,__consentMetadata:g,...p}=e,C=m?p:{...p,sent_from:"Pvolve Web Script",fbp:s,fbc:o,userId:r,anonymousId:i,ip:l,email:p.email||r};analytics.track(c,C,{context:{page:n,...u}}),console.log("[SegmentUser] Event tracked:",c);return}const a=await this.getUserId(),f=h?this.getIpAddressSync():await this.setIpAddress();if(t!=null&&a){const r={...this.customerTraits,...t,sent_from:"Pvolve Web Script",fbp:s,fbc:o,anonymousId:i,ip:f};delete r.email;const l=this.getConsentContext();analytics.identify(a,r,{context:l}),this._hasIdentified=!0}if(e&&e.eventName){const{eventName:r,__consentCategories:l,__consentMetadata:u,...c}=e,d={...c,sent_from:"Pvolve Web Script",fbp:s,fbc:o,userId:a,anonymousId:i,ip:f,email:a},g=w||this.getConsentContext(),p={context:{page:n,...g}};h?(delete d.is_page_view,analytics.page(r,d,p)):analytics.track(r,d,p),console.log("[SegmentUser] Event tracked:",r)}}catch(s){console.error("[SegmentUser] Error sending event:",s)}else this.pendingEvents.push({traits:t,eventData:e}),console.warn("[SegmentUser] Analytics not ready, event queued:",e==null?void 0:e.eventName)},sendProductClickedEvent(t){var n,s,o;if(!t)return;Array.isArray(this.productsData)||(this.productsData=[]);const e=this.productsData.find(i=>i.handle===t);if(e){const i=e.price/100;this.sendSegmentEvent(null,{eventName:"Product Clicked",sent_from:"Pvolve Web Script",brand:e.vendor,category:e.product_type,url:window.location.href+"/products/"+e.handle,product_id:e.id,sku:((n=e.variants[0])==null?void 0:n.sku)||"",name:e.title,price:i,variant:((s=e.variants[0])==null?void 0:s.title)||"",shopify_product_id:e.id,shopify_variant_id:((o=e.variants[0])==null?void 0:o.id)||"",currency:e.currency||"USD",image_url:e.featured_image,tags:e.tags,compare_at_price:e.compare_at_price})}else this.sendSegmentEvent(null,{eventName:"Product Clicked",product_handle:t,sent_from:"Pvolve Web Script"})},setProductsData(t){if(Array.isArray(t))this.productsData=t;else if(typeof t=="string")try{this.productsData=JSON.parse(t)}catch{this.productsData=[]}else this.productsData=[]},setEmail(t){t&&(this.email=t.toLowerCase(),this.traits.email=this.email,b(this.email))},identifyUser(t,e={}){t&&(this.setEmail(t),this.customerTraits={...this.customerTraits,...e}
1,this.sendSegmentEvent(e,null),console.log("[SegmentUser] User identified:",t))},getEmail(){return this.email},getTraits(){return this.traits},async processPendingEvents(){if(this.pendingEvents.length!==0){console.log(`[SegmentUser] Processing ${this.pendingEvents.length} pending events`);for(const{traits:t,eventData:e}of this.pendingEvents)await this.sendSegmentEvent(t,e);this.pendingEvents=[]}},checkAndInitialize(t=0){if(typeof analytics=="object")this.init();else if(t<this.maxRetries){const e=Math.min(this.retryDelay+t*25,200);setTimeout(()=>this.checkAndInitialize(t+1),e)}else console.error("[SegmentUser] Analytics SDK failed to load after maximum retries")}};S.checkAndInitialize();window.SegmentUser=S;typeof y<"u"&&y.exports&&(y.exports=S)});export default k(); 2//# sourceMappingURL=js-segment-user-DjOQZaAI.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.