@epigraph/epigraph-std-lib 4.7.0-alpha → 4.7.1-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.
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.cjs +2 -2
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.js +179 -227
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalyticsEventLibrary.d.ts +83 -109
- package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.cjs +1 -1
- package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.d.ts +2 -1
- package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.js +1 -1
- package/dist/epigraph-std-lib.cjs +1 -1
- package/dist/epigraph-std-lib.js +61 -54
- package/package.json +1 -1
|
@@ -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=(i=>(i.UNAVAILABLE="unavailable",i.AVAILABLE="available",i.RESTRICTED="restricted",i))(h||{});const A=Symbol("data"),g=Symbol("next"),x=class S{constructor(t){this[A]=t,this[g]=null}get data(){return this[A]}set next(t){if(!(t instanceof S)&&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 y=x;const v=Symbol("head");class T{constructor(){this[v]=null}set head(t){this[v]=t}get head(){return this[v]}addToTail(t){let e=this.head;if(e){for(;e.next!==null;)e=e?.next;return e.next=new y(t)}return this.head=new y(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const C=Symbol("queue"),l=Symbol("size");class O{constructor(){this[C]=new T,this[l]=0}get queue(){return this[C]}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,e,n,s,r,o){this._pluginName=t,this._trackingId=e,this._experienceId=n,this._solution=s,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 n={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:n}))}}class R{constructor({trackingID:t,experienceID:e,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=e,this.solution=n,this.verboseLogging=s,this.__queue=new O,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(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 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 n=e.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 e of Array.from(t)){const n=e.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 e=0;e<t;e++){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 e=t.getGTMParameters(this.solution,this.experienceID,this.trackingID);const n=e;this.isValidPayload(e)||(e=await this.convertGTMParametersToEpgEventTag(t.eventName,e)),this.dataLayer&&(this.dataLayer.push(e),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,n))}async sendGA4Event(t){let e=t.getGa4Parameters(this.solution,this.experienceID,this.trackingID);const n=e;this.isValidPayload(e)||(e=await this.convertGA4ParametersToEpgEventTag(e)),window.gtag("event",t.eventName,e),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,e){try{let n=await this.sendGA4LongParameters(e);return{event:t,epg_event_tag:n,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",n={parameters:t};try{const s=await fetch(e,{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,e){try{const n={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(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 e=document.querySelectorAll("script[src]");for(const n of e){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 D{constructor({trackingID:t,experienceID:e,solution:n,sessionId:s,xPath:r,verboseLogging:o=!1,sendToStaging:L=!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=e,this.solution=n,this.verboseLogging=o,this.__queue=new O,this.url=L?"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(),n={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(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=(i=>(i.OneTrust="onetrust",i))(E||{});class a{constructor({eventName:t,interactiveEvent:e,customParameters:n}){this.eventName=t,this.interactiveEvent=e,this.customParameters=n}getGa4Parameters(t,e,n){let s={solution:t,experience_id:e,interactive_event:this.interactiveEvent,send_to:n};return s=Object.assign(s,JSON.parse(JSON.stringify(this.customParameters))),s}getGTMParameters(t,e,n){let s={solution:t,experience_id:e,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=(i=>(i.AR="ar",i.QR="qr",i.INFO="info",i.DOWNLOAD="download",i.PREVIEW_CART="preview_cart",i.HOTSPOT_PANEL="hotspot_panel",i.SHARE_MODAL="share_modal",i.RESTART_MODAL="restart_modal",i.REMOVE_MODAL="remove_modal",i.LOAD_PRECONFIG_MODAL="load_preconfig_modal",i.MOVE_MODAL="move_modal",i.OUT_OF_STOCK_MODAL="out_of_stock_modal",i))(d||{}),_=(i=>(i.AUTO="auto",i.BUTTON="button",i.HOTSPOT="hotspot",i.GESTURE="gesture",i))(_||{}),c=(i=>(i.USD="USD",i.EUR="EUR",i.GBP="GBP",i.CAD="CAD",i))(c||{}),m=(i=>(i.AR="ar",i.QR="qr",i.WEBGL2="webgl2",i))(m||{}),f=(i=>(i.AR_VIEW="ar_view",i.DIMENSION_SHOW="dimension_show",i.DIMENSION_HIDE="dimension_hide",i.HOTSPOTS_SHOW="hotspots_show",i.HOTSPOTS_HIDE="hotspots_hide",i.HELP_SHOW="help_show",i.HELP_HIDE="help_hide",i.HOTSPOT_ENTER="hotspot_enter",i.HOTSPOT_EXIT="hotspot_exit",i.SHARE="share",i.PDF_DOWNLOAD="pdf_download",i.COPY="copy",i.RESTART="restart",i.INSTRUCTIONS_SHOW="show_instructions",i.REVIEW_CART="review_cart",i.SHOP_NOW="shop_now",i.SUB_CATEGORY="sub_category",i.NEXT_STEP="next_step",i.PREVIOUS_STEP="previous_step",i))(f||{}),I=(i=>(i.ZOOM="zoom",i.ROTATE="rotate",i))(I||{}),N=(i=>(i.ROTATE="rotate",i.ZOOM="zoom",i.PAN="pan",i))(N||{});class z extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class M extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class q extends a{constructor(t,e){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e}})}}class G extends a{constructor(t,e,n){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e,error_type:n}})}}class b extends a{constructor(t){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:t}})}}class k extends a{static{this.SUPPORT_TYPE=m}constructor(t,e={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t,device_capabilities:e}})}}class V extends a{static{this.BUTTON_TYPE=f}constructor(t,e){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:e}})}}class $ extends a{static{this.PANEL_TYPE=d}static{this.TRIGGER_SOURCE=_}constructor(t,e,n,s){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:s,panel_type:e,trigger_source:n}})}}class F extends a{static{this.PANEL_TYPE=d}static{this.TRIGGER_SOURCE=_}constructor(t,e,n,s){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:s,panel_type:e,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=I}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class W extends a{static{this.INTERACTION_TYPE=N}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class U extends a{static{this.CURRENCY=c}constructor(t,e,n,s,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:r,value:e,currency:n,quantity:s}})}}class J extends a{constructor(t){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:t}})}}class Z extends a{static{this.CURRENCY=c}constructor(t,e,n,s){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:s,value:t,currency:e,quantity:n}})}}class X extends a{constructor(t,e){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class K extends a{constructor(t,e,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:n,content_type:t,share_destination:e}})}}class Q extends a{static{this.CURRENCY=c}constructor(t,e,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:n,value:t,currency:e}})}}class B extends a{static{this.CURRENCY=c}constructor(t,e,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:n,value:t,currency:e}})}}class Y extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class tt extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class et extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class it extends a{constructor(t,e,n){super({eventName:t,interactiveEvent:e,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
|
|
16
|
+
*/var P;const p=Symbol("analyticsPluginsMap");P=p;class nt{constructor(t,e){this[P]=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 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(e=>{e.sendEvent(t,this.__hasConsent())})}buildConsentPlugin(t,e){return t.toLowerCase()===E.OneTrust.toLowerCase()?new w(e):null}}exports.ACTION_PERFORMED=I;exports.BUTTON_TYPE=f;exports.CURRENCY=c;exports.ConsentPluginNames=E;exports.EpigraphAddToFavouritesEvent=H;exports.EpigraphAnalytics=nt;exports.EpigraphArRequestedEvent=z;exports.EpigraphButtonClickEvent=V;exports.EpigraphChangeRateEvent=Y;exports.EpigraphCheckoutEvent=Q;exports.EpigraphCompletionRateEvent=tt;exports.EpigraphContentSharedEvent=K;exports.EpigraphConversionEvent=B;exports.EpigraphCustomEvent=it;exports.EpigraphEngagementRateEvent=et;exports.EpigraphItemAddedEvent=U;exports.EpigraphItemMovedEvent=J;exports.EpigraphItemRemovedEvent=Z;exports.EpigraphKeyboardInteractionEvent=j;exports.EpigraphModuleClosedEvent=b;exports.EpigraphModuleFailedEvent=G;exports.EpigraphModuleLoadingEvent=M;exports.EpigraphModuleReadyEvent=q;exports.EpigraphPanelClosedEvent=F;exports.EpigraphPanelOpenedEvent=$;exports.EpigraphSupportDetectedEvent=k;exports.EpigraphTouchInteractionEvent=W;exports.EpigraphVariantChangedEvent=X;exports.GA4AnalyticsPlugin=R;exports.INTERACTION_TYPE=N;exports.NexusAnalyticsPlugin=D;exports.OneTrustConsentPlugin=w;exports.PANEL_TYPE=d;exports.SUPPORT_TYPE=m;exports.TRIGGER_SOURCE=_;
|