@salla.sa/analytics 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/checkout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./chunks/extra-context-B8aoGbHo.js"),e=require("@jitsu/js"),s={get(t,e=null){const s="undefined"!=typeof window?window.initialData:null;if(!s||"object"!=typeof s)return e;let i=s;for(const s of t.split(".")){if(null==i||"object"!=typeof i||!(s in i))return e;i=i[s]}return void 0!==i?i:e}};const i="s-session-id";let n=null;function r(t){return`${t}_${s.get("store.id")}`}var o={SESSION_STORAGE_KEY:i,SESSION_TTL_MINUTES:30,resolve:()=>(n||(n=function(t,e=null){try{const s=localStorage.getItem(r(t));if(!s)return e;const i=JSON.parse(s);return i&&"object"==typeof i?(new Date).getTime()>i.expiry?(localStorage.removeItem(r(t)),e):i.value:e}catch(t){return e}}(i)||t.generateSessionId()),function(t,e,s=30){try{const i=(new Date).getTime()+60*s*1e3;localStorage.setItem(r(t),JSON.stringify({value:e,expiry:i}))}catch(t){}}(i,n),n)};class a{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;return{event:"Checkout Started",properties:{checkout_id:null==(t=window.initialData)||null==(t=t.cart)?void 0:t.id,order_id:(null==(e=this.transaction)||null==(e=e.order_id)?void 0:e.toString())||"",cart_id:(null==(s=this.transaction)||null==(s=s.cart_id)?void 0:s.toString())||"",affiliation:(null==(i=this.transaction)?void 0:i.affiliation)||"",value:(null==(n=this.transaction)?void 0:n.value)||0,revenue:(null==(r=this.transaction)?void 0:r.revenue)||0,shipping:(null==(o=this.transaction)?void 0:o.shipping)||0,tax:(null==(a=this.transaction)?void 0:a.tax)||0,discount:(null==(l=this.transaction)?void 0:l.discount)||0,coupon:(null==(d=this.transaction)?void 0:d.coupon)||"",currency:(null==(c=this.transaction)?void 0:c.currency)||"",products:((null==(u=this.transaction)?void 0:u.products)||[]).map(t=>{var e;return{product_id:(null==t||null==(e=t.product_id)?void 0:e.toString())||"",sku:(null==t?void 0:t.sku)||"",name:(null==t?void 0:t.name)||"",price:(null==t?void 0:t.price)||0,quantity:(null==t?void 0:t.quantity)||0,category:(null==t?void 0:t.category)||"",url:(null==t?void 0:t.url)||"",image_url:(null==t?void 0:t.image_url)||""}})}}}}class l{constructor(t){this.transaction=t}toSegment(){return{event:"Payment Info Entered",properties:{order_id:this.transaction.order_id,payment_method:this.transaction.payment_method,checkout_id:this.transaction.checkout_id}}}}class d{constructor(t){this.details=t||{}}toSegment(){var e;return{event:"Checkout Step Viewed",properties:t._extends({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:null!=(e=this.details.payment_method)?e:""},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}const c=/\b(?:\d[ -]?){13,19}\b/g,u=/[\w.+-]+@[\w-]+(\.[\w-]+)+/g,h=t=>t?String(t).replace(c,"[REDACTED]").replace(u,"[REDACTED]").slice(0,500):"",p=t=>t&&"object"==typeof t?Object.keys(t).map(e=>{const s=Array.isArray(t[e])?t[e][0]:t[e],i=s&&"object"==typeof s?s.message||JSON.stringify(s):s;return{field:e,message:h(i)}}):[];class _{constructor(t){this.details=t||{}}toSegment(){var e,s,i,n;const r=this.details.error||{},o=r.fields||{},a=Object.keys(o);return{event:"Checkout Step Completed",properties:t._extends({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:this.details.payment_method,success:null==(e=this.details.success)||e,error_code:null!=(s=r.code)?s:null,error_type:null!=(i=r.type)?i:null,error_message:h(r.message),http_status:null!=(n=r.status)?n:null,error_fields:a,field_errors:p(o)},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}class m{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Entered",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,value:this.transaction.value,currency:this.transaction.currency}}}}class g{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Applied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class v{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Denied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,reason:this.transaction.reason}}}}class y{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Removed",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class k{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,_,m,g,v,y,k,f,S,C,x,P,w;const b=this.transaction.error||{},T=b.fields||{},E=Object.keys(T),A=null==(t=this.transaction.address)?void 0:t.lat,j=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(A)||Boolean(j);return{event:"Address Added",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(_=this.transaction.address)||null==(_=_.region)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.region)?void 0:m.name},city:{id:null==(g=this.transaction.address)||null==(g=g.city)?void 0:g.id,name:null==(v=this.transaction.address)||null==(v=v.city)?void 0:v.name},country:{id:null==(y=this.transaction.address)||null==(y=y.country)?void 0:y.id,name:null==(k=this.transaction.address)||null==(k=k.country)?void 0:k.name},district:{id:null==(f=this.transaction.address)||null==(f=f.district)?void 0:f.id,name:null==(S=this.transaction.address)||null==(S=S.district)?void 0:S.name},lat:I&&null!=A?A:null,lng:I&&null!=j?j:null},success:null==(C=this.transaction.success)||C,error_code:null!=(x=b.code)?x:null,error_type:null!=(P=b.type)?P:null,error_message:h(b.message),http_status:null!=(w=b.status)?w:null,error_fields:E,field_errors:p(T)}}}}class f{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,_,m,g,v,y,k,f,S,C,x,P,w;const b=this.transaction.error||{},T=b.fields||{},E=Object.keys(T),A=null==(t=this.transaction.address)?void 0:t.lat,j=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(A)||Boolean(j);return{event:"Address Updated",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(_=this.transaction.address)||null==(_=_.region)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.region)?void 0:m.name},city:{id:null==(g=this.transaction.address)||null==(g=g.city)?void 0:g.id,name:null==(v=this.transaction.address)||null==(v=v.city)?void 0:v.name},country:{id:null==(y=this.transaction.address)||null==(y=y.country)?void 0:y.id,name:null==(k=this.transaction.address)||null==(k=k.country)?void 0:k.name},district:{id:null==(f=this.transaction.address)||null==(f=f.district)?void 0:f.id,name:null==(S=this.transaction.address)||null==(S=S.district)?void 0:S.name},lat:I&&null!=A?A:null,lng:I&&null!=j?j:null},success:null==(C=this.transaction.success)||C,error_code:null!=(x=b.code)?x:null,error_type:null!=(P=b.type)?P:null,error_message:h(b.message),http_status:null!=(w=b.status)?w:null,error_fields:E,field_errors:p(T)}}}}class S{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;const _=this.transaction.error||{},m=_.fields||{},g=Object.keys(m);return{event:"Map Clicked",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(t=this.transaction.customer)?void 0:t.id,name:(null==(e=this.transaction.customer)?void 0:e.first_name)+" "+(null==(s=this.transaction.customer)?void 0:s.last_name),mobile:null==(i=this.transaction.customer)?void 0:i.mobile,email:null==(n=this.transaction.customer)?void 0:n.email,gender:null==(r=this.transaction.customer)?void 0:r.gender},address:{lat:null==(o=this.transaction.address)?void 0:o.lat,lng:null==(a=this.transaction.address)?void 0:a.lng},success:null==(l=this.transaction.success)||l,error_code:null!=(d=_.code)?d:null,error_type:null!=(c=_.type)?c:null,error_message:h(_.message),http_status:null!=(u=_.status)?u:null,error_fields:g,field_errors:p(m)}}}}class C{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Submitted",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,is_order_free:this.details.is_order_free,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0),shipping_method:this.details.shipping_method,has_partial_payment:this.details.has_partial_payment||!1}}}}class x{constructor(t){this.details=t||{}}toSegment(){const e=this.details.error_fields||{},i=e&&"object"==typeof e?Object.keys(e):[];return{event:"Payment Failed",properties:t._extends({checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,error_code:this.details.error_code,error_type:this.details.error_type,error_message:h(this.details.error_message),http_status:this.details.http_status,error_fields:i,field_errors:p(e)},P(this.details.apple_pay))}}}const P=t=>t&&"object"==typeof t?{apple_pay_cancel_stage:t.cancel_stage||null,apple_pay_elapsed_ms:Number.isFinite(t.elapsed_ms)?t.elapsed_ms:null,apple_pay_validation_result:t.validation_result||null,apple_pay_status_code:t.apple_status_code?String(t.apple_status_code):null,apple_pay_status_message:h(t.apple_status_message)||null,apple_pay_submit_state:t.submit_state||null,apple_pay_authorize_count:Number.isFinite(t.authorize_count)?t.authorize_count:null}:{};class w{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Succeeded",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,response_status:this.details.response_status,has_redirect:this.details.has_redirect||!1,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0)}}}}class b{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Pending",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0)}}}}class T{constructor(t){this.details=t||{}}toSegment(){return{event:"Gift Card Redeemed",properties:t.mapGiftCardRedeemedFields({source:"checkout",customer_id:s.get("customer.id"),store_id:s.get("store.id")},this.details)}}}function E(t,e){var i,n;return{product_id:null==(i=t.id)?void 0:i.toString(),name:t.name,price:t.price,position:e,url:t.url,image_url:null==(n=t.image)?void 0:n.url,currency:t.currency||s.get("cart.currency")||null}}function A(t){var e;return{source:null==t?void 0:t.source,recommendation_source:null==t?void 0:t.recommendation_source,request_id:null!=(e=null==t?void 0:t.request_id)?e:null}}class j{constructor(t){this.details=t}toSegment(){var e;const s=Array.isArray(null==(e=this.details)?void 0:e.products)?this.details.products.filter(Boolean):[];return s.length?{event:"Product List Viewed",properties:t._extends({list_id:"checkout_xsell",category:null,sub_category:null},A(this.details),{products:s.map((e,s)=>t._extends({},E(e,s+1),{variant:"product"}))})}:null}}class I{constructor(t){this.details=t}toSegment(){var e,s;const i=null==(e=this.details)?void 0:e.product;return i?{event:"Product Clicked",properties:t._extends({},E(i,null!=(s=this.details.position)?s:null),A(this.details))}:null}}class O{constructor(t){this.details=t}toSegment(){var e,i,n;const r=null==(e=this.details)?void 0:e.product;return r?{event:"Product Added",properties:t._extends({},E(r,null!=(i=this.details.position)?i:null),{quantity:null!=(n=this.details.quantity)?n:1,cart_id:s.get("cart.id")||null},A(this.details))}:null}}var q=new class{constructor(){this.events={"Checkout Started":a,"Payment Info Entered":l,"Checkout Step Viewed":d,"Checkout Step Completed":_,"Coupon Entered":m,"Coupon Applied":g,"Coupon Denied":v,"Coupon Removed":y,"Address Added":k,"Address Updated":f,"Map Clicked":S,"Payment Submitted":C,"Payment Failed":x,"Payment Succeeded":w,"Payment Pending":b,"Gift Card Redeemed":T,"Product List Viewed":j,"Product Clicked":I,"Product Added":O}}transform(t,e){const s=this.events[t];if(!s)return null;try{const t=new s(e).toSegment();return null!=t&&t.properties&&null!=e&&e.checkout_type&&(t.properties.checkout_type=e.checkout_type),t}catch(t){return console.error("Failed to transform event:",t),null}}};exports.SessionService=o,exports.default=class{constructor(){this.history=[],this.customTrackers=[],this.context={},this.events=[],this._sessionId=null,this.mappedEvents={"payment::method_updated":"Payment Info Entered","checkout::step_viewed":"Checkout Step Viewed","checkout::step_completed":"Checkout Step Completed","coupon::applied":"Coupon Applied","coupon::denied":"Coupon Denied","coupon::entered":"Coupon Entered","coupon::removed":"Coupon Removed","address::added":"Address Added","address::updated":"Address Updated","map::clicked":"Map Clicked","payment::submitted":"Payment Submitted","payment::failed":"Payment Failed","payment::succeeded":"Payment Succeeded","payment::pending":"Payment Pending","giftcard::redeemed":"Gift Card Redeemed","checkout-xsell::list.viewed":"Product List Viewed","checkout-xsell::product.clicked":"Product Clicked","checkout-xsell::product.added":"Product Added"};const t=s.get("config.jitsu",{}),i=s.get("store.url",null),{host:n,key:r}=t||{};this.analytics=null,n&&r&&(this.analytics=e.jitsuAnalytics({host:this.getAnalyticsHost(i),writeKey:r,cookieCapture:this.captureCookies()}),this.events=s.get("config.jitsu.events",[]),s.get("config.jitsu.context.extra",{})&&this.setExtraContext(s.get("config.jitsu.context.extra",{})),this.initSessionId(),this.setSignedInCustomerTraits(),this.page())}setSignedInCustomerTraits(){const t=s.get("customer");t&&t.id&&this.setTraits(t)}setTraits(t){t&&this.setContext("traits",t)}initSessionId(){this._sessionId=o.resolve(),this.setContext("session_id",this._sessionId)}captureCookies(){const e=s.get("store.features",[])||[],i=e.includes("utm-client-ids")&&this.hasCookiesConsent(e);return t.captureSallaCookies("sa_",i)}hasCookiesConsent(t){if(!t.includes("website-cookies"))return!0;try{return"accepted"===this.readCookiesConsent()&&/(?:^|;\s*)advertising_cookies=true(?:;|$)/.test(document.cookie)}catch(t){return!1}}readCookiesConsent(){var t;return null!=(t=globalThis.Salla)&&t.storage?globalThis.Salla.storage.get("cookies-consent"):JSON.parse(localStorage.getItem("cookies-consent"))}getAnalyticsHost(e){var s;return t.resolveAnalyticsHost(e,{documentOrigin:"undefined"!=typeof window?null==(s=window.location)?void 0:s.origin:null,log:console.log})}trackSallaEvent(t){var e;if("customer::identified"===t.type)return this.setTraits(t.detail);const s=null!=(e=this.mappedEvents[t.type])?e:t.type;if(this.analytics&&this.events.includes(s))try{if(!s)return;const e=q.transform(s,t.detail);e&&this.track(e.event,e.properties)}catch(t){console.log(t)}}track(t,e={}){return this.analytics?(e=this.finalPayload(e),this.analytics.track(t,e).then(s=>(this.pushEventToCustomTrackers("track",t,e),s)).then(()=>{this.history.push({action:"track",eventName:t,payload:e})}).catch(t=>Promise.reject(t))):Promise.resolve()}page(t={}){if(!this.analytics)return Promise.resolve();const e=this.finalPayload(t);return this.analytics.page(e).then(t=>(this.pushEventToCustomTrackers("page",e),t)).then(()=>{this.history.push({action:"page",payload:e})}).catch(t=>Promise.reject(t))}finalPayload(e={}){var i;let n={session_id:o.resolve(),cart_id:s.get("cart.id")||e.cart_id||e.checkout_id||null,requires_shipping:Boolean(s.get("cart.requires_shipping",!1))};return this.setContext("version",s.get("config.jitsu.version",1)),this.setContext("store_id",s.get("config.store.id")),n.session_id&&this.setContext("session_id",n.session_id),e.event_id=e.event_id||t.generateSessionId(),t._extends({},n,e,{session_id:e.session_id||n.session_id,cart_id:e.cart_id||n.cart_id,requires_shipping:null!=(i=e.requires_shipping)?i:n.requires_shipping})}registerTracker(e){t.isValidTracker(e,this.customTrackers,console.log)&&(this.customTrackers.push(e),t.replayHistory(e,this.history))}pushEventToCustomTrackers(e,s,i={}){return t.pushEventToTrackers(this.customTrackers,e,s,i,console.log)}setContext(t,e){var s;null==(s=this.analytics)||s.setContextProperty(t,e),this.context[t]=e}setExtraContext(e){t.applyExtraContext((t,e)=>this.setContext(t,e),e,console.log)}},exports.initialData=s,exports.sanitizeErrorMessage=h,exports.sanitizeFieldErrors=p;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./chunks/extra-context-B8aoGbHo.js"),e=require("@jitsu/js"),s={get(t,e=null){const s="undefined"!=typeof window?window.initialData:null;if(!s||"object"!=typeof s)return e;let i=s;for(const s of t.split(".")){if(null==i||"object"!=typeof i||!(s in i))return e;i=i[s]}return void 0!==i?i:e}};const i="s-session-id";let n=null;function r(t){return`${t}_${s.get("store.id")}`}var o={SESSION_STORAGE_KEY:i,SESSION_TTL_MINUTES:30,resolve:()=>(n||(n=function(t,e=null){try{const s=localStorage.getItem(r(t));if(!s)return e;const i=JSON.parse(s);return i&&"object"==typeof i?(new Date).getTime()>i.expiry?(localStorage.removeItem(r(t)),e):i.value:e}catch(t){return e}}(i)||t.generateSessionId()),function(t,e,s=30){try{const i=(new Date).getTime()+60*s*1e3;localStorage.setItem(r(t),JSON.stringify({value:e,expiry:i}))}catch(t){}}(i,n),n)};class a{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;return{event:"Checkout Started",properties:{checkout_id:null==(t=window.initialData)||null==(t=t.cart)?void 0:t.id,order_id:(null==(e=this.transaction)||null==(e=e.order_id)?void 0:e.toString())||"",cart_id:(null==(s=this.transaction)||null==(s=s.cart_id)?void 0:s.toString())||"",affiliation:(null==(i=this.transaction)?void 0:i.affiliation)||"",value:(null==(n=this.transaction)?void 0:n.value)||0,revenue:(null==(r=this.transaction)?void 0:r.revenue)||0,shipping:(null==(o=this.transaction)?void 0:o.shipping)||0,tax:(null==(a=this.transaction)?void 0:a.tax)||0,discount:(null==(l=this.transaction)?void 0:l.discount)||0,coupon:(null==(d=this.transaction)?void 0:d.coupon)||"",currency:(null==(c=this.transaction)?void 0:c.currency)||"",products:((null==(u=this.transaction)?void 0:u.products)||[]).map(t=>{var e;return{product_id:(null==t||null==(e=t.product_id)?void 0:e.toString())||"",sku:(null==t?void 0:t.sku)||"",name:(null==t?void 0:t.name)||"",price:(null==t?void 0:t.price)||0,quantity:(null==t?void 0:t.quantity)||0,category:(null==t?void 0:t.category)||"",url:(null==t?void 0:t.url)||"",image_url:(null==t?void 0:t.image_url)||""}})}}}}class l{constructor(t){this.transaction=t}toSegment(){return{event:"Payment Info Entered",properties:t._extends({order_id:this.transaction.order_id,payment_method:this.transaction.payment_method,checkout_id:this.transaction.checkout_id},d(this.transaction))}}}const d=t=>"apple_pay_sheet"!==t.source?{}:{source:t.source,card_change_index:Number.isFinite(t.card_change_index)?t.card_change_index:null,card_display_name:t.card_display_name||null,card_network:t.card_network||null,card_type:t.card_type||null,card_state:t.card_state||null,card_complete_mode:t.card_complete_mode||null};class c{constructor(t){this.details=t||{}}toSegment(){var e;return{event:"Checkout Step Viewed",properties:t._extends({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:null!=(e=this.details.payment_method)?e:""},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}const u=/\b(?:\d[ -]?){13,19}\b/g,h=/[\w.+-]+@[\w-]+(\.[\w-]+)+/g,p=t=>t?String(t).replace(u,"[REDACTED]").replace(h,"[REDACTED]").slice(0,500):"",_=t=>t&&"object"==typeof t?Object.keys(t).map(e=>{const s=Array.isArray(t[e])?t[e][0]:t[e],i=s&&"object"==typeof s?s.message||JSON.stringify(s):s;return{field:e,message:p(i)}}):[];class m{constructor(t){this.details=t||{}}toSegment(){var e,s,i,n;const r=this.details.error||{},o=r.fields||{},a=Object.keys(o);return{event:"Checkout Step Completed",properties:t._extends({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:this.details.payment_method,success:null==(e=this.details.success)||e,error_code:null!=(s=r.code)?s:null,error_type:null!=(i=r.type)?i:null,error_message:p(r.message),http_status:null!=(n=r.status)?n:null,error_fields:a,field_errors:_(o)},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}class y{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Entered",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,value:this.transaction.value,currency:this.transaction.currency}}}}class g{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Applied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class v{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Denied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,reason:this.transaction.reason}}}}class k{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Removed",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class f{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,m,y,g,v,k,f,S,C,x,w,b;const P=this.transaction.error||{},T=P.fields||{},E=Object.keys(T),A=null==(t=this.transaction.address)?void 0:t.lat,j=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(A)||Boolean(j);return{event:"Address Added",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(m=this.transaction.address)||null==(m=m.region)?void 0:m.name},city:{id:null==(y=this.transaction.address)||null==(y=y.city)?void 0:y.id,name:null==(g=this.transaction.address)||null==(g=g.city)?void 0:g.name},country:{id:null==(v=this.transaction.address)||null==(v=v.country)?void 0:v.id,name:null==(k=this.transaction.address)||null==(k=k.country)?void 0:k.name},district:{id:null==(f=this.transaction.address)||null==(f=f.district)?void 0:f.id,name:null==(S=this.transaction.address)||null==(S=S.district)?void 0:S.name},lat:I&&null!=A?A:null,lng:I&&null!=j?j:null},success:null==(C=this.transaction.success)||C,error_code:null!=(x=P.code)?x:null,error_type:null!=(w=P.type)?w:null,error_message:p(P.message),http_status:null!=(b=P.status)?b:null,error_fields:E,field_errors:_(T)}}}}class S{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,m,y,g,v,k,f,S,C,x,w,b;const P=this.transaction.error||{},T=P.fields||{},E=Object.keys(T),A=null==(t=this.transaction.address)?void 0:t.lat,j=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(A)||Boolean(j);return{event:"Address Updated",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(m=this.transaction.address)||null==(m=m.region)?void 0:m.name},city:{id:null==(y=this.transaction.address)||null==(y=y.city)?void 0:y.id,name:null==(g=this.transaction.address)||null==(g=g.city)?void 0:g.name},country:{id:null==(v=this.transaction.address)||null==(v=v.country)?void 0:v.id,name:null==(k=this.transaction.address)||null==(k=k.country)?void 0:k.name},district:{id:null==(f=this.transaction.address)||null==(f=f.district)?void 0:f.id,name:null==(S=this.transaction.address)||null==(S=S.district)?void 0:S.name},lat:I&&null!=A?A:null,lng:I&&null!=j?j:null},success:null==(C=this.transaction.success)||C,error_code:null!=(x=P.code)?x:null,error_type:null!=(w=P.type)?w:null,error_message:p(P.message),http_status:null!=(b=P.status)?b:null,error_fields:E,field_errors:_(T)}}}}class C{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;const h=this.transaction.error||{},m=h.fields||{},y=Object.keys(m);return{event:"Map Clicked",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(t=this.transaction.customer)?void 0:t.id,name:(null==(e=this.transaction.customer)?void 0:e.first_name)+" "+(null==(s=this.transaction.customer)?void 0:s.last_name),mobile:null==(i=this.transaction.customer)?void 0:i.mobile,email:null==(n=this.transaction.customer)?void 0:n.email,gender:null==(r=this.transaction.customer)?void 0:r.gender},address:{lat:null==(o=this.transaction.address)?void 0:o.lat,lng:null==(a=this.transaction.address)?void 0:a.lng},success:null==(l=this.transaction.success)||l,error_code:null!=(d=h.code)?d:null,error_type:null!=(c=h.type)?c:null,error_message:p(h.message),http_status:null!=(u=h.status)?u:null,error_fields:y,field_errors:_(m)}}}}class x{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Submitted",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,is_order_free:this.details.is_order_free,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0),shipping_method:this.details.shipping_method,has_partial_payment:this.details.has_partial_payment||!1}}}}class w{constructor(t){this.details=t||{}}toSegment(){const e=this.details.error_fields||{},i=e&&"object"==typeof e?Object.keys(e):[];return{event:"Payment Failed",properties:t._extends({checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,error_code:this.details.error_code,error_type:this.details.error_type,error_message:p(this.details.error_message),http_status:this.details.http_status,error_fields:i,field_errors:_(e)},b(this.details.apple_pay))}}}const b=t=>t&&"object"==typeof t?{apple_pay_cancel_stage:t.cancel_stage||null,apple_pay_elapsed_ms:Number.isFinite(t.elapsed_ms)?t.elapsed_ms:null,apple_pay_validation_result:t.validation_result||null,apple_pay_status_code:t.apple_status_code?String(t.apple_status_code):null,apple_pay_status_message:p(t.apple_status_message)||null,apple_pay_submit_state:t.submit_state||null,apple_pay_authorize_count:Number.isFinite(t.authorize_count)?t.authorize_count:null,apple_pay_supported_networks:t.supported_networks||null,apple_pay_recurring:"boolean"==typeof t.recurring?t.recurring:null,apple_pay_card_selections:Number.isFinite(t.card_selections)?t.card_selections:null,apple_pay_card_complete_mode:t.card_complete_mode||null,apple_pay_card_display_name:t.card_display_name||null,apple_pay_card_network:t.card_network||null,apple_pay_card_type:t.card_type||null,apple_pay_card_state:t.card_state||null}:{};class P{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Succeeded",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,response_status:this.details.response_status,has_redirect:this.details.has_redirect||!1,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0)}}}}class T{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Pending",properties:{checkout_id:this.details.checkout_id||s.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||s.get("cart.total_in_customer_currency",0)}}}}class E{constructor(t){this.details=t||{}}toSegment(){return{event:"Gift Card Redeemed",properties:t.mapGiftCardRedeemedFields({source:"checkout",customer_id:s.get("customer.id"),store_id:s.get("store.id")},this.details)}}}function A(t,e){var i,n;return{product_id:null==(i=t.id)?void 0:i.toString(),name:t.name,price:t.price,position:e,url:t.url,image_url:null==(n=t.image)?void 0:n.url,currency:t.currency||s.get("cart.currency")||null}}function j(t){var e;return{source:null==t?void 0:t.source,recommendation_source:null==t?void 0:t.recommendation_source,request_id:null!=(e=null==t?void 0:t.request_id)?e:null}}class I{constructor(t){this.details=t}toSegment(){var e;const s=Array.isArray(null==(e=this.details)?void 0:e.products)?this.details.products.filter(Boolean):[];return s.length?{event:"Product List Viewed",properties:t._extends({list_id:"checkout_xsell",category:null,sub_category:null},j(this.details),{products:s.map((e,s)=>t._extends({},A(e,s+1),{variant:"product"}))})}:null}}class O{constructor(t){this.details=t}toSegment(){var e,s;const i=null==(e=this.details)?void 0:e.product;return i?{event:"Product Clicked",properties:t._extends({},A(i,null!=(s=this.details.position)?s:null),j(this.details))}:null}}class q{constructor(t){this.details=t}toSegment(){var e,i,n;const r=null==(e=this.details)?void 0:e.product;return r?{event:"Product Added",properties:t._extends({},A(r,null!=(i=this.details.position)?i:null),{quantity:null!=(n=this.details.quantity)?n:1,cart_id:s.get("cart.id")||null},j(this.details))}:null}}var D=new class{constructor(){this.events={"Checkout Started":a,"Payment Info Entered":l,"Checkout Step Viewed":c,"Checkout Step Completed":m,"Coupon Entered":y,"Coupon Applied":g,"Coupon Denied":v,"Coupon Removed":k,"Address Added":f,"Address Updated":S,"Map Clicked":C,"Payment Submitted":x,"Payment Failed":w,"Payment Succeeded":P,"Payment Pending":T,"Gift Card Redeemed":E,"Product List Viewed":I,"Product Clicked":O,"Product Added":q}}transform(t,e){const s=this.events[t];if(!s)return null;try{const t=new s(e).toSegment();return null!=t&&t.properties&&null!=e&&e.checkout_type&&(t.properties.checkout_type=e.checkout_type),t}catch(t){return console.error("Failed to transform event:",t),null}}};exports.SessionService=o,exports.default=class{constructor(){this.history=[],this.customTrackers=[],this.context={},this.events=[],this._sessionId=null,this.mappedEvents={"payment::method_updated":"Payment Info Entered","checkout::step_viewed":"Checkout Step Viewed","checkout::step_completed":"Checkout Step Completed","coupon::applied":"Coupon Applied","coupon::denied":"Coupon Denied","coupon::entered":"Coupon Entered","coupon::removed":"Coupon Removed","address::added":"Address Added","address::updated":"Address Updated","map::clicked":"Map Clicked","payment::submitted":"Payment Submitted","payment::failed":"Payment Failed","payment::succeeded":"Payment Succeeded","payment::pending":"Payment Pending","giftcard::redeemed":"Gift Card Redeemed","checkout-xsell::list.viewed":"Product List Viewed","checkout-xsell::product.clicked":"Product Clicked","checkout-xsell::product.added":"Product Added"};const t=s.get("config.jitsu",{}),i=s.get("store.url",null),{host:n,key:r}=t||{};this.analytics=null,n&&r&&(this.analytics=e.jitsuAnalytics({host:this.getAnalyticsHost(i),writeKey:r,cookieCapture:this.captureCookies()}),this.events=s.get("config.jitsu.events",[]),s.get("config.jitsu.context.extra",{})&&this.setExtraContext(s.get("config.jitsu.context.extra",{})),this.initSessionId(),this.setSignedInCustomerTraits(),this.page())}setSignedInCustomerTraits(){const t=s.get("customer");t&&t.id&&this.setTraits(t)}setTraits(t){t&&this.setContext("traits",t)}initSessionId(){this._sessionId=o.resolve(),this.setContext("session_id",this._sessionId)}captureCookies(){const e=s.get("store.features",[])||[],i=e.includes("utm-client-ids")&&this.hasCookiesConsent(e);return t.captureSallaCookies("sa_",i)}hasCookiesConsent(t){if(!t.includes("website-cookies"))return!0;try{return"accepted"===this.readCookiesConsent()&&/(?:^|;\s*)advertising_cookies=true(?:;|$)/.test(document.cookie)}catch(t){return!1}}readCookiesConsent(){var t;return null!=(t=globalThis.Salla)&&t.storage?globalThis.Salla.storage.get("cookies-consent"):JSON.parse(localStorage.getItem("cookies-consent"))}getAnalyticsHost(e){var s;return t.resolveAnalyticsHost(e,{documentOrigin:"undefined"!=typeof window?null==(s=window.location)?void 0:s.origin:null,log:console.log})}trackSallaEvent(t){var e;if("customer::identified"===t.type)return this.setTraits(t.detail);const s=null!=(e=this.mappedEvents[t.type])?e:t.type;if(this.analytics&&this.events.includes(s))try{if(!s)return;const e=D.transform(s,t.detail);e&&this.track(e.event,e.properties)}catch(t){console.log(t)}}track(t,e={}){return this.analytics?(e=this.finalPayload(e),this.analytics.track(t,e).then(s=>(this.pushEventToCustomTrackers("track",t,e),s)).then(()=>{this.history.push({action:"track",eventName:t,payload:e})}).catch(t=>Promise.reject(t))):Promise.resolve()}page(t={}){if(!this.analytics)return Promise.resolve();const e=this.finalPayload(t);return this.analytics.page(e).then(t=>(this.pushEventToCustomTrackers("page",e),t)).then(()=>{this.history.push({action:"page",payload:e})}).catch(t=>Promise.reject(t))}finalPayload(e={}){var i;let n={session_id:o.resolve(),cart_id:s.get("cart.id")||e.cart_id||e.checkout_id||null,requires_shipping:Boolean(s.get("cart.requires_shipping",!1))};return this.setContext("version",s.get("config.jitsu.version",1)),this.setContext("store_id",s.get("config.store.id")),n.session_id&&this.setContext("session_id",n.session_id),e.event_id=e.event_id||t.generateSessionId(),t._extends({},n,e,{session_id:e.session_id||n.session_id,cart_id:e.cart_id||n.cart_id,requires_shipping:null!=(i=e.requires_shipping)?i:n.requires_shipping})}registerTracker(e){t.isValidTracker(e,this.customTrackers,console.log)&&(this.customTrackers.push(e),t.replayHistory(e,this.history))}pushEventToCustomTrackers(e,s,i={}){return t.pushEventToTrackers(this.customTrackers,e,s,i,console.log)}setContext(t,e){var s;null==(s=this.analytics)||s.setContextProperty(t,e),this.context[t]=e}setExtraContext(e){t.applyExtraContext((t,e)=>this.setContext(t,e),e,console.log)}},exports.initialData=s,exports.sanitizeErrorMessage=p,exports.sanitizeFieldErrors=_;
|
|
2
2
|
//# sourceMappingURL=checkout.js.map
|
package/dist/esm/checkout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as t,_ as e,m as s,c as i,b as n,i as r,r as o,p as a,a as l}from"./chunks/extra-context-D4VyOqyT.js";import{jitsuAnalytics as d}from"@jitsu/js";var c={get(t,e=null){const s="undefined"!=typeof window?window.initialData:null;if(!s||"object"!=typeof s)return e;let i=s;for(const s of t.split(".")){if(null==i||"object"!=typeof i||!(s in i))return e;i=i[s]}return void 0!==i?i:e}};const u="s-session-id";let h=null;function p(t){return`${t}_${c.get("store.id")}`}var _={SESSION_STORAGE_KEY:u,SESSION_TTL_MINUTES:30,resolve:()=>(h||(h=function(t,e=null){try{const s=localStorage.getItem(p(t));if(!s)return e;const i=JSON.parse(s);return i&&"object"==typeof i?(new Date).getTime()>i.expiry?(localStorage.removeItem(p(t)),e):i.value:e}catch(t){return e}}(u)||t()),function(t,e,s=30){try{const i=(new Date).getTime()+60*s*1e3;localStorage.setItem(p(t),JSON.stringify({value:e,expiry:i}))}catch(t){}}(u,h),h)};class m{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;return{event:"Checkout Started",properties:{checkout_id:null==(t=window.initialData)||null==(t=t.cart)?void 0:t.id,order_id:(null==(e=this.transaction)||null==(e=e.order_id)?void 0:e.toString())||"",cart_id:(null==(s=this.transaction)||null==(s=s.cart_id)?void 0:s.toString())||"",affiliation:(null==(i=this.transaction)?void 0:i.affiliation)||"",value:(null==(n=this.transaction)?void 0:n.value)||0,revenue:(null==(r=this.transaction)?void 0:r.revenue)||0,shipping:(null==(o=this.transaction)?void 0:o.shipping)||0,tax:(null==(a=this.transaction)?void 0:a.tax)||0,discount:(null==(l=this.transaction)?void 0:l.discount)||0,coupon:(null==(d=this.transaction)?void 0:d.coupon)||"",currency:(null==(c=this.transaction)?void 0:c.currency)||"",products:((null==(u=this.transaction)?void 0:u.products)||[]).map(t=>{var e;return{product_id:(null==t||null==(e=t.product_id)?void 0:e.toString())||"",sku:(null==t?void 0:t.sku)||"",name:(null==t?void 0:t.name)||"",price:(null==t?void 0:t.price)||0,quantity:(null==t?void 0:t.quantity)||0,category:(null==t?void 0:t.category)||"",url:(null==t?void 0:t.url)||"",image_url:(null==t?void 0:t.image_url)||""}})}}}}class g{constructor(t){this.transaction=t}toSegment(){return{event:"Payment Info Entered",properties:{order_id:this.transaction.order_id,payment_method:this.transaction.payment_method,checkout_id:this.transaction.checkout_id}}}}class v{constructor(t){this.details=t||{}}toSegment(){var t;return{event:"Checkout Step Viewed",properties:e({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:null!=(t=this.details.payment_method)?t:""},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}const y=/\b(?:\d[ -]?){13,19}\b/g,k=/[\w.+-]+@[\w-]+(\.[\w-]+)+/g,f=t=>t?String(t).replace(y,"[REDACTED]").replace(k,"[REDACTED]").slice(0,500):"",S=t=>t&&"object"==typeof t?Object.keys(t).map(e=>{const s=Array.isArray(t[e])?t[e][0]:t[e],i=s&&"object"==typeof s?s.message||JSON.stringify(s):s;return{field:e,message:f(i)}}):[];class C{constructor(t){this.details=t||{}}toSegment(){var t,s,i,n;const r=this.details.error||{},o=r.fields||{},a=Object.keys(o);return{event:"Checkout Step Completed",properties:e({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:this.details.payment_method,success:null==(t=this.details.success)||t,error_code:null!=(s=r.code)?s:null,error_type:null!=(i=r.type)?i:null,error_message:f(r.message),http_status:null!=(n=r.status)?n:null,error_fields:a,field_errors:S(o)},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}class w{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Entered",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,value:this.transaction.value,currency:this.transaction.currency}}}}class P{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Applied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class b{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Denied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,reason:this.transaction.reason}}}}class x{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Removed",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class T{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,p,_,m,g,v,y,k,C,w,P,b;const x=this.transaction.error||{},T=x.fields||{},A=Object.keys(T),j=null==(t=this.transaction.address)?void 0:t.lat,E=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(j)||Boolean(E);return{event:"Address Added",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(p=this.transaction.address)||null==(p=p.region)?void 0:p.name},city:{id:null==(_=this.transaction.address)||null==(_=_.city)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.city)?void 0:m.name},country:{id:null==(g=this.transaction.address)||null==(g=g.country)?void 0:g.id,name:null==(v=this.transaction.address)||null==(v=v.country)?void 0:v.name},district:{id:null==(y=this.transaction.address)||null==(y=y.district)?void 0:y.id,name:null==(k=this.transaction.address)||null==(k=k.district)?void 0:k.name},lat:I&&null!=j?j:null,lng:I&&null!=E?E:null},success:null==(C=this.transaction.success)||C,error_code:null!=(w=x.code)?w:null,error_type:null!=(P=x.type)?P:null,error_message:f(x.message),http_status:null!=(b=x.status)?b:null,error_fields:A,field_errors:S(T)}}}}class A{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,p,_,m,g,v,y,k,C,w,P,b;const x=this.transaction.error||{},T=x.fields||{},A=Object.keys(T),j=null==(t=this.transaction.address)?void 0:t.lat,E=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(j)||Boolean(E);return{event:"Address Updated",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(p=this.transaction.address)||null==(p=p.region)?void 0:p.name},city:{id:null==(_=this.transaction.address)||null==(_=_.city)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.city)?void 0:m.name},country:{id:null==(g=this.transaction.address)||null==(g=g.country)?void 0:g.id,name:null==(v=this.transaction.address)||null==(v=v.country)?void 0:v.name},district:{id:null==(y=this.transaction.address)||null==(y=y.district)?void 0:y.id,name:null==(k=this.transaction.address)||null==(k=k.district)?void 0:k.name},lat:I&&null!=j?j:null,lng:I&&null!=E?E:null},success:null==(C=this.transaction.success)||C,error_code:null!=(w=x.code)?w:null,error_type:null!=(P=x.type)?P:null,error_message:f(x.message),http_status:null!=(b=x.status)?b:null,error_fields:A,field_errors:S(T)}}}}class j{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;const h=this.transaction.error||{},p=h.fields||{},_=Object.keys(p);return{event:"Map Clicked",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(t=this.transaction.customer)?void 0:t.id,name:(null==(e=this.transaction.customer)?void 0:e.first_name)+" "+(null==(s=this.transaction.customer)?void 0:s.last_name),mobile:null==(i=this.transaction.customer)?void 0:i.mobile,email:null==(n=this.transaction.customer)?void 0:n.email,gender:null==(r=this.transaction.customer)?void 0:r.gender},address:{lat:null==(o=this.transaction.address)?void 0:o.lat,lng:null==(a=this.transaction.address)?void 0:a.lng},success:null==(l=this.transaction.success)||l,error_code:null!=(d=h.code)?d:null,error_type:null!=(c=h.type)?c:null,error_message:f(h.message),http_status:null!=(u=h.status)?u:null,error_fields:_,field_errors:S(p)}}}}class E{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Submitted",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,is_order_free:this.details.is_order_free,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0),shipping_method:this.details.shipping_method,has_partial_payment:this.details.has_partial_payment||!1}}}}class I{constructor(t){this.details=t||{}}toSegment(){const t=this.details.error_fields||{},s=t&&"object"==typeof t?Object.keys(t):[];return{event:"Payment Failed",properties:e({checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,error_code:this.details.error_code,error_type:this.details.error_type,error_message:f(this.details.error_message),http_status:this.details.http_status,error_fields:s,field_errors:S(t)},O(this.details.apple_pay))}}}const O=t=>t&&"object"==typeof t?{apple_pay_cancel_stage:t.cancel_stage||null,apple_pay_elapsed_ms:Number.isFinite(t.elapsed_ms)?t.elapsed_ms:null,apple_pay_validation_result:t.validation_result||null,apple_pay_status_code:t.apple_status_code?String(t.apple_status_code):null,apple_pay_status_message:f(t.apple_status_message)||null,apple_pay_submit_state:t.submit_state||null,apple_pay_authorize_count:Number.isFinite(t.authorize_count)?t.authorize_count:null}:{};class q{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Succeeded",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,response_status:this.details.response_status,has_redirect:this.details.has_redirect||!1,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0)}}}}class D{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Pending",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0)}}}}class N{constructor(t){this.details=t||{}}toSegment(){return{event:"Gift Card Redeemed",properties:s({source:"checkout",customer_id:c.get("customer.id"),store_id:c.get("store.id")},this.details)}}}function R(t,e){var s,i;return{product_id:null==(s=t.id)?void 0:s.toString(),name:t.name,price:t.price,position:e,url:t.url,image_url:null==(i=t.image)?void 0:i.url,currency:t.currency||c.get("cart.currency")||null}}function B(t){var e;return{source:null==t?void 0:t.source,recommendation_source:null==t?void 0:t.recommendation_source,request_id:null!=(e=null==t?void 0:t.request_id)?e:null}}class F{constructor(t){this.details=t}toSegment(){var t;const s=Array.isArray(null==(t=this.details)?void 0:t.products)?this.details.products.filter(Boolean):[];return s.length?{event:"Product List Viewed",properties:e({list_id:"checkout_xsell",category:null,sub_category:null},B(this.details),{products:s.map((t,s)=>e({},R(t,s+1),{variant:"product"}))})}:null}}class V{constructor(t){this.details=t}toSegment(){var t,s;const i=null==(t=this.details)?void 0:t.product;return i?{event:"Product Clicked",properties:e({},R(i,null!=(s=this.details.position)?s:null),B(this.details))}:null}}class G{constructor(t){this.details=t}toSegment(){var t,s,i;const n=null==(t=this.details)?void 0:t.product;return n?{event:"Product Added",properties:e({},R(n,null!=(s=this.details.position)?s:null),{quantity:null!=(i=this.details.quantity)?i:1,cart_id:c.get("cart.id")||null},B(this.details))}:null}}var J=new class{constructor(){this.events={"Checkout Started":m,"Payment Info Entered":g,"Checkout Step Viewed":v,"Checkout Step Completed":C,"Coupon Entered":w,"Coupon Applied":P,"Coupon Denied":b,"Coupon Removed":x,"Address Added":T,"Address Updated":A,"Map Clicked":j,"Payment Submitted":E,"Payment Failed":I,"Payment Succeeded":q,"Payment Pending":D,"Gift Card Redeemed":N,"Product List Viewed":F,"Product Clicked":V,"Product Added":G}}transform(t,e){const s=this.events[t];if(!s)return null;try{const t=new s(e).toSegment();return null!=t&&t.properties&&null!=e&&e.checkout_type&&(t.properties.checkout_type=e.checkout_type),t}catch(t){return console.error("Failed to transform event:",t),null}}};class L{constructor(){this.history=[],this.customTrackers=[],this.context={},this.events=[],this._sessionId=null,this.mappedEvents={"payment::method_updated":"Payment Info Entered","checkout::step_viewed":"Checkout Step Viewed","checkout::step_completed":"Checkout Step Completed","coupon::applied":"Coupon Applied","coupon::denied":"Coupon Denied","coupon::entered":"Coupon Entered","coupon::removed":"Coupon Removed","address::added":"Address Added","address::updated":"Address Updated","map::clicked":"Map Clicked","payment::submitted":"Payment Submitted","payment::failed":"Payment Failed","payment::succeeded":"Payment Succeeded","payment::pending":"Payment Pending","giftcard::redeemed":"Gift Card Redeemed","checkout-xsell::list.viewed":"Product List Viewed","checkout-xsell::product.clicked":"Product Clicked","checkout-xsell::product.added":"Product Added"};const t=c.get("config.jitsu",{}),e=c.get("store.url",null),{host:s,key:i}=t||{};this.analytics=null,s&&i&&(this.analytics=d({host:this.getAnalyticsHost(e),writeKey:i,cookieCapture:this.captureCookies()}),this.events=c.get("config.jitsu.events",[]),c.get("config.jitsu.context.extra",{})&&this.setExtraContext(c.get("config.jitsu.context.extra",{})),this.initSessionId(),this.setSignedInCustomerTraits(),this.page())}setSignedInCustomerTraits(){const t=c.get("customer");t&&t.id&&this.setTraits(t)}setTraits(t){t&&this.setContext("traits",t)}initSessionId(){this._sessionId=_.resolve(),this.setContext("session_id",this._sessionId)}captureCookies(){const t=c.get("store.features",[])||[],e=t.includes("utm-client-ids")&&this.hasCookiesConsent(t);return i("sa_",e)}hasCookiesConsent(t){if(!t.includes("website-cookies"))return!0;try{return"accepted"===this.readCookiesConsent()&&/(?:^|;\s*)advertising_cookies=true(?:;|$)/.test(document.cookie)}catch(t){return!1}}readCookiesConsent(){var t;return null!=(t=globalThis.Salla)&&t.storage?globalThis.Salla.storage.get("cookies-consent"):JSON.parse(localStorage.getItem("cookies-consent"))}getAnalyticsHost(t){var e;return n(t,{documentOrigin:"undefined"!=typeof window?null==(e=window.location)?void 0:e.origin:null,log:console.log})}trackSallaEvent(t){var e;if("customer::identified"===t.type)return this.setTraits(t.detail);const s=null!=(e=this.mappedEvents[t.type])?e:t.type;if(this.analytics&&this.events.includes(s))try{if(!s)return;const e=J.transform(s,t.detail);e&&this.track(e.event,e.properties)}catch(t){console.log(t)}}track(t,e={}){return this.analytics?(e=this.finalPayload(e),this.analytics.track(t,e).then(s=>(this.pushEventToCustomTrackers("track",t,e),s)).then(()=>{this.history.push({action:"track",eventName:t,payload:e})}).catch(t=>Promise.reject(t))):Promise.resolve()}page(t={}){if(!this.analytics)return Promise.resolve();const e=this.finalPayload(t);return this.analytics.page(e).then(t=>(this.pushEventToCustomTrackers("page",e),t)).then(()=>{this.history.push({action:"page",payload:e})}).catch(t=>Promise.reject(t))}finalPayload(s={}){var i;let n={session_id:_.resolve(),cart_id:c.get("cart.id")||s.cart_id||s.checkout_id||null,requires_shipping:Boolean(c.get("cart.requires_shipping",!1))};return this.setContext("version",c.get("config.jitsu.version",1)),this.setContext("store_id",c.get("config.store.id")),n.session_id&&this.setContext("session_id",n.session_id),s.event_id=s.event_id||t(),e({},n,s,{session_id:s.session_id||n.session_id,cart_id:s.cart_id||n.cart_id,requires_shipping:null!=(i=s.requires_shipping)?i:n.requires_shipping})}registerTracker(t){r(t,this.customTrackers,console.log)&&(this.customTrackers.push(t),o(t,this.history))}pushEventToCustomTrackers(t,e,s={}){return a(this.customTrackers,t,e,s,console.log)}setContext(t,e){var s;null==(s=this.analytics)||s.setContextProperty(t,e),this.context[t]=e}setExtraContext(t){l((t,e)=>this.setContext(t,e),t,console.log)}}export{_ as SessionService,L as default,c as initialData,f as sanitizeErrorMessage,S as sanitizeFieldErrors};
|
|
1
|
+
import{g as t,_ as e,m as s,c as i,b as n,i as r,r as o,p as a,a as l}from"./chunks/extra-context-D4VyOqyT.js";import{jitsuAnalytics as d}from"@jitsu/js";var c={get(t,e=null){const s="undefined"!=typeof window?window.initialData:null;if(!s||"object"!=typeof s)return e;let i=s;for(const s of t.split(".")){if(null==i||"object"!=typeof i||!(s in i))return e;i=i[s]}return void 0!==i?i:e}};const u="s-session-id";let h=null;function p(t){return`${t}_${c.get("store.id")}`}var _={SESSION_STORAGE_KEY:u,SESSION_TTL_MINUTES:30,resolve:()=>(h||(h=function(t,e=null){try{const s=localStorage.getItem(p(t));if(!s)return e;const i=JSON.parse(s);return i&&"object"==typeof i?(new Date).getTime()>i.expiry?(localStorage.removeItem(p(t)),e):i.value:e}catch(t){return e}}(u)||t()),function(t,e,s=30){try{const i=(new Date).getTime()+60*s*1e3;localStorage.setItem(p(t),JSON.stringify({value:e,expiry:i}))}catch(t){}}(u,h),h)};class m{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;return{event:"Checkout Started",properties:{checkout_id:null==(t=window.initialData)||null==(t=t.cart)?void 0:t.id,order_id:(null==(e=this.transaction)||null==(e=e.order_id)?void 0:e.toString())||"",cart_id:(null==(s=this.transaction)||null==(s=s.cart_id)?void 0:s.toString())||"",affiliation:(null==(i=this.transaction)?void 0:i.affiliation)||"",value:(null==(n=this.transaction)?void 0:n.value)||0,revenue:(null==(r=this.transaction)?void 0:r.revenue)||0,shipping:(null==(o=this.transaction)?void 0:o.shipping)||0,tax:(null==(a=this.transaction)?void 0:a.tax)||0,discount:(null==(l=this.transaction)?void 0:l.discount)||0,coupon:(null==(d=this.transaction)?void 0:d.coupon)||"",currency:(null==(c=this.transaction)?void 0:c.currency)||"",products:((null==(u=this.transaction)?void 0:u.products)||[]).map(t=>{var e;return{product_id:(null==t||null==(e=t.product_id)?void 0:e.toString())||"",sku:(null==t?void 0:t.sku)||"",name:(null==t?void 0:t.name)||"",price:(null==t?void 0:t.price)||0,quantity:(null==t?void 0:t.quantity)||0,category:(null==t?void 0:t.category)||"",url:(null==t?void 0:t.url)||"",image_url:(null==t?void 0:t.image_url)||""}})}}}}class y{constructor(t){this.transaction=t}toSegment(){return{event:"Payment Info Entered",properties:e({order_id:this.transaction.order_id,payment_method:this.transaction.payment_method,checkout_id:this.transaction.checkout_id},g(this.transaction))}}}const g=t=>"apple_pay_sheet"!==t.source?{}:{source:t.source,card_change_index:Number.isFinite(t.card_change_index)?t.card_change_index:null,card_display_name:t.card_display_name||null,card_network:t.card_network||null,card_type:t.card_type||null,card_state:t.card_state||null,card_complete_mode:t.card_complete_mode||null};class v{constructor(t){this.details=t||{}}toSegment(){var t;return{event:"Checkout Step Viewed",properties:e({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:null!=(t=this.details.payment_method)?t:""},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}const k=/\b(?:\d[ -]?){13,19}\b/g,f=/[\w.+-]+@[\w-]+(\.[\w-]+)+/g,S=t=>t?String(t).replace(k,"[REDACTED]").replace(f,"[REDACTED]").slice(0,500):"",C=t=>t&&"object"==typeof t?Object.keys(t).map(e=>{const s=Array.isArray(t[e])?t[e][0]:t[e],i=s&&"object"==typeof s?s.message||JSON.stringify(s):s;return{field:e,message:S(i)}}):[];class w{constructor(t){this.details=t||{}}toSegment(){var t,s,i,n;const r=this.details.error||{},o=r.fields||{},a=Object.keys(o);return{event:"Checkout Step Completed",properties:e({checkout_id:this.details.checkout_id,step:this.details.step,shipping_method:this.details.shipping_method,payment_method:this.details.payment_method,success:null==(t=this.details.success)||t,error_code:null!=(s=r.code)?s:null,error_type:null!=(i=r.type)?i:null,error_message:S(r.message),http_status:null!=(n=r.status)?n:null,error_fields:a,field_errors:C(o)},this.details.payment_methods?{payment_methods:this.details.payment_methods}:{})}}}class b{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Entered",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,value:this.transaction.value,currency:this.transaction.currency}}}}class P{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Applied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class x{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Denied",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,reason:this.transaction.reason}}}}class T{constructor(t){this.transaction=t}toSegment(){return{event:"Coupon Removed",properties:{cart_id:this.transaction.cart_id,order_id:this.transaction.order_id,coupon_id:this.transaction.coupon_id,coupon_name:this.transaction.coupon_name,discount:this.transaction.discount,currency:this.transaction.currency}}}}class A{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,p,_,m,y,g,v,k,f,w,b,P;const x=this.transaction.error||{},T=x.fields||{},A=Object.keys(T),j=null==(t=this.transaction.address)?void 0:t.lat,E=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(j)||Boolean(E);return{event:"Address Added",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(p=this.transaction.address)||null==(p=p.region)?void 0:p.name},city:{id:null==(_=this.transaction.address)||null==(_=_.city)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.city)?void 0:m.name},country:{id:null==(y=this.transaction.address)||null==(y=y.country)?void 0:y.id,name:null==(g=this.transaction.address)||null==(g=g.country)?void 0:g.name},district:{id:null==(v=this.transaction.address)||null==(v=v.district)?void 0:v.id,name:null==(k=this.transaction.address)||null==(k=k.district)?void 0:k.name},lat:I&&null!=j?j:null,lng:I&&null!=E?E:null},success:null==(f=this.transaction.success)||f,error_code:null!=(w=x.code)?w:null,error_type:null!=(b=x.type)?b:null,error_message:S(x.message),http_status:null!=(P=x.status)?P:null,error_fields:A,field_errors:C(T)}}}}class j{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u,h,p,_,m,y,g,v,k,f,w,b,P;const x=this.transaction.error||{},T=x.fields||{},A=Object.keys(T),j=null==(t=this.transaction.address)?void 0:t.lat,E=null==(e=this.transaction.address)?void 0:e.lng,I=Boolean(j)||Boolean(E);return{event:"Address Updated",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(s=this.transaction.customer)?void 0:s.id,name:(null==(i=this.transaction.customer)?void 0:i.first_name)+" "+(null==(n=this.transaction.customer)?void 0:n.last_name),mobile:null==(r=this.transaction.customer)?void 0:r.mobile,email:null==(o=this.transaction.customer)?void 0:o.email,gender:null==(a=this.transaction.customer)?void 0:a.gender},address:{local:null==(l=this.transaction.address)?void 0:l.local,street:null==(d=this.transaction.address)?void 0:d.street,postal_code:null==(c=this.transaction.address)?void 0:c.postal_code,short_address:null==(u=this.transaction.address)?void 0:u.short_address,region:{id:null==(h=this.transaction.address)||null==(h=h.region)?void 0:h.id,name:null==(p=this.transaction.address)||null==(p=p.region)?void 0:p.name},city:{id:null==(_=this.transaction.address)||null==(_=_.city)?void 0:_.id,name:null==(m=this.transaction.address)||null==(m=m.city)?void 0:m.name},country:{id:null==(y=this.transaction.address)||null==(y=y.country)?void 0:y.id,name:null==(g=this.transaction.address)||null==(g=g.country)?void 0:g.name},district:{id:null==(v=this.transaction.address)||null==(v=v.district)?void 0:v.id,name:null==(k=this.transaction.address)||null==(k=k.district)?void 0:k.name},lat:I&&null!=j?j:null,lng:I&&null!=E?E:null},success:null==(f=this.transaction.success)||f,error_code:null!=(w=x.code)?w:null,error_type:null!=(b=x.type)?b:null,error_message:S(x.message),http_status:null!=(P=x.status)?P:null,error_fields:A,field_errors:C(T)}}}}class E{constructor(t){this.transaction=t}toSegment(){var t,e,s,i,n,r,o,a,l,d,c,u;const h=this.transaction.error||{},p=h.fields||{},_=Object.keys(p);return{event:"Map Clicked",properties:{checkout_id:this.transaction.cart_id,order_id:this.transaction.order_id,cart_id:this.transaction.cart_id,customer:{id:null==(t=this.transaction.customer)?void 0:t.id,name:(null==(e=this.transaction.customer)?void 0:e.first_name)+" "+(null==(s=this.transaction.customer)?void 0:s.last_name),mobile:null==(i=this.transaction.customer)?void 0:i.mobile,email:null==(n=this.transaction.customer)?void 0:n.email,gender:null==(r=this.transaction.customer)?void 0:r.gender},address:{lat:null==(o=this.transaction.address)?void 0:o.lat,lng:null==(a=this.transaction.address)?void 0:a.lng},success:null==(l=this.transaction.success)||l,error_code:null!=(d=h.code)?d:null,error_type:null!=(c=h.type)?c:null,error_message:S(h.message),http_status:null!=(u=h.status)?u:null,error_fields:_,field_errors:C(p)}}}}class I{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Submitted",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,is_order_free:this.details.is_order_free,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0),shipping_method:this.details.shipping_method,has_partial_payment:this.details.has_partial_payment||!1}}}}class O{constructor(t){this.details=t||{}}toSegment(){const t=this.details.error_fields||{},s=t&&"object"==typeof t?Object.keys(t):[];return{event:"Payment Failed",properties:e({checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,error_code:this.details.error_code,error_type:this.details.error_type,error_message:S(this.details.error_message),http_status:this.details.http_status,error_fields:s,field_errors:C(t)},N(this.details.apple_pay))}}}const N=t=>t&&"object"==typeof t?{apple_pay_cancel_stage:t.cancel_stage||null,apple_pay_elapsed_ms:Number.isFinite(t.elapsed_ms)?t.elapsed_ms:null,apple_pay_validation_result:t.validation_result||null,apple_pay_status_code:t.apple_status_code?String(t.apple_status_code):null,apple_pay_status_message:S(t.apple_status_message)||null,apple_pay_submit_state:t.submit_state||null,apple_pay_authorize_count:Number.isFinite(t.authorize_count)?t.authorize_count:null,apple_pay_supported_networks:t.supported_networks||null,apple_pay_recurring:"boolean"==typeof t.recurring?t.recurring:null,apple_pay_card_selections:Number.isFinite(t.card_selections)?t.card_selections:null,apple_pay_card_complete_mode:t.card_complete_mode||null,apple_pay_card_display_name:t.card_display_name||null,apple_pay_card_network:t.card_network||null,apple_pay_card_type:t.card_type||null,apple_pay_card_state:t.card_state||null}:{};class q{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Succeeded",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,response_status:this.details.response_status,has_redirect:this.details.has_redirect||!1,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0)}}}}class D{constructor(t){this.details=t||{}}toSegment(){return{event:"Payment Pending",properties:{checkout_id:this.details.checkout_id||c.get("cart.id"),payment_method:this.details.payment_method,gateway:this.details.gateway,redirect_url:this.details.redirect_url||null,order_id:this.details.order_id||null,cart_total:this.details.cart_total||c.get("cart.total_in_customer_currency",0)}}}}class R{constructor(t){this.details=t||{}}toSegment(){return{event:"Gift Card Redeemed",properties:s({source:"checkout",customer_id:c.get("customer.id"),store_id:c.get("store.id")},this.details)}}}function F(t,e){var s,i;return{product_id:null==(s=t.id)?void 0:s.toString(),name:t.name,price:t.price,position:e,url:t.url,image_url:null==(i=t.image)?void 0:i.url,currency:t.currency||c.get("cart.currency")||null}}function B(t){var e;return{source:null==t?void 0:t.source,recommendation_source:null==t?void 0:t.recommendation_source,request_id:null!=(e=null==t?void 0:t.request_id)?e:null}}class V{constructor(t){this.details=t}toSegment(){var t;const s=Array.isArray(null==(t=this.details)?void 0:t.products)?this.details.products.filter(Boolean):[];return s.length?{event:"Product List Viewed",properties:e({list_id:"checkout_xsell",category:null,sub_category:null},B(this.details),{products:s.map((t,s)=>e({},F(t,s+1),{variant:"product"}))})}:null}}class G{constructor(t){this.details=t}toSegment(){var t,s;const i=null==(t=this.details)?void 0:t.product;return i?{event:"Product Clicked",properties:e({},F(i,null!=(s=this.details.position)?s:null),B(this.details))}:null}}class J{constructor(t){this.details=t}toSegment(){var t,s,i;const n=null==(t=this.details)?void 0:t.product;return n?{event:"Product Added",properties:e({},F(n,null!=(s=this.details.position)?s:null),{quantity:null!=(i=this.details.quantity)?i:1,cart_id:c.get("cart.id")||null},B(this.details))}:null}}var L=new class{constructor(){this.events={"Checkout Started":m,"Payment Info Entered":y,"Checkout Step Viewed":v,"Checkout Step Completed":w,"Coupon Entered":b,"Coupon Applied":P,"Coupon Denied":x,"Coupon Removed":T,"Address Added":A,"Address Updated":j,"Map Clicked":E,"Payment Submitted":I,"Payment Failed":O,"Payment Succeeded":q,"Payment Pending":D,"Gift Card Redeemed":R,"Product List Viewed":V,"Product Clicked":G,"Product Added":J}}transform(t,e){const s=this.events[t];if(!s)return null;try{const t=new s(e).toSegment();return null!=t&&t.properties&&null!=e&&e.checkout_type&&(t.properties.checkout_type=e.checkout_type),t}catch(t){return console.error("Failed to transform event:",t),null}}};class M{constructor(){this.history=[],this.customTrackers=[],this.context={},this.events=[],this._sessionId=null,this.mappedEvents={"payment::method_updated":"Payment Info Entered","checkout::step_viewed":"Checkout Step Viewed","checkout::step_completed":"Checkout Step Completed","coupon::applied":"Coupon Applied","coupon::denied":"Coupon Denied","coupon::entered":"Coupon Entered","coupon::removed":"Coupon Removed","address::added":"Address Added","address::updated":"Address Updated","map::clicked":"Map Clicked","payment::submitted":"Payment Submitted","payment::failed":"Payment Failed","payment::succeeded":"Payment Succeeded","payment::pending":"Payment Pending","giftcard::redeemed":"Gift Card Redeemed","checkout-xsell::list.viewed":"Product List Viewed","checkout-xsell::product.clicked":"Product Clicked","checkout-xsell::product.added":"Product Added"};const t=c.get("config.jitsu",{}),e=c.get("store.url",null),{host:s,key:i}=t||{};this.analytics=null,s&&i&&(this.analytics=d({host:this.getAnalyticsHost(e),writeKey:i,cookieCapture:this.captureCookies()}),this.events=c.get("config.jitsu.events",[]),c.get("config.jitsu.context.extra",{})&&this.setExtraContext(c.get("config.jitsu.context.extra",{})),this.initSessionId(),this.setSignedInCustomerTraits(),this.page())}setSignedInCustomerTraits(){const t=c.get("customer");t&&t.id&&this.setTraits(t)}setTraits(t){t&&this.setContext("traits",t)}initSessionId(){this._sessionId=_.resolve(),this.setContext("session_id",this._sessionId)}captureCookies(){const t=c.get("store.features",[])||[],e=t.includes("utm-client-ids")&&this.hasCookiesConsent(t);return i("sa_",e)}hasCookiesConsent(t){if(!t.includes("website-cookies"))return!0;try{return"accepted"===this.readCookiesConsent()&&/(?:^|;\s*)advertising_cookies=true(?:;|$)/.test(document.cookie)}catch(t){return!1}}readCookiesConsent(){var t;return null!=(t=globalThis.Salla)&&t.storage?globalThis.Salla.storage.get("cookies-consent"):JSON.parse(localStorage.getItem("cookies-consent"))}getAnalyticsHost(t){var e;return n(t,{documentOrigin:"undefined"!=typeof window?null==(e=window.location)?void 0:e.origin:null,log:console.log})}trackSallaEvent(t){var e;if("customer::identified"===t.type)return this.setTraits(t.detail);const s=null!=(e=this.mappedEvents[t.type])?e:t.type;if(this.analytics&&this.events.includes(s))try{if(!s)return;const e=L.transform(s,t.detail);e&&this.track(e.event,e.properties)}catch(t){console.log(t)}}track(t,e={}){return this.analytics?(e=this.finalPayload(e),this.analytics.track(t,e).then(s=>(this.pushEventToCustomTrackers("track",t,e),s)).then(()=>{this.history.push({action:"track",eventName:t,payload:e})}).catch(t=>Promise.reject(t))):Promise.resolve()}page(t={}){if(!this.analytics)return Promise.resolve();const e=this.finalPayload(t);return this.analytics.page(e).then(t=>(this.pushEventToCustomTrackers("page",e),t)).then(()=>{this.history.push({action:"page",payload:e})}).catch(t=>Promise.reject(t))}finalPayload(s={}){var i;let n={session_id:_.resolve(),cart_id:c.get("cart.id")||s.cart_id||s.checkout_id||null,requires_shipping:Boolean(c.get("cart.requires_shipping",!1))};return this.setContext("version",c.get("config.jitsu.version",1)),this.setContext("store_id",c.get("config.store.id")),n.session_id&&this.setContext("session_id",n.session_id),s.event_id=s.event_id||t(),e({},n,s,{session_id:s.session_id||n.session_id,cart_id:s.cart_id||n.cart_id,requires_shipping:null!=(i=s.requires_shipping)?i:n.requires_shipping})}registerTracker(t){r(t,this.customTrackers,console.log)&&(this.customTrackers.push(t),o(t,this.history))}pushEventToCustomTrackers(t,e,s={}){return a(this.customTrackers,t,e,s,console.log)}setContext(t,e){var s;null==(s=this.analytics)||s.setContextProperty(t,e),this.context[t]=e}setExtraContext(t){l((t,e)=>this.setContext(t,e),t,console.log)}}export{_ as SessionService,M as default,c as initialData,S as sanitizeErrorMessage,C as sanitizeFieldErrors};
|
|
2
2
|
//# sourceMappingURL=checkout.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salla.sa/analytics",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Salla unified analytics: Jitsu engine, event transformers and trackers for storefront (twilight) and checkout",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"rollup-plugin-exclude-dependencies-from-bundle": "^1.1.24",
|
|
64
64
|
"rollup-plugin-version-injector": "^1.3.3"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "6e792486c809c2f84a7c3c46e0a63360e5ed4328"
|
|
67
67
|
}
|
|
@@ -42,5 +42,13 @@ const applePayProperties = (applePay) => {
|
|
|
42
42
|
apple_pay_status_message: sanitizeErrorMessage(applePay.apple_status_message) || null,
|
|
43
43
|
apple_pay_submit_state: applePay.submit_state || null,
|
|
44
44
|
apple_pay_authorize_count: Number.isFinite(applePay.authorize_count) ? applePay.authorize_count : null,
|
|
45
|
+
apple_pay_supported_networks: applePay.supported_networks || null,
|
|
46
|
+
apple_pay_recurring: typeof applePay.recurring === 'boolean' ? applePay.recurring : null,
|
|
47
|
+
apple_pay_card_selections: Number.isFinite(applePay.card_selections) ? applePay.card_selections : null,
|
|
48
|
+
apple_pay_card_complete_mode: applePay.card_complete_mode || null,
|
|
49
|
+
apple_pay_card_display_name: applePay.card_display_name || null,
|
|
50
|
+
apple_pay_card_network: applePay.card_network || null,
|
|
51
|
+
apple_pay_card_type: applePay.card_type || null,
|
|
52
|
+
apple_pay_card_state: applePay.card_state || null,
|
|
45
53
|
};
|
|
46
54
|
};
|
|
@@ -11,7 +11,25 @@ export default class PaymentInfoEntered {
|
|
|
11
11
|
order_id: this.transaction.order_id,
|
|
12
12
|
payment_method: this.transaction.payment_method,
|
|
13
13
|
checkout_id: this.transaction.checkout_id,
|
|
14
|
+
...applePaySheetProperties(this.transaction),
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
// Only set when the card was picked inside the Apple Pay sheet, not on the checkout page.
|
|
21
|
+
const applePaySheetProperties = (details) => {
|
|
22
|
+
if (details.source !== 'apple_pay_sheet') {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
source: details.source,
|
|
28
|
+
card_change_index: Number.isFinite(details.card_change_index) ? details.card_change_index : null,
|
|
29
|
+
card_display_name: details.card_display_name || null,
|
|
30
|
+
card_network: details.card_network || null,
|
|
31
|
+
card_type: details.card_type || null,
|
|
32
|
+
card_state: details.card_state || null,
|
|
33
|
+
card_complete_mode: details.card_complete_mode || null,
|
|
34
|
+
};
|
|
35
|
+
};
|