@epigraph/epigraph-std-lib 4.5.3-alpha → 4.5.5-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.
@@ -2,7 +2,9 @@ export interface IAnalyticsEvent {
2
2
  eventName: string;
3
3
  interactiveEvent: boolean;
4
4
  customParameters: Record<string, unknown>;
5
- getParameters(): Record<string, unknown>;
5
+ getGa4Parameters(solution: string, experienceId: string, sendTo: string): Record<string, unknown>;
6
+ getGTMParameters(solution: string, experienceId: string, sendTo: string): Record<string, unknown>;
7
+ getNexusParameters(): Record<string, unknown>;
6
8
  }
7
9
  export interface IAnalyticsParameterItem {
8
10
  item_id: string;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var u=(i=>(i.UNAVAILABLE="unavailable",i.AVAILABLE="available",i.RESTRICTED="restricted",i))(u||{});const g=Symbol("data"),d=Symbol("next"),w=class m{constructor(e){this[g]=e,this[d]=null}get data(){return this[g]}set next(e){if(!(e instanceof m)&&e!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[d]=e}get next(){return this[d]}};let _=w;const p=Symbol("head");class P{constructor(){this[p]=null}set head(e){this[p]=e}get head(){return this[p]}addToTail(e){let t=this.head;if(t){for(;t.next!==null;)t=t?.next;return t.next=new _(e)}return this.head=new _(e)}removeHead(){const e=this.head;if(e)return this.head=e.next,e.data}}const v=Symbol("queue"),h=Symbol("size");class E{constructor(){this[v]=new P,this[h]=0}get queue(){return this[v]}get size(){return this[h]}enqueue(e){this.queue.addToTail(e),this[h]++}dequeue(){const e=this.queue.removeHead();return this[h]--,e}}class N{constructor({trackingID:e,experienceID:t,solution:n,verboseLogging:s=!1}){this.dataLayerName="dataLayer",this.__status=u.UNAVAILABLE,this.__sentEventCount=0,this.__initializationAttempts=0,this.__lastInitializationAttempt=0,this.__maxInitializationAttempts=10,this.__initializationRetryDelay=2e3,this.__isInitialized=!1,this.__initializationMethod="NONE",this.__nexusFailureReported=!1,this.name=this.pluginName="GA4-PLUGIN",this.trackingID=e,this.experienceID=t,this.solution=n,this.verboseLogging=s,this.__queue=new E,this.initializePlugin()}getStatus(){return this.__status}setStatus(e){this.__status=e}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(e,t){if(this.__queue.enqueue(e),!t){this.__status=u.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")}}async initializePlugin(){if(this.__isInitialized)return;const e=Date.now();if(this.__initializationAttempts>=this.__maxInitializationAttempts){this.__nexusFailureReported||(await this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS","Maximum initialization attempts reached"),this.__nexusFailureReported=!0);return}if(e-this.__lastInitializationAttempt<this.__initializationRetryDelay)return;this.__lastInitializationAttempt=e,this.__initializationAttempts++;const t=await this.detectAndSetupAnalytics();t.success?(this.__isInitialized=!0,this.__status=u.AVAILABLE,this.__initializationMethod=t.method,this.dataLayerName=t.dataLayerName,this.dataLayer=window[this.dataLayerName],this.logger(`Successfully initialized ${t.method} with dataLayer: ${this.dataLayerName}`),this.__queue.size>0&&await this.dequeueAndSendEvents()):(this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${t.error}`),this.__initializationAttempts<this.__maxInitializationAttempts&&setTimeout(()=>this.initializePlugin(),this.__initializationRetryDelay))}async detectAndSetupAnalytics(){const e=this.detectGTM();if(e)return this.logger(`GTM detected with container ID: ${e.containerId}`),{success:!0,method:"GTM",dataLayerName:e.dataLayerName};if(window.dataLayer)return this.logger("Existing dataLayer found"),{success:!0,method:"GA4",dataLayerName:"dataLayer"};const t=this.findGA4ScriptInfo(this.trackingID);if(t){const n=t.l||"dataLayer";if(this.logger(`GA4 script found, setting up with dataLayer: ${n}`),this.setupGA4(n))return{success:!0,method:"GA4",dataLayerName:n}}return this.setupGA4("dataLayer")?{success:!0,method:"GA4",dataLayerName:"dataLayer"}:{success:!1,method:"NONE",dataLayerName:"dataLayer",error:"No analytics setup found and unable to create one"}}detectGTM(){const e=document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');for(const t of Array.from(e)){const n=t.getAttribute("src");if(n){const s=n.match(/gtm\.js\?id=([^&]+)/);if(s){const r=n.match(/&l=([^&]+)/),o=r?r[1]:"dataLayer";return{containerId:s[1],dataLayerName:o}}}}return null}setupGA4(e){try{return window[e]||(window[e]=[]),window.epgDataLayerName=e,typeof window.gtag!="function"&&(window.gtag=function(){const t=window.epgDataLayerName;t&&window[t]&&Array.isArray(window[t])&&window[t].push(arguments)},window.gtag("js",new Date),window.gtag("config",this.trackingID,{send_page_view:!1})),!0}catch(t){return this.logger(`Error setting up GA4: ${t}`),!1}}async dequeueAndSendEvents(){if(!this.__isInitialized||!this.dataLayer)return;let e=this.__queue.size;for(let t=0;t<e;t++){const n=this.__queue.dequeue();let s=n.getParameters();if(s.solution=this.solution,s.experience_id=this.experienceID,n.customParameters&&Object.assign(s,n.customParameters),JSON.stringify(s).length>459)try{s={epg_event_tag:await this.sendGA4LongParameters(s)}}catch{}try{this.__initializationMethod==="GTM"?this.sendToGTM(n.eventName,s):this.__initializationMethod==="GA4"&&window.gtag("event",n.eventName,s),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${n.eventName}`)}catch(o){this.logger(`Error sending event ${n.eventName}: ${o}`),this.__queue.enqueue(n)}}}logger(e){this.verboseLogging&&console.warn(e)}async sendGA4LongParameters(e){const t="https://api.myepigraph.com/api/analytics/ga4/custom",n={parameters:e};try{const s=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return s.ok?(await s.json())?.id??"":""}catch{return""}}sendToGTM(e,t){this.dataLayer&&this.dataLayer.push({event:e,...t})}async reportFailureToNexus(e,t){try{const n={plugin:"GA4",trackingId:this.trackingID,solution:this.solution,experienceId:this.experienceID,failureType:e,errorMessage:t,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}`)}}findGA4ScriptInfo(e){const t=document.querySelectorAll("script[src]");for(const n of t){const s=n.getAttribute("src");if(s&&s.includes(e)){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 C{constructor({trackingID:e,experienceID:t,solution:n,sessionId:s,xPath:r,verboseLogging:o=!1,sendToStaging:A=!1}){this.__status=u.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=s,this.xPath=r,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=e,this.experienceID=t,this.solution=n,this.verboseLogging=o,this.__queue=new E,this.url=A?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=u.AVAILABLE}getStatus(){return this.__status}setStatus(e){this.__status=e}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}async sendEvent(e,t){if(this.__queue.enqueue(e),!t){this.__status=u.RESTRICTED;return}await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let e=0;e<this.__queue.size;e++){const t=this.__queue.dequeue();t.customParameters.solution=this.solution;const n={trackingID:this.trackingID,experience_id:this.experienceID,action:t.eventName,parameters:t.getParameters()};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)})).status===200,""}catch{return""}this.__sentEventCount++}return""}}class f{constructor(e){this.consentSet=!1,this.consent=!1,this.pluginName="OneTrustConsentPlugin",this.consentIdentifier=e,this.consent=!1,this.addConsentChangedListener()}hasConsent(){if(this.consentSet)return this.consent;if(window.OnetrustActiveGroups!==void 0){let e=window.OnetrustActiveGroups;e!==void 0&&e.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 l=(i=>(i.OneTrust="onetrust",i))(l||{});class a{constructor({eventName:e,interactiveEvent:t,customParameters:n}){this.eventName=e,this.interactiveEvent=t,this.customParameters=n}getParameters(){let e={interactive_event:this.interactiveEvent};return e=Object.assign(e,JSON.parse(JSON.stringify(this.customParameters))),e}}class I extends a{constructor(e=[]){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:e}})}}class L extends a{constructor(e){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:e}})}}class S extends a{constructor(e,t){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:e,load_time_ms:t}})}}class x extends a{constructor(e,t,n){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:e,load_time_ms:t,error_type:n}})}}class T extends a{constructor(e=[]){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:e}})}}class q extends a{constructor(e,t={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:e,device_capabilities:t}})}}class z extends a{constructor(e,t){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:e,button_name:t}})}}class R extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:s}})}}class D extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:s}})}}class O extends a{constructor(e=[]){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:e}})}}class b extends a{constructor(e){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:e}})}}class G extends a{constructor(e){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:e}})}}class M extends a{constructor(e=[],t,n,s,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:e,value:n,currency:s,quantity:r}})}}class $ extends a{constructor(e=[]){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:e}})}}class k extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n,quantity:s}})}}class F extends a{constructor(e=[],t){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class j extends a{constructor(e=[],t,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:e,content_type:t,share_destination:n}})}}class U extends a{constructor(e=[],t,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class B extends a{constructor(e=[],t,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class V extends a{constructor(e){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:e}})}}class J extends a{constructor(e){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:e}})}}class H extends a{constructor(e){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:e}})}}class X extends a{constructor(e,t,n){super({eventName:e,interactiveEvent:t,customParameters:n})}}/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var o=(s=>(s.UNAVAILABLE="unavailable",s.AVAILABLE="available",s.RESTRICTED="restricted",s))(o||{});const g=Symbol("data"),l=Symbol("next"),A=class m{constructor(e){this[g]=e,this[l]=null}get data(){return this[g]}set next(e){if(!(e instanceof m)&&e!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[l]=e}get next(){return this[l]}};let v=A;const d=Symbol("head");class N{constructor(){this[d]=null}set head(e){this[d]=e}get head(){return this[d]}addToTail(e){let t=this.head;if(t){for(;t.next!==null;)t=t?.next;return t.next=new v(e)}return this.head=new v(e)}removeHead(){const e=this.head;if(e)return this.head=e.next,e.data}}const _=Symbol("queue"),h=Symbol("size");class E{constructor(){this[_]=new N,this[h]=0}get queue(){return this[_]}get size(){return this[h]}enqueue(e){this.queue.addToTail(e),this[h]++}dequeue(){const e=this.queue.removeHead();return this[h]--,e}}class C{constructor({trackingID:e,experienceID:t,solution:n,verboseLogging:i=!1}){this.__status=o.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=e,this.experienceID=t,this.solution=n,this.verboseLogging=i,this.__queue=new E,this.initializePlugin()}getStatus(){return this.__status}setStatus(e){this.__status=e}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(e,t){if(this.__queue.enqueue(e),!t){this.__status=o.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);return}const e=performance.now();if(this.__initializationAttempts>0&&e-this.__lastInitializationAttempt<this.__initializationRetryDelay)return;this.__lastInitializationAttempt=e,this.__initializationAttempts++;const t=this.detectAndSetupAnalytics();t.success?(this.__isInitialized=!0,this.__status=o.AVAILABLE,this.__initializationMethod=t.method,this.dataLayerName=t.dataLayerName,this.dataLayer=window[this.dataLayerName],this.logger(`Successfully initialized ${t.method} with dataLayer: ${this.dataLayerName}`),this.__queue.size>0&&this.dequeueAndSendEvents()):(this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${t.error}`),this.__initializationAttempts<this.__maxInitializationAttempts&&setTimeout(()=>{this.initializePlugin()},this.__initializationRetryDelay))}detectAndSetupAnalytics(){const e=this.detectGTM();if(e)return this.logger(`GTM detected with container ID: ${e.containerId}`),{success:!0,method:"GTM",dataLayerName:e.dataLayerName};const t=this.findGA4Info(this.trackingID);if(t){const n=t.l||"dataLayer";return this.logger(`GA4 script found, setting up with dataLayer: ${n}`),{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 e=document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');for(const t of Array.from(e)){const n=t.getAttribute("src");if(n){const i=n.match(/gtm\.js\?id=([^&]+)/);if(i&&i.length>0){const r=n.match(/&l=([^&]+)/),u=r?r[1]:"dataLayer";return{containerId:i[1],dataLayerName:u}}}}return null}async dequeueAndSendEvents(){if(!this.__isInitialized||!this.dataLayer)return;let e=this.__queue.size;for(let t=0;t<e;t++){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(i){this.logger(`Error sending event ${n.eventName}: ${i}`),this.__queue.enqueue(n)}}}async sendGTMEvent(e){let t=e.getGTMParameters(this.solution,this.experienceID,this.trackingID);this.isValidPayload(t)||(t=await this.convertGTMParametersToEpgEventTag(e.eventName,t)),this.dataLayer&&this.dataLayer.push(t)}async sendGA4Event(e){let t=e.getGa4Parameters(this.solution,this.experienceID,this.trackingID);this.isValidPayload(t)||(t=await this.convertGA4ParametersToEpgEventTag(t)),window.gtag("event",e.eventName,t)}isValidPayload(e){if(Object.keys(e).length>=25)return!1;for(const[i,r]of Object.entries(e))if(i!=="items"&&(i.length>40||String(r).length>100))return!1;return!0}async convertGTMParametersToEpgEventTag(e,t){try{let n=await this.sendGA4LongParameters(t);return{event:e,epg_event_tag:n,send_to:this.trackingID}}catch{return t}}async convertGA4ParametersToEpgEventTag(e){try{return{epg_event_tag:await this.sendGA4LongParameters(e),send_to:this.trackingID}}catch{return e}}logger(e){this.verboseLogging&&console.warn(e)}async sendGA4LongParameters(e){const t="https://api.myepigraph.com/api/analytics/ga4/custom",n={parameters:e};try{const i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return i.ok?(await i.json())?.id??"":""}catch{return""}}async reportFailureToNexus(e,t){try{const n={plugin:"GA4",trackingId:this.trackingID,solution:this.solution,experienceId:this.experienceID,failureType:e,errorMessage:t,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(e){if(window.google_tag_manager&&window.google_tag_manager[e]){const n=window.google_tag_manager[e];if(n&&n.dataLayerName)return{fullSrc:"",id:e,l:n.dataLayerName}}const t=document.querySelectorAll("script[src]");for(const n of t){const i=n.getAttribute("src");if(i&&i.includes(e)){const r=new URL(i,location.href),u=Object.fromEntries(r.searchParams.entries());return{fullSrc:r.href,id:u.id||void 0,l:u.l||void 0}}}return null}}class I{constructor({trackingID:e,experienceID:t,solution:n,sessionId:i,xPath:r,verboseLogging:u=!1,sendToStaging:P=!1}){this.__status=o.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=i,this.xPath=r,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=e,this.experienceID=t,this.solution=n,this.verboseLogging=u,this.__queue=new E,this.url=P?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=o.AVAILABLE}getStatus(){return this.__status}setStatus(e){this.__status=e}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}async sendEvent(e,t){if(this.__queue.enqueue(e),!t){this.__status=o.RESTRICTED;return}await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let e=0;e<this.__queue.size;e++){const t=this.__queue.dequeue();t.customParameters.solution=this.solution;const n={trackingID:this.trackingID,experience_id:this.experienceID,action:t.eventName,parameters:t.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)})).status===200,""}catch{return""}this.__sentEventCount++}return""}}class f{constructor(e){this.consentSet=!1,this.consent=!1,this.pluginName="OneTrustConsentPlugin",this.consentIdentifier=e,this.consent=!1,this.addConsentChangedListener()}hasConsent(){if(this.consentSet)return this.consent;if(window.OnetrustActiveGroups!==void 0){let e=window.OnetrustActiveGroups;e!==void 0&&e.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 p=(s=>(s.OneTrust="onetrust",s))(p||{});class a{constructor({eventName:e,interactiveEvent:t,customParameters:n}){this.eventName=e,this.interactiveEvent=t,this.customParameters=n}getGa4Parameters(e,t,n){let i={solution:e,experience_id:t,interactive_event:this.interactiveEvent,send_to:n};return i=Object.assign(i,JSON.parse(JSON.stringify(this.customParameters))),i}getGTMParameters(e,t,n){let i={solution:e,experience_id:t,event:this.eventName,interactive_event:this.interactiveEvent,send_to:n};return i=Object.assign(i,JSON.parse(JSON.stringify(this.customParameters))),i}getNexusParameters(){let e={interactive_event:this.interactiveEvent};return e=Object.assign(e,JSON.parse(JSON.stringify(this.customParameters))),e}}class S extends a{constructor(e=[]){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:e}})}}class w extends a{constructor(e){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:e}})}}class T extends a{constructor(e,t){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:e,load_time_ms:t}})}}class x extends a{constructor(e,t,n){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:e,load_time_ms:t,error_type:n}})}}class L extends a{constructor(e=[]){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:e}})}}class q extends a{constructor(e,t={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:e,device_capabilities:t}})}}class z extends a{constructor(e,t){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:e,button_name:t}})}}class O extends a{constructor(e=[],t,n,i){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:i}})}}class G extends a{constructor(e=[],t,n,i){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:i}})}}class M extends a{constructor(e=[]){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:e}})}}class b extends a{constructor(e){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:e}})}}class R extends a{constructor(e){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:e}})}}class D extends a{constructor(e=[],t,n,i,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:e,value:n,currency:i,quantity:r}})}}class k extends a{constructor(e=[]){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:e}})}}class $ extends a{constructor(e=[],t,n,i){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n,quantity:i}})}}class j extends a{constructor(e=[],t){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class F extends a{constructor(e=[],t,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:e,content_type:t,share_destination:n}})}}class V extends a{constructor(e=[],t,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class U extends a{constructor(e=[],t,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class B extends a{constructor(e){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:e}})}}class J extends a{constructor(e){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:e}})}}class K extends a{constructor(e){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:e}})}}class H extends a{constructor(e,t,n){super({eventName:e,interactiveEvent:t,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 K{constructor(e,t){this[y]=new Map,this.__consentPlugin=null,e&&t&&(this.__consentPlugin=this.buildConsentPlugin(e,t)),window.addEventListener("epigraphAnalyticsConsentChange",this.__onConsentChangeFromEvent)}__onConsentChangeFromEvent(e){let t=e;this.__overrideConsent=t.detail.hasConsent;for(const n of this[c].values())this.__hasConsent()||n.setStatus(u.RESTRICTED)}addEventPlugin(e){this[c].has(e.getUniquePluginIdentifier())||(this[c].set(e.getUniquePluginIdentifier(),e),e.setupPlugin())}__hasConsent(){let e=!0;return this.__overrideConsent!==void 0?(e=this.__overrideConsent,e):(this.__consentPlugin&&(e=this.__consentPlugin.hasConsent()),e)}sendEvent(e){this[c].forEach(t=>{t.sendEvent(e,this.__hasConsent())})}buildConsentPlugin(e,t){return e.toLowerCase()===l.OneTrust.toLowerCase()?new f(t):null}}exports.ConsentPluginNames=l;exports.EpigraphAddToFavouritesEvent=O;exports.EpigraphAnalytics=K;exports.EpigraphArRequestedEvent=I;exports.EpigraphButtonClickEvent=z;exports.EpigraphChangeRateEvent=V;exports.EpigraphCheckoutEvent=U;exports.EpigraphCompletionRateEvent=J;exports.EpigraphContentSharedEvent=j;exports.EpigraphConversionEvent=B;exports.EpigraphCustomEvent=X;exports.EpigraphEngagementRateEvent=H;exports.EpigraphItemAddedEvent=M;exports.EpigraphItemMovedEvent=$;exports.EpigraphItemRemovedEvent=k;exports.EpigraphKeyboardInteractionEvent=b;exports.EpigraphModuleClosedEvent=T;exports.EpigraphModuleFailedEvent=x;exports.EpigraphModuleLoadingEvent=L;exports.EpigraphModuleReadyEvent=S;exports.EpigraphPanelClosedEvent=D;exports.EpigraphPanelOpenedEvent=R;exports.EpigraphSupportDetectedEvent=q;exports.EpigraphTouchInteractionEvent=G;exports.EpigraphVariantChangedEvent=F;exports.GA4AnalyticsPlugin=N;exports.NexusAnalyticsPlugin=C;exports.OneTrustConsentPlugin=f;
16
+ */var y;const c=Symbol("analyticsPluginsMap");y=c;class X{constructor(e,t){this[y]=new Map,this.__consentPlugin=null,e&&t&&(this.__consentPlugin=this.buildConsentPlugin(e,t)),window.addEventListener("epigraphAnalyticsConsentChange",this.__onConsentChangeFromEvent)}__onConsentChangeFromEvent(e){let t=e;this.__overrideConsent=t.detail.hasConsent;for(const n of this[c].values())this.__hasConsent()||n.setStatus(o.RESTRICTED)}addEventPlugin(e){this[c].has(e.getUniquePluginIdentifier())||(this[c].set(e.getUniquePluginIdentifier(),e),e.setupPlugin())}__hasConsent(){let e=!0;return this.__overrideConsent!==void 0?(e=this.__overrideConsent,e):(this.__consentPlugin&&(e=this.__consentPlugin.hasConsent()),e)}sendEvent(e){this[c].forEach(t=>{t.sendEvent(e,this.__hasConsent())})}buildConsentPlugin(e,t){return e.toLowerCase()===p.OneTrust.toLowerCase()?new f(t):null}}exports.ConsentPluginNames=p;exports.EpigraphAddToFavouritesEvent=M;exports.EpigraphAnalytics=X;exports.EpigraphArRequestedEvent=S;exports.EpigraphButtonClickEvent=z;exports.EpigraphChangeRateEvent=B;exports.EpigraphCheckoutEvent=V;exports.EpigraphCompletionRateEvent=J;exports.EpigraphContentSharedEvent=F;exports.EpigraphConversionEvent=U;exports.EpigraphCustomEvent=H;exports.EpigraphEngagementRateEvent=K;exports.EpigraphItemAddedEvent=D;exports.EpigraphItemMovedEvent=k;exports.EpigraphItemRemovedEvent=$;exports.EpigraphKeyboardInteractionEvent=b;exports.EpigraphModuleClosedEvent=L;exports.EpigraphModuleFailedEvent=x;exports.EpigraphModuleLoadingEvent=w;exports.EpigraphModuleReadyEvent=T;exports.EpigraphPanelClosedEvent=G;exports.EpigraphPanelOpenedEvent=O;exports.EpigraphSupportDetectedEvent=q;exports.EpigraphTouchInteractionEvent=R;exports.EpigraphVariantChangedEvent=j;exports.GA4AnalyticsPlugin=C;exports.NexusAnalyticsPlugin=I;exports.OneTrustConsentPlugin=f;
@@ -1,53 +1,53 @@
1
- var u = /* @__PURE__ */ ((i) => (i.UNAVAILABLE = "unavailable", i.AVAILABLE = "available", i.RESTRICTED = "restricted", i))(u || {});
2
- const p = Symbol("data"), d = Symbol("next"), w = class m {
3
- constructor(t) {
4
- this[p] = t, this[d] = null;
1
+ var o = /* @__PURE__ */ ((s) => (s.UNAVAILABLE = "unavailable", s.AVAILABLE = "available", s.RESTRICTED = "restricted", s))(o || {});
2
+ const p = Symbol("data"), l = Symbol("next"), N = class v {
3
+ constructor(e) {
4
+ this[p] = e, this[l] = null;
5
5
  }
6
6
  get data() {
7
7
  return this[p];
8
8
  }
9
- set next(t) {
10
- if (!(t instanceof m) && t !== null)
9
+ set next(e) {
10
+ if (!(e instanceof v) && e !== null)
11
11
  throw new Error(
12
12
  "This node is not an instance of the custom class 'Node'."
13
13
  );
14
- this[d] = t;
14
+ this[l] = e;
15
15
  }
16
16
  get next() {
17
- return this[d];
17
+ return this[l];
18
18
  }
19
19
  };
20
- let g = w;
21
- const l = Symbol("head");
22
- class A {
20
+ let g = N;
21
+ const d = Symbol("head");
22
+ class P {
23
23
  constructor() {
24
- this[l] = null;
24
+ this[d] = null;
25
25
  }
26
- set head(t) {
27
- this[l] = t;
26
+ set head(e) {
27
+ this[d] = e;
28
28
  }
29
29
  get head() {
30
- return this[l];
30
+ return this[d];
31
31
  }
32
- addToTail(t) {
33
- let e = this.head;
34
- if (e) {
35
- for (; e.next !== null; )
36
- e = e?.next;
37
- return e.next = new g(t);
32
+ addToTail(e) {
33
+ let t = this.head;
34
+ if (t) {
35
+ for (; t.next !== null; )
36
+ t = t?.next;
37
+ return t.next = new g(e);
38
38
  }
39
- return this.head = new g(t);
39
+ return this.head = new g(e);
40
40
  }
41
41
  removeHead() {
42
- const t = this.head;
43
- if (t)
44
- return this.head = t.next, t.data;
42
+ const e = this.head;
43
+ if (e)
44
+ return this.head = e.next, e.data;
45
45
  }
46
46
  }
47
47
  const _ = Symbol("queue"), h = Symbol("size");
48
- class v {
48
+ class m {
49
49
  constructor() {
50
- this[_] = new A(), this[h] = 0;
50
+ this[_] = new P(), this[h] = 0;
51
51
  }
52
52
  get queue() {
53
53
  return this[_];
@@ -55,28 +55,28 @@ class v {
55
55
  get size() {
56
56
  return this[h];
57
57
  }
58
- enqueue(t) {
59
- this.queue.addToTail(t), this[h]++;
58
+ enqueue(e) {
59
+ this.queue.addToTail(e), this[h]++;
60
60
  }
61
61
  dequeue() {
62
- const t = this.queue.removeHead();
63
- return this[h]--, t;
62
+ const e = this.queue.removeHead();
63
+ return this[h]--, e;
64
64
  }
65
65
  }
66
- class P {
66
+ class I {
67
67
  constructor({
68
- trackingID: t,
69
- experienceID: e,
68
+ trackingID: e,
69
+ experienceID: t,
70
70
  solution: n,
71
- verboseLogging: s = !1
71
+ verboseLogging: i = !1
72
72
  }) {
73
- this.dataLayerName = "dataLayer", this.__status = u.UNAVAILABLE, this.__sentEventCount = 0, this.__initializationAttempts = 0, this.__lastInitializationAttempt = 0, 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 v(), this.initializePlugin();
73
+ this.__status = o.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 = e, this.experienceID = t, this.solution = n, this.verboseLogging = i, this.__queue = new m(), this.initializePlugin();
74
74
  }
75
75
  getStatus() {
76
76
  return this.__status;
77
77
  }
78
- setStatus(t) {
79
- this.__status = t;
78
+ setStatus(e) {
79
+ this.__status = e;
80
80
  }
81
81
  getPendingEventCount() {
82
82
  return this.__queue.size;
@@ -99,12 +99,12 @@ class P {
99
99
  /**
100
100
  * This function will send an Event to Google Analytics 4.
101
101
  *
102
- * @param eventData IAnalyticsEvent The event to be tracked
102
+ * @param analyticsEvent
103
103
  * @param consent boolean Whether consent is granted
104
104
  */
105
- async sendEvent(t, e) {
106
- if (this.__queue.enqueue(t), !e) {
107
- this.__status = u.RESTRICTED;
105
+ async sendEvent(e, t) {
106
+ if (this.__queue.enqueue(e), !t) {
107
+ this.__status = o.RESTRICTED;
108
108
  return;
109
109
  }
110
110
  if (!this.__isInitialized) {
@@ -117,49 +117,40 @@ class P {
117
117
  this.logger(n), await this.reportFailureToNexus("EVENT_SEND_ERROR", n?.toString() || "Unknown error");
118
118
  }
119
119
  }
120
- async initializePlugin() {
120
+ initializePlugin() {
121
121
  if (this.__isInitialized)
122
122
  return;
123
- const t = Date.now();
124
123
  if (this.__initializationAttempts >= this.__maxInitializationAttempts) {
125
- this.__nexusFailureReported || (await this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS", "Maximum initialization attempts reached"), this.__nexusFailureReported = !0);
124
+ this.__nexusFailureReported || (this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS", "Maximum initialization attempts reached"), this.__nexusFailureReported = !0);
126
125
  return;
127
126
  }
128
- if (t - this.__lastInitializationAttempt < this.__initializationRetryDelay)
127
+ const e = performance.now();
128
+ if (this.__initializationAttempts > 0 && e - this.__lastInitializationAttempt < this.__initializationRetryDelay)
129
129
  return;
130
- this.__lastInitializationAttempt = t, this.__initializationAttempts++;
131
- const e = await this.detectAndSetupAnalytics();
132
- e.success ? (this.__isInitialized = !0, this.__status = u.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.__queue.size > 0 && await this.dequeueAndSendEvents()) : (this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${e.error}`), this.__initializationAttempts < this.__maxInitializationAttempts && setTimeout(() => this.initializePlugin(), this.__initializationRetryDelay));
133
- }
134
- async detectAndSetupAnalytics() {
135
- const t = this.detectGTM();
136
- if (t)
137
- return this.logger(`GTM detected with container ID: ${t.containerId}`), {
130
+ this.__lastInitializationAttempt = e, this.__initializationAttempts++;
131
+ const t = this.detectAndSetupAnalytics();
132
+ t.success ? (this.__isInitialized = !0, this.__status = o.AVAILABLE, this.__initializationMethod = t.method, this.dataLayerName = t.dataLayerName, this.dataLayer = window[this.dataLayerName], this.logger(`Successfully initialized ${t.method} with dataLayer: ${this.dataLayerName}`), this.__queue.size > 0 && this.dequeueAndSendEvents()) : (this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${t.error}`), this.__initializationAttempts < this.__maxInitializationAttempts && setTimeout(() => {
133
+ this.initializePlugin();
134
+ }, this.__initializationRetryDelay));
135
+ }
136
+ detectAndSetupAnalytics() {
137
+ const e = this.detectGTM();
138
+ if (e)
139
+ return this.logger(`GTM detected with container ID: ${e.containerId}`), {
138
140
  success: !0,
139
141
  method: "GTM",
140
- dataLayerName: t.dataLayerName
142
+ dataLayerName: e.dataLayerName
141
143
  };
142
- if (window.dataLayer)
143
- return this.logger("Existing dataLayer found"), {
144
+ const t = this.findGA4Info(this.trackingID);
145
+ if (t) {
146
+ const n = t.l || "dataLayer";
147
+ return this.logger(`GA4 script found, setting up with dataLayer: ${n}`), {
144
148
  success: !0,
145
149
  method: "GA4",
146
- dataLayerName: "dataLayer"
150
+ dataLayerName: n
147
151
  };
148
- const e = this.findGA4ScriptInfo(this.trackingID);
149
- if (e) {
150
- const n = e.l || "dataLayer";
151
- if (this.logger(`GA4 script found, setting up with dataLayer: ${n}`), this.setupGA4(n))
152
- return {
153
- success: !0,
154
- method: "GA4",
155
- dataLayerName: n
156
- };
157
152
  }
158
- return this.setupGA4("dataLayer") ? {
159
- success: !0,
160
- method: "GA4",
161
- dataLayerName: "dataLayer"
162
- } : {
153
+ return {
163
154
  success: !1,
164
155
  method: "NONE",
165
156
  dataLayerName: "dataLayer",
@@ -167,32 +158,22 @@ class P {
167
158
  };
168
159
  }
169
160
  detectGTM() {
170
- const t = document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');
171
- for (const e of Array.from(t)) {
172
- const n = e.getAttribute("src");
161
+ const e = document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');
162
+ for (const t of Array.from(e)) {
163
+ const n = t.getAttribute("src");
173
164
  if (n) {
174
- const s = n.match(/gtm\.js\?id=([^&]+)/);
175
- if (s) {
176
- const r = n.match(/&l=([^&]+)/), o = r ? r[1] : "dataLayer";
165
+ const i = n.match(/gtm\.js\?id=([^&]+)/);
166
+ if (i && i.length > 0) {
167
+ const r = n.match(/&l=([^&]+)/), u = r ? r[1] : "dataLayer";
177
168
  return {
178
- containerId: s[1],
179
- dataLayerName: o
169
+ containerId: i[1],
170
+ dataLayerName: u
180
171
  };
181
172
  }
182
173
  }
183
174
  }
184
175
  return null;
185
176
  }
186
- setupGA4(t) {
187
- try {
188
- return window[t] || (window[t] = []), window.epgDataLayerName = t, typeof window.gtag != "function" && (window.gtag = function() {
189
- const e = window.epgDataLayerName;
190
- e && window[e] && Array.isArray(window[e]) && window[e].push(arguments);
191
- }, window.gtag("js", /* @__PURE__ */ new Date()), window.gtag("config", this.trackingID, { send_page_view: !1 })), !0;
192
- } catch (e) {
193
- return this.logger(`Error setting up GA4: ${e}`), !1;
194
- }
195
- }
196
177
  /**
197
178
  * Send all events that are in the queue
198
179
  * @private
@@ -200,35 +181,97 @@ class P {
200
181
  async dequeueAndSendEvents() {
201
182
  if (!this.__isInitialized || !this.dataLayer)
202
183
  return;
203
- let t = this.__queue.size;
204
- for (let e = 0; e < t; e++) {
184
+ let e = this.__queue.size;
185
+ for (let t = 0; t < e; t++) {
205
186
  const n = this.__queue.dequeue();
206
- let s = n.getParameters();
207
- if (s.solution = this.solution, s.experience_id = this.experienceID, n.customParameters && Object.assign(s, n.customParameters), JSON.stringify(s).length > 459)
208
- try {
209
- s = {
210
- epg_event_tag: await this.sendGA4LongParameters(s)
211
- };
212
- } catch {
213
- }
214
187
  try {
215
- this.__initializationMethod === "GTM" ? this.sendToGTM(n.eventName, s) : this.__initializationMethod === "GA4" && window.gtag("event", n.eventName, s), this.__sentEventCount++, this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${n.eventName}`);
216
- } catch (o) {
217
- this.logger(`Error sending event ${n.eventName}: ${o}`), this.__queue.enqueue(n);
188
+ 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);
189
+ } catch (i) {
190
+ this.logger(`Error sending event ${n.eventName}: ${i}`), this.__queue.enqueue(n);
218
191
  }
219
192
  }
220
193
  }
194
+ /**
195
+ * Send events to GTM based GA4
196
+ * @param event
197
+ * @private
198
+ */
199
+ async sendGTMEvent(e) {
200
+ let t = e.getGTMParameters(this.solution, this.experienceID, this.trackingID);
201
+ this.isValidPayload(t) || (t = await this.convertGTMParametersToEpgEventTag(e.eventName, t)), this.dataLayer && this.dataLayer.push(t);
202
+ }
203
+ /**
204
+ * Send events to GA4 via Google Analytics 4.
205
+ * @param event
206
+ * @private
207
+ */
208
+ async sendGA4Event(e) {
209
+ let t = e.getGa4Parameters(this.solution, this.experienceID, this.trackingID);
210
+ this.isValidPayload(t) || (t = await this.convertGA4ParametersToEpgEventTag(t)), window.gtag("event", e.eventName, t);
211
+ }
212
+ /**
213
+ * Validates a payload by checking its parameter count and the constraints of parameter names and values.
214
+ * See docs here for requirements: https://support.google.com/analytics/answer/9267744?hl=en
215
+ *
216
+ * @param {Record<string, unknown>} parameterPayload - An object containing the parameters to validate.
217
+ * The keys represent parameter names and the values represent parameter values.
218
+ * @return {boolean} Returns true if the payload meets the validation criteria; false otherwise.
219
+ */
220
+ isValidPayload(e) {
221
+ if (Object.keys(e).length >= 25)
222
+ return !1;
223
+ for (const [i, r] of Object.entries(e))
224
+ if (i !== "items" && (i.length > 40 || String(r).length > 100))
225
+ return !1;
226
+ return !0;
227
+ }
228
+ /**
229
+ * Converts the given GTM parameters to an EPG event tag, sending specific parameter payloads
230
+ * for processing and returning the formatted result. Falls back to the original payload in case of errors.
231
+ *
232
+ * @param {string} eventName - The event name associated with the EPG event tag being processed.
233
+ * @param {Record<string, unknown>} parameterPayload - A key-value pair object containing the parameters to be converted.
234
+ * @return {Promise<Record<string, unknown>>} A promise that resolves to an object containing the event name and the generated EPG event tag, or the original payload upon failure.
235
+ */
236
+ async convertGTMParametersToEpgEventTag(e, t) {
237
+ try {
238
+ let n = await this.sendGA4LongParameters(t);
239
+ return {
240
+ event: e,
241
+ epg_event_tag: n,
242
+ send_to: this.trackingID
243
+ };
244
+ } catch {
245
+ return t;
246
+ }
247
+ }
248
+ /**
249
+ * Converts GA4 parameters into an EPG event tag.
250
+ *
251
+ * @param {Record<string, unknown>} parameterPayload - The GA4 parameters to be converted.
252
+ * @return {Promise<Record<string, any>>} A promise resolving to an object containing the EPG event tag or the original payload if the conversion fails.
253
+ */
254
+ async convertGA4ParametersToEpgEventTag(e) {
255
+ try {
256
+ return {
257
+ epg_event_tag: await this.sendGA4LongParameters(e),
258
+ send_to: this.trackingID
259
+ };
260
+ } catch {
261
+ return e;
262
+ }
263
+ }
221
264
  /**
222
265
  * Checks if verboseLogging is enabled, then logs the error
223
266
  * @param err
224
267
  */
225
- logger(t) {
226
- this.verboseLogging && console.warn(t);
268
+ logger(e) {
269
+ this.verboseLogging && console.warn(e);
227
270
  }
228
- async sendGA4LongParameters(t) {
229
- const e = "https://api.myepigraph.com/api/analytics/ga4/custom", n = { parameters: t };
271
+ async sendGA4LongParameters(e) {
272
+ const t = "https://api.myepigraph.com/api/analytics/ga4/custom", n = { parameters: e };
230
273
  try {
231
- const s = await fetch(e, {
274
+ const i = await fetch(t, {
232
275
  method: "POST",
233
276
  // Assuming it's a POST request, adjust if necessary
234
277
  headers: {
@@ -237,26 +280,20 @@ class P {
237
280
  },
238
281
  body: JSON.stringify(n)
239
282
  });
240
- return s.ok ? (await s.json())?.id ?? "" : "";
283
+ return i.ok ? (await i.json())?.id ?? "" : "";
241
284
  } catch {
242
285
  return "";
243
286
  }
244
287
  }
245
- sendToGTM(t, e) {
246
- this.dataLayer && this.dataLayer.push({
247
- event: t,
248
- ...e
249
- });
250
- }
251
- async reportFailureToNexus(t, e) {
288
+ async reportFailureToNexus(e, t) {
252
289
  try {
253
290
  const n = {
254
291
  plugin: "GA4",
255
292
  trackingId: this.trackingID,
256
293
  solution: this.solution,
257
294
  experienceId: this.experienceID,
258
- failureType: t,
259
- errorMessage: e,
295
+ failureType: e,
296
+ errorMessage: t,
260
297
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
261
298
  url: window.location.href,
262
299
  userAgent: navigator.userAgent
@@ -266,39 +303,48 @@ class P {
266
303
  this.logger(`Error reporting failure to Nexus: ${n}`);
267
304
  }
268
305
  }
269
- findGA4ScriptInfo(t) {
270
- const e = document.querySelectorAll("script[src]");
271
- for (const n of e) {
272
- const s = n.getAttribute("src");
273
- if (s && s.includes(t)) {
274
- const r = new URL(s, location.href), o = Object.fromEntries(r.searchParams.entries());
306
+ findGA4Info(e) {
307
+ if (window.google_tag_manager && window.google_tag_manager[e]) {
308
+ const n = window.google_tag_manager[e];
309
+ if (n && n.dataLayerName)
310
+ return {
311
+ fullSrc: "",
312
+ id: e,
313
+ l: n.dataLayerName
314
+ };
315
+ }
316
+ const t = document.querySelectorAll("script[src]");
317
+ for (const n of t) {
318
+ const i = n.getAttribute("src");
319
+ if (i && i.includes(e)) {
320
+ const r = new URL(i, location.href), u = Object.fromEntries(r.searchParams.entries());
275
321
  return {
276
322
  fullSrc: r.href,
277
- id: o.id || void 0,
278
- l: o.l || void 0
323
+ id: u.id || void 0,
324
+ l: u.l || void 0
279
325
  };
280
326
  }
281
327
  }
282
328
  return null;
283
329
  }
284
330
  }
285
- class I {
331
+ class C {
286
332
  constructor({
287
- trackingID: t,
288
- experienceID: e,
333
+ trackingID: e,
334
+ experienceID: t,
289
335
  solution: n,
290
- sessionId: s,
336
+ sessionId: i,
291
337
  xPath: r,
292
- verboseLogging: o = !1,
338
+ verboseLogging: u = !1,
293
339
  sendToStaging: y = !1
294
340
  }) {
295
- this.__status = u.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 v(), this.url = y ? "https://nexus.epigraph.dev/api/analytics/event" : "https://api.myepigraph.com/api/analytics/event", this.__status = u.AVAILABLE;
341
+ this.__status = o.UNAVAILABLE, this.__sentEventCount = 0, this.sessionId = i, this.xPath = r, this.name = this.pluginName = "NEXUS-PLUGIN", this.trackingID = e, this.experienceID = t, this.solution = n, this.verboseLogging = u, this.__queue = new m(), this.url = y ? "https://nexus.epigraph.dev/api/analytics/event" : "https://api.myepigraph.com/api/analytics/event", this.__status = o.AVAILABLE;
296
342
  }
297
343
  getStatus() {
298
344
  return this.__status;
299
345
  }
300
- setStatus(t) {
301
- this.__status = t;
346
+ setStatus(e) {
347
+ this.__status = e;
302
348
  }
303
349
  getPendingEventCount() {
304
350
  return this.__queue.size;
@@ -314,22 +360,22 @@ class I {
314
360
  }
315
361
  setupPlugin() {
316
362
  }
317
- async sendEvent(t, e) {
318
- if (this.__queue.enqueue(t), !e) {
319
- this.__status = u.RESTRICTED;
363
+ async sendEvent(e, t) {
364
+ if (this.__queue.enqueue(e), !t) {
365
+ this.__status = o.RESTRICTED;
320
366
  return;
321
367
  }
322
368
  await this.dequeueAndSendEvents();
323
369
  }
324
370
  async dequeueAndSendEvents() {
325
- for (let t = 0; t < this.__queue.size; t++) {
326
- const e = this.__queue.dequeue();
327
- e.customParameters.solution = this.solution;
371
+ for (let e = 0; e < this.__queue.size; e++) {
372
+ const t = this.__queue.dequeue();
373
+ t.customParameters.solution = this.solution;
328
374
  const n = {
329
375
  trackingID: this.trackingID,
330
376
  experience_id: this.experienceID,
331
- action: e.eventName,
332
- parameters: e.getParameters()
377
+ action: t.eventName,
378
+ parameters: t.getNexusParameters()
333
379
  };
334
380
  try {
335
381
  return (await fetch(this.url, {
@@ -352,9 +398,9 @@ class I {
352
398
  return "";
353
399
  }
354
400
  }
355
- class N {
356
- constructor(t) {
357
- this.consentSet = !1, this.consent = !1, this.pluginName = "OneTrustConsentPlugin", this.consentIdentifier = t, this.consent = !1, this.addConsentChangedListener();
401
+ class A {
402
+ constructor(e) {
403
+ this.consentSet = !1, this.consent = !1, this.pluginName = "OneTrustConsentPlugin", this.consentIdentifier = e, this.consent = !1, this.addConsentChangedListener();
358
404
  }
359
405
  /**
360
406
  * Checks to see if the user has consented. If this is false, it will block all analytics
@@ -363,8 +409,8 @@ class N {
363
409
  if (this.consentSet)
364
410
  return this.consent;
365
411
  if (window.OnetrustActiveGroups !== void 0) {
366
- let t = window.OnetrustActiveGroups;
367
- t !== void 0 && t.split(",").forEach((n) => {
412
+ let e = window.OnetrustActiveGroups;
413
+ e !== void 0 && e.split(",").forEach((n) => {
368
414
  n === this.consentIdentifier && (this.consent = !0, this.consentSet = !0);
369
415
  });
370
416
  }
@@ -378,291 +424,310 @@ class N {
378
424
  });
379
425
  }
380
426
  }
381
- var E = /* @__PURE__ */ ((i) => (i.OneTrust = "onetrust", i))(E || {});
427
+ var E = /* @__PURE__ */ ((s) => (s.OneTrust = "onetrust", s))(E || {});
382
428
  class a {
383
429
  constructor({
384
- eventName: t,
385
- interactiveEvent: e,
430
+ eventName: e,
431
+ interactiveEvent: t,
386
432
  customParameters: n
387
433
  }) {
388
- this.eventName = t, this.interactiveEvent = e, this.customParameters = n;
434
+ this.eventName = e, this.interactiveEvent = t, this.customParameters = n;
435
+ }
436
+ getGa4Parameters(e, t, n) {
437
+ let i = {
438
+ solution: e,
439
+ experience_id: t,
440
+ interactive_event: this.interactiveEvent,
441
+ send_to: n
442
+ };
443
+ return i = Object.assign(i, JSON.parse(JSON.stringify(this.customParameters))), i;
444
+ }
445
+ getGTMParameters(e, t, n) {
446
+ let i = {
447
+ solution: e,
448
+ experience_id: t,
449
+ event: this.eventName,
450
+ interactive_event: this.interactiveEvent,
451
+ send_to: n
452
+ };
453
+ return i = Object.assign(i, JSON.parse(JSON.stringify(this.customParameters))), i;
389
454
  }
390
- getParameters() {
391
- let t = {
455
+ getNexusParameters() {
456
+ let e = {
392
457
  interactive_event: this.interactiveEvent
393
458
  };
394
- return t = Object.assign(t, JSON.parse(JSON.stringify(this.customParameters))), t;
459
+ return e = Object.assign(e, JSON.parse(JSON.stringify(this.customParameters))), e;
395
460
  }
396
461
  }
397
- class C extends a {
398
- constructor(t = []) {
462
+ class w extends a {
463
+ constructor(e = []) {
399
464
  super({
400
465
  eventName: "epigraph_ar_requested",
401
466
  interactiveEvent: !0,
402
467
  customParameters: {
403
- items: t
468
+ items: e
404
469
  }
405
470
  });
406
471
  }
407
472
  }
408
- class L extends a {
409
- constructor(t) {
473
+ class x extends a {
474
+ constructor(e) {
410
475
  super({
411
476
  eventName: "epigraph_module_loading",
412
477
  interactiveEvent: !1,
413
478
  customParameters: {
414
- is_pre_config: t
479
+ is_pre_config: e
415
480
  }
416
481
  });
417
482
  }
418
483
  }
419
484
  class S extends a {
420
- constructor(t, e) {
485
+ constructor(e, t) {
421
486
  super({
422
487
  eventName: "epigraph_module_ready",
423
488
  interactiveEvent: !1,
424
489
  customParameters: {
425
- is_pre_config: t,
426
- load_time_ms: e
490
+ is_pre_config: e,
491
+ load_time_ms: t
427
492
  }
428
493
  });
429
494
  }
430
495
  }
431
- class x extends a {
432
- constructor(t, e, n) {
496
+ class T extends a {
497
+ constructor(e, t, n) {
433
498
  super({
434
499
  eventName: "epigraph_module_failed",
435
500
  interactiveEvent: !1,
436
501
  customParameters: {
437
- is_pre_config: t,
438
- load_time_ms: e,
502
+ is_pre_config: e,
503
+ load_time_ms: t,
439
504
  error_type: n
440
505
  }
441
506
  });
442
507
  }
443
508
  }
444
- class T extends a {
445
- constructor(t = []) {
509
+ class L extends a {
510
+ constructor(e = []) {
446
511
  super({
447
512
  eventName: "epigraph_module_closed",
448
513
  interactiveEvent: !0,
449
514
  customParameters: {
450
- items: t
515
+ items: e
451
516
  }
452
517
  });
453
518
  }
454
519
  }
455
520
  class z extends a {
456
- constructor(t, e = {}) {
521
+ constructor(e, t = {}) {
457
522
  super({
458
523
  eventName: "epigraph_support_detected",
459
524
  interactiveEvent: !1,
460
525
  customParameters: {
461
- support_type: t,
462
- device_capabilities: e
526
+ support_type: e,
527
+ device_capabilities: t
463
528
  }
464
529
  });
465
530
  }
466
531
  }
467
532
  class q extends a {
468
- constructor(t, e) {
533
+ constructor(e, t) {
469
534
  super({
470
535
  eventName: "epigraph_button_click",
471
536
  interactiveEvent: !0,
472
537
  customParameters: {
473
- button_type: t,
474
- button_name: e
538
+ button_type: e,
539
+ button_name: t
475
540
  }
476
541
  });
477
542
  }
478
543
  }
479
- class D extends a {
480
- constructor(t = [], e, n, s) {
544
+ class O extends a {
545
+ constructor(e = [], t, n, i) {
481
546
  super({
482
547
  eventName: "epigraph_panel_opened",
483
- interactiveEvent: e,
548
+ interactiveEvent: t,
484
549
  customParameters: {
485
- items: t,
550
+ items: e,
486
551
  panel_type: n,
487
- trigger_source: s
552
+ trigger_source: i
488
553
  }
489
554
  });
490
555
  }
491
556
  }
492
557
  class G extends a {
493
- constructor(t = [], e, n, s) {
558
+ constructor(e = [], t, n, i) {
494
559
  super({
495
560
  eventName: "epigraph_panel_closed",
496
- interactiveEvent: e,
561
+ interactiveEvent: t,
497
562
  customParameters: {
498
- items: t,
563
+ items: e,
499
564
  panel_type: n,
500
- trigger_source: s
565
+ trigger_source: i
501
566
  }
502
567
  });
503
568
  }
504
569
  }
505
- class O extends a {
506
- constructor(t = []) {
570
+ class b extends a {
571
+ constructor(e = []) {
507
572
  super({
508
573
  eventName: "epigraph_add_to_favourites",
509
574
  interactiveEvent: !0,
510
575
  customParameters: {
511
- items: t
576
+ items: e
512
577
  }
513
578
  });
514
579
  }
515
580
  }
516
- class b extends a {
517
- constructor(t) {
581
+ class D extends a {
582
+ constructor(e) {
518
583
  super({
519
584
  eventName: "epigraph_keyboard_interaction",
520
585
  interactiveEvent: !0,
521
586
  customParameters: {
522
- action_performed: t
587
+ action_performed: e
523
588
  }
524
589
  });
525
590
  }
526
591
  }
527
- class R extends a {
528
- constructor(t) {
592
+ class M extends a {
593
+ constructor(e) {
529
594
  super({
530
595
  eventName: "epigraph_touch_interaction",
531
596
  interactiveEvent: !0,
532
597
  customParameters: {
533
- interaction_type: t
598
+ interaction_type: e
534
599
  }
535
600
  });
536
601
  }
537
602
  }
538
- class M extends a {
539
- constructor(t = [], e, n, s, r) {
603
+ class R extends a {
604
+ constructor(e = [], t, n, i, r) {
540
605
  super({
541
606
  eventName: "epigraph_item_added",
542
- interactiveEvent: e,
607
+ interactiveEvent: t,
543
608
  customParameters: {
544
- items: t,
609
+ items: e,
545
610
  value: n,
546
- currency: s,
611
+ currency: i,
547
612
  quantity: r
548
613
  }
549
614
  });
550
615
  }
551
616
  }
552
617
  class $ extends a {
553
- constructor(t = []) {
618
+ constructor(e = []) {
554
619
  super({
555
620
  eventName: "epigraph_item_moved",
556
621
  interactiveEvent: !0,
557
622
  customParameters: {
558
- items: t
623
+ items: e
559
624
  }
560
625
  });
561
626
  }
562
627
  }
563
628
  class k extends a {
564
- constructor(t = [], e, n, s) {
629
+ constructor(e = [], t, n, i) {
565
630
  super({
566
631
  eventName: "epigraph_item_removed",
567
632
  interactiveEvent: !0,
568
633
  customParameters: {
569
- items: t,
570
- value: e,
634
+ items: e,
635
+ value: t,
571
636
  currency: n,
572
- quantity: s
637
+ quantity: i
573
638
  }
574
639
  });
575
640
  }
576
641
  }
577
- class U extends a {
578
- constructor(t = [], e) {
642
+ class j extends a {
643
+ constructor(e = [], t) {
579
644
  super({
580
645
  eventName: "epigraph_variant_changed",
581
646
  interactiveEvent: !0,
582
647
  customParameters: {
583
- items: t,
584
- change_type: e
648
+ items: e,
649
+ change_type: t
585
650
  }
586
651
  });
587
652
  }
588
653
  }
589
- class j extends a {
590
- constructor(t = [], e, n) {
654
+ class U extends a {
655
+ constructor(e = [], t, n) {
591
656
  super({
592
657
  eventName: "epigraph_content_shared",
593
658
  interactiveEvent: !0,
594
659
  customParameters: {
595
- items: t,
596
- content_type: e,
660
+ items: e,
661
+ content_type: t,
597
662
  share_destination: n
598
663
  }
599
664
  });
600
665
  }
601
666
  }
602
- class F extends a {
603
- constructor(t = [], e, n) {
667
+ class V extends a {
668
+ constructor(e = [], t, n) {
604
669
  super({
605
670
  eventName: "epigraph_checkout",
606
671
  interactiveEvent: !0,
607
672
  customParameters: {
608
- items: t,
609
- value: e,
673
+ items: e,
674
+ value: t,
610
675
  currency: n
611
676
  }
612
677
  });
613
678
  }
614
679
  }
615
- class B extends a {
616
- constructor(t = [], e, n) {
680
+ class F extends a {
681
+ constructor(e = [], t, n) {
617
682
  super({
618
683
  eventName: "epigraph_conversion",
619
684
  interactiveEvent: !0,
620
685
  customParameters: {
621
- items: t,
622
- value: e,
686
+ items: e,
687
+ value: t,
623
688
  currency: n
624
689
  }
625
690
  });
626
691
  }
627
692
  }
628
- class V extends a {
629
- constructor(t) {
693
+ class B extends a {
694
+ constructor(e) {
630
695
  super({
631
696
  eventName: "epigraph_changeRate",
632
697
  interactiveEvent: !1,
633
698
  customParameters: {
634
- value: t
699
+ value: e
635
700
  }
636
701
  });
637
702
  }
638
703
  }
639
704
  class J extends a {
640
- constructor(t) {
705
+ constructor(e) {
641
706
  super({
642
707
  eventName: "epigraph_completionRate",
643
708
  interactiveEvent: !1,
644
709
  customParameters: {
645
- value: t
710
+ value: e
646
711
  }
647
712
  });
648
713
  }
649
714
  }
650
715
  class H extends a {
651
- constructor(t) {
716
+ constructor(e) {
652
717
  super({
653
718
  eventName: "epigraph_engagementRate",
654
719
  interactiveEvent: !1,
655
720
  customParameters: {
656
- value: t
721
+ value: e
657
722
  }
658
723
  });
659
724
  }
660
725
  }
661
- class X extends a {
662
- constructor(t, e, n) {
726
+ class K extends a {
727
+ constructor(e, t, n) {
663
728
  super({
664
- eventName: t,
665
- interactiveEvent: e,
729
+ eventName: e,
730
+ interactiveEvent: t,
666
731
  customParameters: n
667
732
  });
668
733
  }
@@ -686,15 +751,15 @@ class X extends a {
686
751
  var f;
687
752
  const c = Symbol("analyticsPluginsMap");
688
753
  f = c;
689
- class K {
690
- constructor(t, e) {
691
- this[f] = /* @__PURE__ */ new Map(), this.__consentPlugin = null, t && e && (this.__consentPlugin = this.buildConsentPlugin(t, e)), window.addEventListener("epigraphAnalyticsConsentChange", this.__onConsentChangeFromEvent);
754
+ class X {
755
+ constructor(e, t) {
756
+ this[f] = /* @__PURE__ */ new Map(), this.__consentPlugin = null, e && t && (this.__consentPlugin = this.buildConsentPlugin(e, t)), window.addEventListener("epigraphAnalyticsConsentChange", this.__onConsentChangeFromEvent);
692
757
  }
693
- __onConsentChangeFromEvent(t) {
694
- let e = t;
695
- this.__overrideConsent = e.detail.hasConsent;
758
+ __onConsentChangeFromEvent(e) {
759
+ let t = e;
760
+ this.__overrideConsent = t.detail.hasConsent;
696
761
  for (const n of this[c].values())
697
- this.__hasConsent() || n.setStatus(u.RESTRICTED);
762
+ this.__hasConsent() || n.setStatus(o.RESTRICTED);
698
763
  }
699
764
  /**
700
765
  * Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
@@ -703,11 +768,11 @@ class K {
703
768
  *
704
769
  * @param plugin
705
770
  */
706
- addEventPlugin(t) {
707
- this[c].has(t.getUniquePluginIdentifier()) || (this[c].set(
708
- t.getUniquePluginIdentifier(),
709
- t
710
- ), t.setupPlugin());
771
+ addEventPlugin(e) {
772
+ this[c].has(e.getUniquePluginIdentifier()) || (this[c].set(
773
+ e.getUniquePluginIdentifier(),
774
+ e
775
+ ), e.setupPlugin());
711
776
  }
712
777
  /**
713
778
  * Resolves session consent by prioritizing this._overrideConsent and if not found,
@@ -716,17 +781,17 @@ class K {
716
781
  * @returns {boolean} Whether the session has consent to track analytics or not.
717
782
  */
718
783
  __hasConsent() {
719
- let t = !0;
720
- return this.__overrideConsent !== void 0 ? (t = this.__overrideConsent, t) : (this.__consentPlugin && (t = this.__consentPlugin.hasConsent()), t);
784
+ let e = !0;
785
+ return this.__overrideConsent !== void 0 ? (e = this.__overrideConsent, e) : (this.__consentPlugin && (e = this.__consentPlugin.hasConsent()), e);
721
786
  }
722
787
  /**
723
788
  * Send an Event to all plugins
724
789
  *
725
790
  * @param eventData
726
791
  */
727
- sendEvent(t) {
728
- this[c].forEach((e) => {
729
- e.sendEvent(t, this.__hasConsent());
792
+ sendEvent(e) {
793
+ this[c].forEach((t) => {
794
+ t.sendEvent(e, this.__hasConsent());
730
795
  });
731
796
  }
732
797
  /**
@@ -735,37 +800,37 @@ class K {
735
800
  * @param consentIdentifier
736
801
  * @private
737
802
  */
738
- buildConsentPlugin(t, e) {
739
- return t.toLowerCase() === E.OneTrust.toLowerCase() ? new N(e) : null;
803
+ buildConsentPlugin(e, t) {
804
+ return e.toLowerCase() === E.OneTrust.toLowerCase() ? new A(t) : null;
740
805
  }
741
806
  }
742
807
  export {
743
808
  E as ConsentPluginNames,
744
- O as EpigraphAddToFavouritesEvent,
745
- K as EpigraphAnalytics,
746
- C as EpigraphArRequestedEvent,
809
+ b as EpigraphAddToFavouritesEvent,
810
+ X as EpigraphAnalytics,
811
+ w as EpigraphArRequestedEvent,
747
812
  q as EpigraphButtonClickEvent,
748
- V as EpigraphChangeRateEvent,
749
- F as EpigraphCheckoutEvent,
813
+ B as EpigraphChangeRateEvent,
814
+ V as EpigraphCheckoutEvent,
750
815
  J as EpigraphCompletionRateEvent,
751
- j as EpigraphContentSharedEvent,
752
- B as EpigraphConversionEvent,
753
- X as EpigraphCustomEvent,
816
+ U as EpigraphContentSharedEvent,
817
+ F as EpigraphConversionEvent,
818
+ K as EpigraphCustomEvent,
754
819
  H as EpigraphEngagementRateEvent,
755
- M as EpigraphItemAddedEvent,
820
+ R as EpigraphItemAddedEvent,
756
821
  $ as EpigraphItemMovedEvent,
757
822
  k as EpigraphItemRemovedEvent,
758
- b as EpigraphKeyboardInteractionEvent,
759
- T as EpigraphModuleClosedEvent,
760
- x as EpigraphModuleFailedEvent,
761
- L as EpigraphModuleLoadingEvent,
823
+ D as EpigraphKeyboardInteractionEvent,
824
+ L as EpigraphModuleClosedEvent,
825
+ T as EpigraphModuleFailedEvent,
826
+ x as EpigraphModuleLoadingEvent,
762
827
  S as EpigraphModuleReadyEvent,
763
828
  G as EpigraphPanelClosedEvent,
764
- D as EpigraphPanelOpenedEvent,
829
+ O as EpigraphPanelOpenedEvent,
765
830
  z as EpigraphSupportDetectedEvent,
766
- R as EpigraphTouchInteractionEvent,
767
- U as EpigraphVariantChangedEvent,
768
- P as GA4AnalyticsPlugin,
769
- I as NexusAnalyticsPlugin,
770
- N as OneTrustConsentPlugin
831
+ M as EpigraphTouchInteractionEvent,
832
+ j as EpigraphVariantChangedEvent,
833
+ I as GA4AnalyticsPlugin,
834
+ C as NexusAnalyticsPlugin,
835
+ A as OneTrustConsentPlugin
771
836
  };
@@ -8,7 +8,20 @@ declare class BaseAnalyticsEvent implements IAnalyticsEvent {
8
8
  interactiveEvent: boolean;
9
9
  customParameters: Record<string, unknown>;
10
10
  });
11
- getParameters(): {
11
+ getGa4Parameters(solution: string, experienceId: string, sendTo: string): {
12
+ solution: string;
13
+ experience_id: string;
14
+ interactive_event: boolean;
15
+ send_to: string;
16
+ };
17
+ getGTMParameters(solution: string, experienceId: string, sendTo: string): {
18
+ solution: string;
19
+ experience_id: string;
20
+ event: string;
21
+ interactive_event: boolean;
22
+ send_to: string;
23
+ };
24
+ getNexusParameters(): {
12
25
  interactive_event: boolean;
13
26
  };
14
27
  }
@@ -6,6 +6,7 @@ declare global {
6
6
  gtag?: (...args: any[]) => void;
7
7
  dataLayer?: Array<Record<string, any>>;
8
8
  epgDataLayerName?: string;
9
+ google_tag_manager: Record<string, any>;
9
10
  }
10
11
  }
11
12
  export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
@@ -16,7 +17,7 @@ export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
16
17
  experienceID: string;
17
18
  verboseLogging: boolean;
18
19
  dataLayer: Array<Record<string, any>> | undefined;
19
- dataLayerName: string;
20
+ dataLayerName: string | undefined;
20
21
  private __queue;
21
22
  private __status;
22
23
  private __sentEventCount;
@@ -46,26 +47,61 @@ export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
46
47
  /**
47
48
  * This function will send an Event to Google Analytics 4.
48
49
  *
49
- * @param eventData IAnalyticsEvent The event to be tracked
50
+ * @param analyticsEvent
50
51
  * @param consent boolean Whether consent is granted
51
52
  */
52
53
  sendEvent(analyticsEvent: IAnalyticsEvent, consent: boolean): Promise<void>;
53
54
  private initializePlugin;
54
55
  private detectAndSetupAnalytics;
55
56
  private detectGTM;
56
- private setupGA4;
57
57
  /**
58
58
  * Send all events that are in the queue
59
59
  * @private
60
60
  */
61
61
  private dequeueAndSendEvents;
62
+ /**
63
+ * Send events to GTM based GA4
64
+ * @param event
65
+ * @private
66
+ */
67
+ private sendGTMEvent;
68
+ /**
69
+ * Send events to GA4 via Google Analytics 4.
70
+ * @param event
71
+ * @private
72
+ */
73
+ private sendGA4Event;
74
+ /**
75
+ * Validates a payload by checking its parameter count and the constraints of parameter names and values.
76
+ * See docs here for requirements: https://support.google.com/analytics/answer/9267744?hl=en
77
+ *
78
+ * @param {Record<string, unknown>} parameterPayload - An object containing the parameters to validate.
79
+ * The keys represent parameter names and the values represent parameter values.
80
+ * @return {boolean} Returns true if the payload meets the validation criteria; false otherwise.
81
+ */
82
+ private isValidPayload;
83
+ /**
84
+ * Converts the given GTM parameters to an EPG event tag, sending specific parameter payloads
85
+ * for processing and returning the formatted result. Falls back to the original payload in case of errors.
86
+ *
87
+ * @param {string} eventName - The event name associated with the EPG event tag being processed.
88
+ * @param {Record<string, unknown>} parameterPayload - A key-value pair object containing the parameters to be converted.
89
+ * @return {Promise<Record<string, unknown>>} A promise that resolves to an object containing the event name and the generated EPG event tag, or the original payload upon failure.
90
+ */
91
+ private convertGTMParametersToEpgEventTag;
92
+ /**
93
+ * Converts GA4 parameters into an EPG event tag.
94
+ *
95
+ * @param {Record<string, unknown>} parameterPayload - The GA4 parameters to be converted.
96
+ * @return {Promise<Record<string, any>>} A promise resolving to an object containing the EPG event tag or the original payload if the conversion fails.
97
+ */
98
+ private convertGA4ParametersToEpgEventTag;
62
99
  /**
63
100
  * Checks if verboseLogging is enabled, then logs the error
64
101
  * @param err
65
102
  */
66
103
  private logger;
67
104
  private sendGA4LongParameters;
68
- private sendToGTM;
69
105
  private reportFailureToNexus;
70
- private findGA4ScriptInfo;
106
+ private findGA4Info;
71
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epigraph/epigraph-std-lib",
3
- "version": "4.5.3-alpha",
3
+ "version": "4.5.5-alpha",
4
4
  "type": "module",
5
5
  "main": "./dist/epigraph-std-lib.cjs",
6
6
  "module": "./dist/epigraph-std-lib.js",