@epigraph/epigraph-std-lib 4.7.0-alpha → 5.0.0-alpha

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var h=(s=>(s.UNAVAILABLE="unavailable",s.AVAILABLE="available",s.RESTRICTED="restricted",s))(h||{});const E=Symbol("data"),l=Symbol("next"),C=class N{constructor(t){this[E]=t,this[l]=null}get data(){return this[E]}set next(t){if(!(t instanceof N)&&t!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[l]=t}get next(){return this[l]}};let v=C;const d=Symbol("head");class O{constructor(){this[d]=null}set head(t){this[d]=t}get head(){return this[d]}addToTail(t){let e=this.head;if(e){for(;e.next!==null;)e=e?.next;return e.next=new v(t)}return this.head=new v(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const m=Symbol("queue"),p=Symbol("size");class f{constructor(){this[m]=new O,this[p]=0}get queue(){return this[m]}get size(){return this[p]}enqueue(t){this.queue.addToTail(t),this[p]++}dequeue(){const t=this.queue.removeHead();return this[p]--,t}}class u{static{this.NOTIFICATION_NAME="epg-notification"}static{this.ACTION_SEND_EVENT="send-event"}static{this.ACTION_INITIALIZED="initialized"}static{this.ACTION_FAILED_INITIALIZATION="initialization-failed"}constructor(t,e,i,n,r,o){this._pluginName=t,this._trackingId=e,this._experienceId=i,this._solution=n,this._initializer=r,this._status=o}updateStatus(t){this._status=t}updateInitializer(t){this._initializer=t}notify(t,e){console.log("Notifying",t,e);const i={pluginName:this._pluginName,trackingId:this._trackingId,experienceId:this._experienceId,solution:this._solution,initializer:this._initializer,status:this._status,action:t,eventDetails:e};window.dispatchEvent(new CustomEvent("epg-notification",{detail:i}))}}class S{constructor({trackingID:t,experienceID:e,solution:i,verboseLogging:n=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.__initializationAttempts=0,this.__lastInitializationAttempt=performance.now(),this.__maxInitializationAttempts=10,this.__initializationRetryDelay=2e3,this.__isInitialized=!1,this.__initializationMethod="NONE",this.__nexusFailureReported=!1,this.name=this.pluginName="GA4-PLUGIN",this.trackingID=t,this.experienceID=e,this.solution=i,this.verboseLogging=n,this.__queue=new f,this.__epigraphNotifier=new u(this.pluginName,this.pluginName,this.experienceID,this.solution,this.__initializationMethod,this.__status),this.initializePlugin()}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return`${this.name}-${this.trackingID}`}setupPlugin(){this.__isInitialized&&this.dataLayer!==void 0&&this.dequeueAndSendEvents()}async sendEvent(t,e){if(this.__queue.enqueue(t),!e){this.__status=h.RESTRICTED;return}if(!this.__isInitialized){this.logger("Cannot send analytics event: dataLayer not defined or plugin not initialized.");return}try{await this.dequeueAndSendEvents()}catch(i){this.logger(i),await this.reportFailureToNexus("EVENT_SEND_ERROR",i?.toString()||"Unknown error")}}initializePlugin(){if(this.__isInitialized)return;if(this.__initializationAttempts>=this.__maxInitializationAttempts){this.__nexusFailureReported||(this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS","Maximum initialization attempts reached"),this.__nexusFailureReported=!0,this.__epigraphNotifier.notify(u.ACTION_FAILED_INITIALIZATION,{}));return}const t=performance.now();if(this.__initializationAttempts>0&&t-this.__lastInitializationAttempt<this.__initializationRetryDelay)return;this.__lastInitializationAttempt=t,this.__initializationAttempts++;const e=this.detectAndSetupAnalytics();e.success?(this.__isInitialized=!0,this.__status=h.AVAILABLE,this.__initializationMethod=e.method,this.dataLayerName=e.dataLayerName,this.dataLayer=window[this.dataLayerName],this.logger(`Successfully initialized ${e.method} with dataLayer: ${this.dataLayerName}`),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{}),this.__queue.size>0&&this.dequeueAndSendEvents()):(this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${e.error}`),this.__initializationAttempts<this.__maxInitializationAttempts&&setTimeout(()=>{this.initializePlugin()},this.__initializationRetryDelay))}detectAndSetupAnalytics(){const t=this.detectGTM();if(t)return this.logger(`GTM detected with container ID: ${t.containerId}`),this.__epigraphNotifier.updateInitializer("GTM"),{success:!0,method:"GTM",dataLayerName:t.dataLayerName};const e=this.findGA4Info(this.trackingID);if(e){const i=e.l||"dataLayer";return this.logger(`GA4 script found, setting up with dataLayer: ${i}`),this.__epigraphNotifier.updateInitializer("GA4"),{success:!0,method:"GA4",dataLayerName:i}}return{success:!1,method:"NONE",dataLayerName:"dataLayer",error:"No analytics setup found and unable to create one"}}detectGTM(){const t=document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');for(const e of Array.from(t)){const i=e.getAttribute("src");if(i){const n=i.match(/gtm\.js\?id=([^&]+)/);if(n&&n.length>0){const r=i.match(/&l=([^&]+)/),o=r?r[1]:"dataLayer";return{containerId:n[1],dataLayerName:o}}}}return null}async dequeueAndSendEvents(){if(!this.__isInitialized||!this.dataLayer)return;let t=this.__queue.size;for(let e=0;e<t;e++){const i=this.__queue.dequeue();try{this.__initializationMethod==="GTM"?(this.sendGTMEvent(i),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${i.eventName}`)):this.__initializationMethod==="GA4"?(this.sendGA4Event(i),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${i.eventName}`)):this.__queue.enqueue(i)}catch(n){this.logger(`Error sending event ${i.eventName}: ${n}`),this.__queue.enqueue(i)}}}async sendGTMEvent(t){let e=t.getGTMParameters(this.solution,this.experienceID,this.trackingID);const i=e;this.isValidPayload(e)||(e=await this.convertGTMParametersToEpgEventTag(t.eventName,e)),this.dataLayer&&(this.dataLayer.push(e),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i))}async sendGA4Event(t){let e=t.getGa4Parameters(this.solution,this.experienceID,this.trackingID);const i=e;this.isValidPayload(e)||(e=await this.convertGA4ParametersToEpgEventTag(e)),window.gtag("event",t.eventName,e),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i)}isValidPayload(t){if(Object.keys(t).length>=25)return!1;for(const[n,r]of Object.entries(t))if(n!=="items"&&(n.length>40||String(r).length>100))return!1;return!0}async convertGTMParametersToEpgEventTag(t,e){try{let i=await this.sendGA4LongParameters(e);return{event:t,epg_event_tag:i,send_to:this.trackingID}}catch{return e}}async convertGA4ParametersToEpgEventTag(t){try{return{epg_event_tag:await this.sendGA4LongParameters(t),send_to:this.trackingID}}catch{return t}}logger(t){this.verboseLogging&&console.warn(t)}async sendGA4LongParameters(t){const e="https://api.myepigraph.com/api/analytics/ga4/custom",i={parameters:t};try{const n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(i)});return n.ok?(await n.json())?.id??"":""}catch{return""}}async reportFailureToNexus(t,e){try{const i={plugin:"GA4",trackingId:this.trackingID,solution:this.solution,experienceId:this.experienceID,failureType:t,errorMessage:e,timestamp:new Date().toISOString(),url:window.location.href,userAgent:navigator.userAgent};this.logger(`Failure reported to Nexus: ${JSON.stringify(i)}`)}catch(i){this.logger(`Error reporting failure to Nexus: ${i}`)}}findGA4Info(t){if(window.google_tag_manager&&window.google_tag_manager[t]){const i=window.google_tag_manager[t];if(i&&i.dataLayerName)return{fullSrc:"",id:t,l:i.dataLayerName}}const e=document.querySelectorAll("script[src]");for(const i of e){const n=i.getAttribute("src");if(n&&n.includes(t)){const r=new URL(n,location.href),o=Object.fromEntries(r.searchParams.entries());return{fullSrc:r.href,id:o.id||void 0,l:o.l||void 0}}}return null}}class R{constructor({trackingID:t,experienceID:e,solution:i,sessionId:n,xPath:r,verboseLogging:o=!1,sendToStaging:P=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=n,this.xPath=r,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=t,this.experienceID=e,this.solution=i,this.verboseLogging=o,this.__queue=new f,this.url=P?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=h.AVAILABLE,this.__epigraphNotifier=new u(this.pluginName,this.trackingID,this.experienceID,this.solution,"NEXUS",this.__status),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{})}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}async sendEvent(t,e){if(this.__queue.enqueue(t),!e){this.__status=h.RESTRICTED,this.__epigraphNotifier.updateStatus(this.__status);return}await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let t=0;t<this.__queue.size;t++){const e=this.__queue.dequeue(),i={send_to:this.trackingID,experience_id:this.experienceID,solution:this.solution,event:e.eventName,parameters:e.getNexusParameters()};try{return(await fetch(this.url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","EPG-SESSION-ID":this.sessionId,"EPG-XPATH":this.xPath,Origin:typeof window<"u"?window.location.origin:""},body:JSON.stringify(i)})).ok&&this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i),""}catch{return""}this.__sentEventCount++}return""}}class I{constructor(t){this.consentSet=!1,this.consent=!1,this.pluginName="OneTrustConsentPlugin",this.consentIdentifier=t,this.consent=!1,this.addConsentChangedListener()}hasConsent(){if(this.consentSet)return this.consent;if(window.OnetrustActiveGroups!==void 0){let t=window.OnetrustActiveGroups;t!==void 0&&t.split(",").forEach(i=>{i===this.consentIdentifier&&(this.consent=!0,this.consentSet=!0)})}return this.consent}addConsentChangedListener(){window.addEventListener("load",()=>{this.hasConsent(),window.OneTrust!==void 0&&typeof window.OneTrust=="object"&&window.OneTrust.OnConsentChanged(()=>{this.consentSet=!1,this.hasConsent()})})}}var g=(s=>(s.OneTrust="onetrust",s))(g||{});class a{constructor({eventName:t,interactiveEvent:e,customParameters:i}){this.eventName=t,this.interactiveEvent=e,this.customParameters=i}getGa4Parameters(t,e,i){let n={solution:t,experience_id:e,interactive_event:this.interactiveEvent,send_to:i};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getGTMParameters(t,e,i){let n={solution:t,experience_id:e,event:this.eventName,interactive_event:this.interactiveEvent,send_to:i};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getNexusParameters(){let t={interactive_event:this.interactiveEvent};return t=Object.assign(t,JSON.parse(JSON.stringify(this.customParameters))),t}}const A={AR:"ar",QR:"qr",INFO:"info",DOWNLOAD:"download",PREVIEW_CART:"preview_cart",HOTSPOT_PANEL:"hotspot_panel",SHARE_MODAL:"share_modal",RESTART_MODAL:"restart_modal",REMOVE_MODAL:"remove_modal",LOAD_PRECONFIG_MODAL:"load_preconfig_modal",MOVE_MODAL:"move_modal",OUT_OF_STOCK_MODAL:"out_of_stock_modal"},T={AUTO:"auto",BUTTON:"button",HOTSPOT:"hotspot",GESTURE:"gesture"},_={USD:"USD",EUR:"EUR",GBP:"GBP",CAD:"CAD"};class L extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class w extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class x extends a{constructor(t,e){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e}})}}class D extends a{constructor(t,e,i){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e,error_type:i}})}}class z extends a{constructor(t){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:t}})}}class M extends a{static{this.SUPPORT_TYPE={AR:"ar",QR:"qr",WEBGL2:"webgl2"}}constructor(t,e={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t,device_capabilities:e}})}}class G extends a{static{this.BUTTON_TYPE={AR_VIEW:"ar_view",DIMENSION_SHOW:"dimension_show",DIMENSION_HIDE:"dimension_hide",HOTSPOTS_SHOW:"hotspots_show",HOTSPOTS_HIDE:"hotspots_hide",HELP_SHOW:"help_show",HELP_HIDE:"help_hide",HOTSPOT_ENTER:"hotspot_enter",HOTSPOT_EXIT:"hotspot_exit",SHARE:"share",PDF_DOWNLOAD:"pdf_download",COPY:"copy",RESTART:"restart",INSTRUCTIONS_SHOW:"show_instructions",REVIEW_CART:"review_cart",SHOP_NOW:"shop_now",SUB_CATEGORY:"sub_category",NEXT_STEP:"next_step",PREVIOUS_STEP:"previous_step"}}constructor(t,e){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:e}})}}class q extends a{static{this.PANEL_TYPE=A}static{this.TRIGGER_SOURCE=T}constructor(t,e,i,n){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:n,panel_type:e,trigger_source:i}})}}class b extends a{static{this.PANEL_TYPE=A}static{this.TRIGGER_SOURCE=T}constructor(t,e,i,n){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:n,panel_type:e,trigger_source:i}})}}class U extends a{constructor(t){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:t}})}}class k extends a{static{this.ACTION_PERFORMED={ZOOM:"zoom",ROTATE:"rotate"}}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class V extends a{static{this.INTERACTION_TYPE={ROTATE:"rotate",ZOOM:"zoom",PAN:"pan"}}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class $ extends a{static{this.CURRENCY=_}constructor(t,e,i,n,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:r,value:e,currency:i,quantity:n}})}}class F extends a{constructor(t){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:t}})}}class H extends a{static{this.CURRENCY=_}constructor(t,e,i,n){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:n,value:t,currency:e,quantity:i}})}}class B extends a{constructor(t,e){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class j extends a{constructor(t,e,i){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:i,content_type:t,share_destination:e}})}}class Y extends a{static{this.CURRENCY=_}constructor(t,e,i){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:i,value:t,currency:e}})}}class W extends a{static{this.CURRENCY=_}constructor(t,e,i){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:i,value:t,currency:e}})}}class J extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class Z extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class X extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class K extends a{constructor(t,e,i){super({eventName:t,interactiveEvent:e,customParameters:i})}}/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var h=(e=>(e.UNAVAILABLE="unavailable",e.AVAILABLE="available",e.RESTRICTED="restricted",e))(h||{});const C=Symbol("data"),g=Symbol("next"),R=class P{constructor(t){this[C]=t,this[g]=null}get data(){return this[C]}set next(t){if(!(t instanceof P)&&t!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[g]=t}get next(){return this[g]}};let O=R;const v=Symbol("head");class D{constructor(){this[v]=null}set head(t){this[v]=t}get head(){return this[v]}addToTail(t){let i=this.head;if(i){for(;i.next!==null;)i=i?.next;return i.next=new O(t)}return this.head=new O(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const S=Symbol("queue"),l=Symbol("size");class T{constructor(){this[S]=new D,this[l]=0}get queue(){return this[S]}get size(){return this[l]}enqueue(t){this.queue.addToTail(t),this[l]++}dequeue(){const t=this.queue.removeHead();return this[l]--,t}}class u{static{this.NOTIFICATION_NAME="epg-notification"}static{this.ACTION_SEND_EVENT="send-event"}static{this.ACTION_INITIALIZED="initialized"}static{this.ACTION_FAILED_INITIALIZATION="initialization-failed"}constructor(t,i,n,s,r,o){this._pluginName=t,this._trackingId=i,this._experienceId=n,this._solution=s,this._initializer=r,this._status=o}updateStatus(t){this._status=t}updateInitializer(t){this._initializer=t}notify(t,i){console.log("Notifying",t,i);const n={pluginName:this._pluginName,trackingId:this._trackingId,experienceId:this._experienceId,solution:this._solution,initializer:this._initializer,status:this._status,action:t,eventDetails:i};window.dispatchEvent(new CustomEvent("epg-notification",{detail:n}))}}class z{constructor({trackingID:t,experienceID:i,solution:n,verboseLogging:s=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.__initializationAttempts=0,this.__lastInitializationAttempt=performance.now(),this.__maxInitializationAttempts=10,this.__initializationRetryDelay=2e3,this.__isInitialized=!1,this.__initializationMethod="NONE",this.__nexusFailureReported=!1,this.name=this.pluginName="GA4-PLUGIN",this.trackingID=t,this.experienceID=i,this.solution=n,this.verboseLogging=s,this.__queue=new T,this.__epigraphNotifier=new u(this.pluginName,this.pluginName,this.experienceID,this.solution,this.__initializationMethod,this.__status),this.initializePlugin()}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return`${this.name}-${this.trackingID}`}setupPlugin(){this.__isInitialized&&this.dataLayer!==void 0&&this.dequeueAndSendEvents()}async sendEvent(t,i){if(this.__queue.enqueue(t),!i){this.__status=h.RESTRICTED;return}if(!this.__isInitialized){this.logger("Cannot send analytics event: dataLayer not defined or plugin not initialized.");return}try{await this.dequeueAndSendEvents()}catch(n){this.logger(n),await this.reportFailureToNexus("EVENT_SEND_ERROR",n?.toString()||"Unknown error")}}initializePlugin(){if(this.__isInitialized)return;if(this.__initializationAttempts>=this.__maxInitializationAttempts){this.__nexusFailureReported||(this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS","Maximum initialization attempts reached"),this.__nexusFailureReported=!0,this.__epigraphNotifier.notify(u.ACTION_FAILED_INITIALIZATION,{}));return}const t=performance.now();if(this.__initializationAttempts>0&&t-this.__lastInitializationAttempt<this.__initializationRetryDelay)return;this.__lastInitializationAttempt=t,this.__initializationAttempts++;const i=this.detectAndSetupAnalytics();i.success?(this.__isInitialized=!0,this.__status=h.AVAILABLE,this.__initializationMethod=i.method,this.dataLayerName=i.dataLayerName,this.dataLayer=window[this.dataLayerName],this.logger(`Successfully initialized ${i.method} with dataLayer: ${this.dataLayerName}`),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{}),this.__queue.size>0&&this.dequeueAndSendEvents()):(this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${i.error}`),this.__initializationAttempts<this.__maxInitializationAttempts&&setTimeout(()=>{this.initializePlugin()},this.__initializationRetryDelay))}detectAndSetupAnalytics(){const t=this.detectGTM();if(t)return this.logger(`GTM detected with container ID: ${t.containerId}`),this.__epigraphNotifier.updateInitializer("GTM"),{success:!0,method:"GTM",dataLayerName:t.dataLayerName};const i=this.findGA4Info(this.trackingID);if(i){const n=i.l||"dataLayer";return this.logger(`GA4 script found, setting up with dataLayer: ${n}`),this.__epigraphNotifier.updateInitializer("GA4"),{success:!0,method:"GA4",dataLayerName:n}}return{success:!1,method:"NONE",dataLayerName:"dataLayer",error:"No analytics setup found and unable to create one"}}detectGTM(){const t=document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');for(const i of Array.from(t)){const n=i.getAttribute("src");if(n){const s=n.match(/gtm\.js\?id=([^&]+)/);if(s&&s.length>0){const r=n.match(/&l=([^&]+)/),o=r?r[1]:"dataLayer";return{containerId:s[1],dataLayerName:o}}}}return null}async dequeueAndSendEvents(){if(!this.__isInitialized||!this.dataLayer)return;let t=this.__queue.size;for(let i=0;i<t;i++){const n=this.__queue.dequeue();try{this.__initializationMethod==="GTM"?(this.sendGTMEvent(n),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${n.eventName}`)):this.__initializationMethod==="GA4"?(this.sendGA4Event(n),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${n.eventName}`)):this.__queue.enqueue(n)}catch(s){this.logger(`Error sending event ${n.eventName}: ${s}`),this.__queue.enqueue(n)}}}async sendGTMEvent(t){let i=t.getGTMParameters(this.solution,this.experienceID,this.trackingID);const n=i;this.isValidPayload(i)||(i=await this.convertGTMParametersToEpgEventTag(t.eventName,i)),this.dataLayer&&(this.dataLayer.push(i),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,n))}async sendGA4Event(t){let i=t.getGa4Parameters(this.solution,this.experienceID,this.trackingID);const n=i;this.isValidPayload(i)||(i=await this.convertGA4ParametersToEpgEventTag(i)),window.gtag("event",t.eventName,i),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,n)}isValidPayload(t){if(Object.keys(t).length>=25)return!1;for(const[s,r]of Object.entries(t))if(s!=="items"&&(s.length>40||String(r).length>100))return!1;return!0}async convertGTMParametersToEpgEventTag(t,i){try{let n=await this.sendGA4LongParameters(i);return{event:t,epg_event_tag:n,send_to:this.trackingID}}catch{return i}}async convertGA4ParametersToEpgEventTag(t){try{return{epg_event_tag:await this.sendGA4LongParameters(t),send_to:this.trackingID}}catch{return t}}logger(t){this.verboseLogging&&console.warn(t)}async sendGA4LongParameters(t){const i="https://api.myepigraph.com/api/analytics/ga4/custom",n={parameters:t};try{const s=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return s.ok?(await s.json())?.id??"":""}catch{return""}}async reportFailureToNexus(t,i){try{const n={plugin:"GA4",trackingId:this.trackingID,solution:this.solution,experienceId:this.experienceID,failureType:t,errorMessage:i,timestamp:new Date().toISOString(),url:window.location.href,userAgent:navigator.userAgent};this.logger(`Failure reported to Nexus: ${JSON.stringify(n)}`)}catch(n){this.logger(`Error reporting failure to Nexus: ${n}`)}}findGA4Info(t){if(window.google_tag_manager&&window.google_tag_manager[t]){const n=window.google_tag_manager[t];if(n&&n.dataLayerName)return{fullSrc:"",id:t,l:n.dataLayerName}}const i=document.querySelectorAll("script[src]");for(const n of i){const s=n.getAttribute("src");if(s&&s.includes(t)){const r=new URL(s,location.href),o=Object.fromEntries(r.searchParams.entries());return{fullSrc:r.href,id:o.id||void 0,l:o.l||void 0}}}return null}}class G{constructor({trackingID:t,experienceID:i,solution:n,sessionId:s,xPath:r,verboseLogging:o=!1,sendToStaging:x=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=s,this.xPath=r,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=t,this.experienceID=i,this.solution=n,this.verboseLogging=o,this.__queue=new T,this.url=x?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=h.AVAILABLE,this.__epigraphNotifier=new u(this.pluginName,this.trackingID,this.experienceID,this.solution,"NEXUS",this.__status),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{})}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}async sendEvent(t,i){if(this.__queue.enqueue(t),!i){this.__status=h.RESTRICTED,this.__epigraphNotifier.updateStatus(this.__status);return}await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let t=0;t<this.__queue.size;t++){const i=this.__queue.dequeue(),n={send_to:this.trackingID,experience_id:this.experienceID,solution:this.solution,event:i.eventName,parameters:i.getNexusParameters()};try{return(await fetch(this.url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","EPG-SESSION-ID":this.sessionId,"EPG-XPATH":this.xPath,Origin:typeof window<"u"?window.location.origin:""},body:JSON.stringify(n)})).ok&&this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,n),""}catch{return""}this.__sentEventCount++}return""}}class w{constructor(t){this.consentSet=!1,this.consent=!1,this.pluginName="OneTrustConsentPlugin",this.consentIdentifier=t,this.consent=!1,this.addConsentChangedListener()}hasConsent(){if(this.consentSet)return this.consent;if(window.OnetrustActiveGroups!==void 0){let t=window.OnetrustActiveGroups;t!==void 0&&t.split(",").forEach(n=>{n===this.consentIdentifier&&(this.consent=!0,this.consentSet=!0)})}return this.consent}addConsentChangedListener(){window.addEventListener("load",()=>{this.hasConsent(),window.OneTrust!==void 0&&typeof window.OneTrust=="object"&&window.OneTrust.OnConsentChanged(()=>{this.consentSet=!1,this.hasConsent()})})}}var E=(e=>(e.OneTrust="onetrust",e))(E||{});class a{constructor({eventName:t,interactiveEvent:i,customParameters:n}){this.eventName=t,this.interactiveEvent=i,this.customParameters=n}getGa4Parameters(t,i,n){let s={solution:t,experience_id:i,interactive_event:this.interactiveEvent,send_to:n};return s=Object.assign(s,JSON.parse(JSON.stringify(this.customParameters))),s}getGTMParameters(t,i,n){let s={solution:t,experience_id:i,event:this.eventName,interactive_event:this.interactiveEvent,send_to:n};return s=Object.assign(s,JSON.parse(JSON.stringify(this.customParameters))),s}getNexusParameters(){let t={interactive_event:this.interactiveEvent};return t=Object.assign(t,JSON.parse(JSON.stringify(this.customParameters))),t}}var d=(e=>(e.AR="ar",e.QR="qr",e.INFO="info",e.DOWNLOAD="download",e.PREVIEW_CART="preview_cart",e.HOTSPOT_PANEL="hotspot_panel",e.SHARE_MODAL="share_modal",e.RESTART_MODAL="restart_modal",e.REMOVE_MODAL="remove_modal",e.LOAD_PRECONFIG_MODAL="load_preconfig_modal",e.MOVE_MODAL="move_modal",e.OUT_OF_STOCK_MODAL="out_of_stock_modal",e))(d||{}),_=(e=>(e.AUTO="auto",e.BUTTON="button",e.HOTSPOT="hotspot",e.GESTURE="gesture",e))(_||{}),c=(e=>(e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.CAD="CAD",e))(c||{}),m=(e=>(e.AR="ar",e.QR="qr",e.WEBGL2="webgl2",e))(m||{}),f=(e=>(e.AR_VIEW="ar_view",e.DIMENSION_TOGGLE="dimension_toggle",e.HOTSPOTS_TOGGLE="hotspots_toggle",e.HELP_TOGGLE="help_toggle",e.UTILITY_MENU_TOGGLE="utility_menu_toggle",e.HOTSPOT_ENTER="hotspot_enter",e.HOTSPOT_EXIT="hotspot_exit",e.SHARE="share",e.PDF_DOWNLOAD="pdf_download",e.COPY="copy",e.RESTART="restart",e.INSTRUCTIONS_SHOW="show_instructions",e.REVIEW_CART="review_cart",e.SHOP_NOW="shop_now",e.SUB_CATEGORY="sub_category",e.NEXT_STEP="next_step",e.PREVIOUS_STEP="previous_step",e))(f||{}),I=(e=>(e.ZOOM="zoom",e.ROTATE="rotate",e))(I||{}),N=(e=>(e.ROTATE="rotate",e.ZOOM="zoom",e.PAN="pan",e))(N||{}),y=(e=>(e.CONFIGURATION="configuration",e.SCENE="scene",e.PRODUCT="product",e))(y||{}),A=(e=>(e.FACEBOOK="facebook",e.TWITTER="twitter",e.EMAIL="email",e.COPY_LINK="copy_link",e.WHATSAPP="whatsapp",e.LINKEDIN="linkedin",e))(A||{});class M extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class q extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class b extends a{constructor(t,i){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:i}})}}class k extends a{constructor(t,i,n){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:i,error_type:n}})}}class F extends a{constructor(t){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:t}})}}class V extends a{static{this.SUPPORT_TYPE=m}constructor(t,i={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t,device_capabilities:i}})}}class $ extends a{static{this.BUTTON_TYPE=f}constructor(t,i){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:i}})}}class U extends a{static{this.PANEL_TYPE=d}static{this.TRIGGER_SOURCE=_}constructor(t,i,n,s){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:s,panel_type:i,trigger_source:n}})}}class j extends a{static{this.PANEL_TYPE=d}static{this.TRIGGER_SOURCE=_}constructor(t,i,n,s){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:s,panel_type:i,trigger_source:n}})}}class H extends a{constructor(t){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:t}})}}class W extends a{static{this.ACTION_PERFORMED=I}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class J extends a{static{this.INTERACTION_TYPE=N}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class K extends a{static{this.CURRENCY=c}constructor(t,i,n,s,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:r,value:i,currency:n,quantity:s}})}}class Z extends a{constructor(t){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:t}})}}class X extends a{static{this.CURRENCY=c}constructor(t,i,n,s){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:s,value:t,currency:i,quantity:n}})}}class B extends a{constructor(t,i){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:i,change_type:t}})}}class Q extends a{static{this.CONTENT_TYPES=y}static{this.SHARE_DESTINATIONS=A}constructor(t,i,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:n,content_type:t,share_destination:i}})}}class Y extends a{static{this.CURRENCY=c}constructor(t,i,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class tt extends a{static{this.CURRENCY=c}constructor(t,i,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class et extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class it extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class nt extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class st extends a{constructor(t,i,n){super({eventName:t,interactiveEvent:i,customParameters:n})}}/**
2
2
  * @license
3
3
  * Copyright (c) 2023 Epigraph LLC. All Rights Reserved.
4
4
  *
@@ -13,4 +13,4 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */var y;const c=Symbol("analyticsPluginsMap");y=c;class Q{constructor(t,e){this[y]=new Map,this.__consentPlugin=null,t&&e&&(this.__consentPlugin=this.buildConsentPlugin(t,e)),window.addEventListener("epigraphAnalyticsConsentChange",this.__onConsentChangeFromEvent)}__onConsentChangeFromEvent(t){let e=t;this.__overrideConsent=e.detail.hasConsent;for(const i of this[c].values())this.__hasConsent()||i.setStatus(h.RESTRICTED)}addEventPlugin(t){this[c].has(t.getUniquePluginIdentifier())||(this[c].set(t.getUniquePluginIdentifier(),t),t.setupPlugin())}__hasConsent(){let t=!0;return this.__overrideConsent!==void 0?(t=this.__overrideConsent,t):(this.__consentPlugin&&(t=this.__consentPlugin.hasConsent()),t)}sendEvent(t){this[c].forEach(e=>{e.sendEvent(t,this.__hasConsent())})}buildConsentPlugin(t,e){return t.toLowerCase()===g.OneTrust.toLowerCase()?new I(e):null}}exports.ConsentPluginNames=g;exports.EpigraphAddToFavouritesEvent=U;exports.EpigraphAnalytics=Q;exports.EpigraphArRequestedEvent=L;exports.EpigraphButtonClickEvent=G;exports.EpigraphChangeRateEvent=J;exports.EpigraphCheckoutEvent=Y;exports.EpigraphCompletionRateEvent=Z;exports.EpigraphContentSharedEvent=j;exports.EpigraphConversionEvent=W;exports.EpigraphCustomEvent=K;exports.EpigraphEngagementRateEvent=X;exports.EpigraphItemAddedEvent=$;exports.EpigraphItemMovedEvent=F;exports.EpigraphItemRemovedEvent=H;exports.EpigraphKeyboardInteractionEvent=k;exports.EpigraphModuleClosedEvent=z;exports.EpigraphModuleFailedEvent=D;exports.EpigraphModuleLoadingEvent=w;exports.EpigraphModuleReadyEvent=x;exports.EpigraphPanelClosedEvent=b;exports.EpigraphPanelOpenedEvent=q;exports.EpigraphSupportDetectedEvent=M;exports.EpigraphTouchInteractionEvent=V;exports.EpigraphVariantChangedEvent=B;exports.GA4AnalyticsPlugin=S;exports.NexusAnalyticsPlugin=R;exports.OneTrustConsentPlugin=I;
16
+ */var L;const p=Symbol("analyticsPluginsMap");L=p;class at{constructor(t,i){this[L]=new Map,this.__consentPlugin=null,t&&i&&(this.__consentPlugin=this.buildConsentPlugin(t,i)),window.addEventListener("epigraphAnalyticsConsentChange",this.__onConsentChangeFromEvent)}__onConsentChangeFromEvent(t){let i=t;this.__overrideConsent=i.detail.hasConsent;for(const n of this[p].values())this.__hasConsent()||n.setStatus(h.RESTRICTED)}addEventPlugin(t){this[p].has(t.getUniquePluginIdentifier())||(this[p].set(t.getUniquePluginIdentifier(),t),t.setupPlugin())}__hasConsent(){let t=!0;return this.__overrideConsent!==void 0?(t=this.__overrideConsent,t):(this.__consentPlugin&&(t=this.__consentPlugin.hasConsent()),t)}sendEvent(t){this[p].forEach(i=>{i.sendEvent(t,this.__hasConsent())})}buildConsentPlugin(t,i){return t.toLowerCase()===E.OneTrust.toLowerCase()?new w(i):null}}exports.ACTION_PERFORMED=I;exports.BUTTON_TYPE=f;exports.CONTENT_TYPES=y;exports.CURRENCY=c;exports.ConsentPluginNames=E;exports.EpigraphAddToFavouritesEvent=H;exports.EpigraphAnalytics=at;exports.EpigraphArRequestedEvent=M;exports.EpigraphButtonClickEvent=$;exports.EpigraphChangeRateEvent=et;exports.EpigraphCheckoutEvent=Y;exports.EpigraphCompletionRateEvent=it;exports.EpigraphContentSharedEvent=Q;exports.EpigraphConversionEvent=tt;exports.EpigraphCustomEvent=st;exports.EpigraphEngagementRateEvent=nt;exports.EpigraphItemAddedEvent=K;exports.EpigraphItemMovedEvent=Z;exports.EpigraphItemRemovedEvent=X;exports.EpigraphKeyboardInteractionEvent=W;exports.EpigraphModuleClosedEvent=F;exports.EpigraphModuleFailedEvent=k;exports.EpigraphModuleLoadingEvent=q;exports.EpigraphModuleReadyEvent=b;exports.EpigraphPanelClosedEvent=j;exports.EpigraphPanelOpenedEvent=U;exports.EpigraphSupportDetectedEvent=V;exports.EpigraphTouchInteractionEvent=J;exports.EpigraphVariantChangedEvent=B;exports.GA4AnalyticsPlugin=z;exports.INTERACTION_TYPE=N;exports.NexusAnalyticsPlugin=G;exports.OneTrustConsentPlugin=w;exports.PANEL_TYPE=d;exports.SHARE_DESTINATIONS=A;exports.SUPPORT_TYPE=m;exports.TRIGGER_SOURCE=_;