@epigraph/epigraph-std-lib 5.0.0-alpha.8 → 5.0.0-alpha.9
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 c=(e=>(e.UNAVAILABLE="unavailable",e.AVAILABLE="available",e.RESTRICTED="restricted",e))(c||{});const O=Symbol("data"),v=Symbol("next"),D=class w{constructor(t){this[O]=t,this[v]=null}get data(){return this[O]}set next(t){if(!(t instanceof w)&&t!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[v]=t}get next(){return this[v]}};let S=D;const E=Symbol("head");class G{constructor(){this[E]=null}set head(t){this[E]=t}get head(){return this[E]}addToTail(t){let i=this.head;if(i){for(;i.next!==null;)i=i?.next;return i.next=new S(t)}return this.head=new S(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const T=Symbol("queue"),l=Symbol("size");class L{constructor(){this[T]=new G,this[l]=0}get queue(){return this[T]}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=c.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 L,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=c.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=c.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 M{constructor({trackingID:t,experienceID:i,solution:n,sessionId:s,xPath:r,verboseLogging:o=!1,sendToStaging:x=!1}){this.__status=c.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 L,this.url=x?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=c.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=c.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 P{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 m=(e=>(e.OneTrust="onetrust",e))(m||{});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 f=(e=>(e.VARIANT="variant",e.CATEGORY_VARIANT="category_variant",e.GEOMETRY="geometry",e.CATEGORY_GEOMETRY="category_geometry",e.GLOBAL="global",e))(f||{}),d=(e=>(e.AR="ar",e.QR="qr",e.INFO="info",e.INSTRUCTIONS="instructions",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||{}),I=(e=>(e.NETWORK="network",e.EXPERIENCE_CONFIG_ERROR="experience-config-error",e.SCENE_LOAD_ERROR="scene-load-error",e.INITIAL_SCENE_LOAD_ERROR="initial-scene-load-error",e.AUTHENTICATION_FAILED="authentication-failed",e))(I||{}),_=(e=>(e.AUTO="auto",e.BUTTON="button",e.HOTSPOT="hotspot",e.GESTURE="gesture",e))(_||{}),h=(e=>(e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.CAD="CAD",e))(h||{}),N=(e=>(e.AR="ar",e.QR="qr",e.AR_WEBGL2="ar-webgl2",e.QR_WEBGL2="qr-webgl2",e))(N||{}),y=(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))(y||{}),g=(e=>(e.ZOOM="zoom",e.ROTATE="rotate",e.PAN="pan",e))(g||{}),A=(e=>(e.CONFIGURATION="configuration",e.SCENE="scene",e.PRODUCT="product",e))(A||{}),C=(e=>(e.FACEBOOK="facebook",e.TWITTER="twitter",e.EMAIL="email",e.COPY_LINK="copy_link",e.WHATSAPP="whatsapp",e.LINKEDIN="linkedin",e))(C||{});class q extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class b extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class k extends a{constructor(t,i){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:i}})}}class V extends a{static{this.MODULE_FAILED_ERRORS=I}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 $ extends a{static{this.SUPPORT_TYPE=N}constructor(t){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t}})}}class U extends a{static{this.BUTTON_TYPE=y}constructor(t,i){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:i}})}}class j 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 W 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 J extends a{static{this.ACTION_PERFORMED=g}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class K extends a{static{this.INTERACTION_TYPE=g}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class X extends a{static{this.CURRENCY=h}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 B extends a{static{this.CURRENCY=h}constructor(t,i,n,s){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:s,value:t,currency:i,quantity:n}})}}class Q extends a{static{this.VARIANT_CHANGE_TYPES=f}constructor(t,i){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:i,change_type:t}})}}class Y extends a{static{this.CONTENT_TYPES=A}static{this.SHARE_DESTINATIONS=C}constructor(t,i,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:n,content_type:t,share_destination:i}})}}class tt extends a{static{this.CURRENCY=h}constructor(t,i,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class et extends a{static{this.CURRENCY=h}constructor(t,i,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class it extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class nt extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class st extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class at extends a{constructor(t,i,n){super({eventName:t,interactiveEvent:i,customParameters:n})}}/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var c=(e=>(e.UNAVAILABLE="unavailable",e.AVAILABLE="available",e.RESTRICTED="restricted",e))(c||{});const O=Symbol("data"),v=Symbol("next"),D=class w{constructor(t){this[O]=t,this[v]=null}get data(){return this[O]}set next(t){if(!(t instanceof w)&&t!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[v]=t}get next(){return this[v]}};let S=D;const E=Symbol("head");class G{constructor(){this[E]=null}set head(t){this[E]=t}get head(){return this[E]}addToTail(t){let i=this.head;if(i){for(;i.next!==null;)i=i?.next;return i.next=new S(t)}return this.head=new S(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const T=Symbol("queue"),l=Symbol("size");class L{constructor(){this[T]=new G,this[l]=0}get queue(){return this[T]}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){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=c.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 L,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=c.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=c.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 M{constructor({trackingID:t,experienceID:i,solution:n,sessionId:s,xPath:r,verboseLogging:o=!1,sendToStaging:x=!1}){this.__status=c.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 L,this.url=x?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=c.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=c.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 P{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 m=(e=>(e.OneTrust="onetrust",e))(m||{});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 f=(e=>(e.VARIANT="variant",e.CATEGORY_VARIANT="category_variant",e.GEOMETRY="geometry",e.CATEGORY_GEOMETRY="category_geometry",e.GLOBAL="global",e))(f||{}),d=(e=>(e.AR="ar",e.QR="qr",e.INFO="info",e.INSTRUCTIONS="instructions",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||{}),I=(e=>(e.NETWORK="network",e.EXPERIENCE_CONFIG_ERROR="experience-config-error",e.SCENE_LOAD_ERROR="scene-load-error",e.INITIAL_SCENE_LOAD_ERROR="initial-scene-load-error",e.AUTHENTICATION_FAILED="authentication-failed",e))(I||{}),_=(e=>(e.AUTO="auto",e.BUTTON="button",e.HOTSPOT="hotspot",e.GESTURE="gesture",e))(_||{}),h=(e=>(e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.CAD="CAD",e))(h||{}),N=(e=>(e.AR="ar",e.QR="qr",e.AR_WEBGL2="ar-webgl2",e.QR_WEBGL2="qr-webgl2",e))(N||{}),y=(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))(y||{}),g=(e=>(e.ZOOM="zoom",e.ROTATE="rotate",e.PAN="pan",e))(g||{}),A=(e=>(e.CONFIGURATION="configuration",e.SCENE="scene",e.PRODUCT="product",e))(A||{}),C=(e=>(e.FACEBOOK="facebook",e.TWITTER="twitter",e.EMAIL="email",e.COPY_LINK="copy_link",e.WHATSAPP="whatsapp",e.LINKEDIN="linkedin",e))(C||{});class q extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class b extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class k extends a{constructor(t,i){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:i}})}}class V extends a{static{this.MODULE_FAILED_ERRORS=I}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 $ extends a{static{this.SUPPORT_TYPE=N}constructor(t){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t}})}}class U extends a{static{this.BUTTON_TYPE=y}constructor(t,i){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:i}})}}class j 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 W 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 J extends a{static{this.ACTION_PERFORMED=g}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class K extends a{static{this.INTERACTION_TYPE=g}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class X extends a{static{this.CURRENCY=h}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 B extends a{static{this.CURRENCY=h}constructor(t,i,n,s){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:s,value:t,currency:i,quantity:n}})}}class Q extends a{static{this.VARIANT_CHANGE_TYPES=f}constructor(t,i){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:i,change_type:t}})}}class Y extends a{static{this.CONTENT_TYPES=A}static{this.SHARE_DESTINATIONS=C}constructor(t,i,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:n,content_type:t,share_destination:i}})}}class tt extends a{static{this.CURRENCY=h}constructor(t,i,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class et extends a{static{this.CURRENCY=h}constructor(t,i,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:n,value:t,currency:i}})}}class it extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class nt extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class st extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class at 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
|
*
|
|
@@ -86,7 +86,6 @@ class u {
|
|
|
86
86
|
this._initializer = t;
|
|
87
87
|
}
|
|
88
88
|
notify(t, i) {
|
|
89
|
-
console.log("Notifying", t, i);
|
|
90
89
|
const n = {
|
|
91
90
|
pluginName: this._pluginName,
|
|
92
91
|
trackingId: this._trackingId,
|
|
@@ -100,7 +99,7 @@ class u {
|
|
|
100
99
|
window.dispatchEvent(new CustomEvent("epg-notification", { detail: n }));
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
|
-
class
|
|
102
|
+
class G {
|
|
104
103
|
constructor({
|
|
105
104
|
trackingID: t,
|
|
106
105
|
experienceID: i,
|
|
@@ -450,7 +449,7 @@ class q {
|
|
|
450
449
|
return "";
|
|
451
450
|
}
|
|
452
451
|
}
|
|
453
|
-
class
|
|
452
|
+
class D {
|
|
454
453
|
constructor(t) {
|
|
455
454
|
this.consentSet = !1, this.consent = !1, this.pluginName = "OneTrustConsentPlugin", this.consentIdentifier = t, this.consent = !1, this.addConsentChangedListener();
|
|
456
455
|
}
|
|
@@ -901,7 +900,7 @@ class rt {
|
|
|
901
900
|
* @private
|
|
902
901
|
*/
|
|
903
902
|
buildConsentPlugin(t, i) {
|
|
904
|
-
return t.toLowerCase() === A.OneTrust.toLowerCase() ? new
|
|
903
|
+
return t.toLowerCase() === A.OneTrust.toLowerCase() ? new D(i) : null;
|
|
905
904
|
}
|
|
906
905
|
}
|
|
907
906
|
export {
|
|
@@ -934,10 +933,10 @@ export {
|
|
|
934
933
|
F as EpigraphSupportDetectedEvent,
|
|
935
934
|
K as EpigraphTouchInteractionEvent,
|
|
936
935
|
B as EpigraphVariantChangedEvent,
|
|
937
|
-
|
|
936
|
+
G as GA4AnalyticsPlugin,
|
|
938
937
|
O as MODULE_FAILED_ERRORS,
|
|
939
938
|
q as NexusAnalyticsPlugin,
|
|
940
|
-
|
|
939
|
+
D as OneTrustConsentPlugin,
|
|
941
940
|
g as PANEL_TYPE,
|
|
942
941
|
x as SHARE_DESTINATIONS,
|
|
943
942
|
w as SUPPORT_TYPE,
|