@epigraph/epigraph-std-lib 4.5.1-alpha → 4.5.2-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/README.md CHANGED
@@ -1,68 +1,68 @@
1
- # INTRODUCTION
2
-
3
- Epigraph Standard Library or epigraph-std-lib is a collection of standards that we follow across our solutions. The idea is to have a single source of truth across solutions while ensuring that the dependencies are always up to date with the industry standards.
4
-
5
- ### EPIGRAPH
6
- A global object that must only be initialized once per session and provides some common functionalities across solutions in that session.
7
-
8
- ### EPIGRAPH LIBRARY EXPORTS
9
-
10
- | Name | Description |
11
- |---|---|
12
- | EpigraphBaseSolutionHtmlElement | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
13
- | EpigraphBaseSolutionLitElement | A base class intended to enforce some common functionalities across our solutions, built by extending the LitElement |
14
- | EpigraphLogger | A logger class that provides a convenient way for logging info, warning or errors in any given session |
15
- | EpigraphQrCoreGenerator | A Utility class that allows the generation of a QR code from a give string input |
16
- | EpigraphUnitsConverter | |
17
- | EpigraphUrlProcessor | |
18
-
19
-
20
- # HOW TO:
21
-
22
- ### Add a new EpigraphLibrary:
23
- 1. Create a new directory under lib/EpigraphLibs/`<MyEpigraphLibrary>`
24
- 2. Create the module file/s. Ensure that the names of these files are in camelCase.
25
- 3. Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
26
- 4. Add the module that you wish to export as an entry in vite.config.ts > defineConfig > build > entry, similar to other entries in there. This will bundle the new module on build.
27
- 5. Go to package.json:
28
- - Add the new module entry under exports similar to other entries in that field.
29
- - Add the new module entry under typesVersions similar to other entries in that field.
30
-
31
- ### Use the library
32
- This library exports the module into submodules to allow for better tree shaking when bundling the final product. Here is how you can import the submodules individually.
33
-
34
- ```javascript
35
- // Epigraph Object
36
- import { Epigraph } from "@epigraph/epigraph-std-lib/dist/Epigraph/epigraph";
37
-
38
- // Epigraph libs
39
- import { EpigraphAnalytics } from "@epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics";
40
-
41
- ```
42
-
43
- Exported Submodules:
44
- | Name | Description |
45
- |---|---|
46
- | @epigraph/epigraph-std-lib/dist/Epigraph/epigraph | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
47
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics | An Analytics modules that exports handy ways to log analytics across our solutions |
48
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphLogger | A Logger modules that exports handy ways to log across our solutions |
49
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphNexusApi | A Nexus API modules that exports handy ways to interact with the Nexus API across our solutions |
50
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphQrCodeGenerator | A QR Code generator modules that exports handy ways to generate QR Codes across our solutions |
51
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphResultFactory | A Result Factory modules that exports handy ways to generate Result objects across our solutions |
52
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUnitsConverter | A Utility class that allows conversion between different standard unit, including but not limited to Distance, Color, etc. |
53
- | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
54
-
55
-
56
- ### Write a test:
57
- We use [vitest](https://vitest.dev/guide/) to write tests in this repository using [happy-dom](https://www.npmjs.com/package/happy-dom) to support some but not all browser functionalities. In order to write a new test:
58
-
59
- 1. Create a new file for a specific test under tests/ as `<MyEpigraphLibrary>`.test.ts
60
- 2. Write a test following the instructions and samples [here](https://vitest.dev/guide/#writing-tests)
61
- 3. Make sure to import the library from "../dist/epigraph-std-lib" to avoid any issues that might come up after bundling.
62
- 4. Open a terminal and execute "npm run test". This will build all the libraries under dist/ and then run tests using those.
63
-
64
-
65
- # REFERENCES
66
- A huge thanks to everyone who inspired the setup for this repository:
67
- 1. [Andreas Riedmuller's Article](https://dev.to/receter/how-to-create-a-react-component-library-using-vites-library-mode-4lma)
68
- 2. [Vitest Docs](https://vitest.dev/guide/)
1
+ # INTRODUCTION
2
+
3
+ Epigraph Standard Library or epigraph-std-lib is a collection of standards that we follow across our solutions. The idea is to have a single source of truth across solutions while ensuring that the dependencies are always up to date with the industry standards.
4
+
5
+ ### EPIGRAPH
6
+ A global object that must only be initialized once per session and provides some common functionalities across solutions in that session.
7
+
8
+ ### EPIGRAPH LIBRARY EXPORTS
9
+
10
+ | Name | Description |
11
+ |---|---|
12
+ | EpigraphBaseSolutionHtmlElement | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
13
+ | EpigraphBaseSolutionLitElement | A base class intended to enforce some common functionalities across our solutions, built by extending the LitElement |
14
+ | EpigraphLogger | A logger class that provides a convenient way for logging info, warning or errors in any given session |
15
+ | EpigraphQrCoreGenerator | A Utility class that allows the generation of a QR code from a give string input |
16
+ | EpigraphUnitsConverter | |
17
+ | EpigraphUrlProcessor | |
18
+
19
+
20
+ # HOW TO:
21
+
22
+ ### Add a new EpigraphLibrary:
23
+ 1. Create a new directory under lib/EpigraphLibs/`<MyEpigraphLibrary>`
24
+ 2. Create the module file/s. Ensure that the names of these files are in camelCase.
25
+ 3. Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
26
+ 4. Add the module that you wish to export as an entry in vite.config.ts > defineConfig > build > entry, similar to other entries in there. This will bundle the new module on build.
27
+ 5. Go to package.json:
28
+ - Add the new module entry under exports similar to other entries in that field.
29
+ - Add the new module entry under typesVersions similar to other entries in that field.
30
+
31
+ ### Use the library
32
+ This library exports the module into submodules to allow for better tree shaking when bundling the final product. Here is how you can import the submodules individually.
33
+
34
+ ```javascript
35
+ // Epigraph Object
36
+ import { Epigraph } from "@epigraph/epigraph-std-lib/dist/Epigraph/epigraph";
37
+
38
+ // Epigraph libs
39
+ import { EpigraphAnalytics } from "@epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics";
40
+
41
+ ```
42
+
43
+ Exported Submodules:
44
+ | Name | Description |
45
+ |---|---|
46
+ | @epigraph/epigraph-std-lib/dist/Epigraph/epigraph | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
47
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics | An Analytics modules that exports handy ways to log analytics across our solutions |
48
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphLogger | A Logger modules that exports handy ways to log across our solutions |
49
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphNexusApi | A Nexus API modules that exports handy ways to interact with the Nexus API across our solutions |
50
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphQrCodeGenerator | A QR Code generator modules that exports handy ways to generate QR Codes across our solutions |
51
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphResultFactory | A Result Factory modules that exports handy ways to generate Result objects across our solutions |
52
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUnitsConverter | A Utility class that allows conversion between different standard unit, including but not limited to Distance, Color, etc. |
53
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
54
+
55
+
56
+ ### Write a test:
57
+ We use [vitest](https://vitest.dev/guide/) to write tests in this repository using [happy-dom](https://www.npmjs.com/package/happy-dom) to support some but not all browser functionalities. In order to write a new test:
58
+
59
+ 1. Create a new file for a specific test under tests/ as `<MyEpigraphLibrary>`.test.ts
60
+ 2. Write a test following the instructions and samples [here](https://vitest.dev/guide/#writing-tests)
61
+ 3. Make sure to import the library from "../dist/epigraph-std-lib" to avoid any issues that might come up after bundling.
62
+ 4. Open a terminal and execute "npm run test". This will build all the libraries under dist/ and then run tests using those.
63
+
64
+
65
+ # REFERENCES
66
+ A huge thanks to everyone who inspired the setup for this repository:
67
+ 1. [Andreas Riedmuller's Article](https://dev.to/receter/how-to-create-a-react-component-library-using-vites-library-mode-4lma)
68
+ 2. [Vitest Docs](https://vitest.dev/guide/)
@@ -1,4 +1,4 @@
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 l=Symbol("data"),p=Symbol("next"),C=class m{constructor(e){this[l]=e,this[p]=null}get data(){return this[l]}set next(e){if(!(e instanceof m)&&e!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[p]=e}get next(){return this[p]}};let v=C;const d=Symbol("head");class w{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 E=Symbol("queue"),h=Symbol("size");class _{constructor(){this[E]=new w,this[h]=0}get queue(){return this[E]}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:r=!1}){this.__status=o.UNAVAILABLE,this.__sentEventCount=0,this.name=this.pluginName="GA4-PLUGIN",this.trackingID=e,this.experienceID=t,this.solution=n,this.verboseLogging=r,this.__queue=new _,this.dataLayer=window.dataLayer,this.dataLayerName="dataLayer",this.setupDataLayer(),this.initGtag(this.dataLayerName,this.trackingID)}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.dataLayer!==void 0&&this.dequeueAndSendEvents()}async sendEvent(e,t){if(this.__queue.enqueue(e),!t){this.__status=o.RESTRICTED;return}if(this.dataLayer!==void 0)try{await this.dequeueAndSendEvents()}catch(n){this.logger(n)}else this.logger("Cannot send Google Analytics 4 event: dataLayer is not defined.")}setupDataLayer(){if(this.dataLayer){this.__status=o.AVAILABLE;return}const t=this.findGA4ScriptInfo(this.trackingID)?.l;t&&(this.dataLayerName=t,this.dataLayer=window[t])}initGtag(e="dataLayer",t){window.epgDataLayerName=e,typeof window.gtag!="function"&&(window.gtag=function(){window[window.epgDataLayerName].push(arguments)},window.gtag("js",new Date),window.gtag("config",t,{send_page_view:!1}))}async dequeueAndSendEvents(){let e=this.__queue.size;for(let t=0;t<e;t++){const n=this.__queue.dequeue(),r=n.getGa4Parameters(this.solution,this.experienceID);if(n.customParameters&&Object.assign(r,n.customParameters),JSON.stringify(r).length>459)try{let u=await this.sendGA4LongParameters(r);r.epg_event_tag=u}catch{}gtag("event",n.eventName,r),this.__sentEventCount++,this.logger(`Google Analytics 4 event successfully sent: ${n.eventName}`)}}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 r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});if(r.ok){const i=await r.json();return i&&i.id?i.id:""}else return""}catch{return""}}findGA4ScriptInfo(e){const t=document.querySelectorAll("script[src]");for(const n of t){const r=n.getAttribute("src");if(r&&r.includes(e)){const i=new URL(r,location.href),u=Object.fromEntries(i.searchParams.entries());return{fullSrc:i.href,id:u.id||void 0,l:u.l||void 0}}}return null}}class S{constructor({trackingID:e,experienceID:t,solution:n,sessionId:r,xPath:i,verboseLogging:u=!1,sendToStaging:P=!1}){this.__status=o.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=r,this.xPath=i,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=e,this.experienceID=t,this.solution=n,this.verboseLogging=u,this.__queue=new _,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 g=(s=>(s.OneTrust="onetrust",s))(g||{});class a{constructor({eventName:e,interactiveEvent:t,customParameters:n}){this.eventName=e,this.interactiveEvent=t,this.customParameters=n}getGa4Parameters(e,t){let n={solution:e,experience_id:t,interactive_event:this.interactiveEvent,items:[],epg_event_tag:""};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getGTMParameters(){return{}}getNexusParameters(){let e={interactive_event:this.interactiveEvent,items:[]};return e=Object.assign(e,JSON.parse(JSON.stringify(this.customParameters))),e}}class A extends a{constructor(e){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:e}})}}class L extends a{constructor(e,t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t}})}}class I extends a{constructor(e,t,n){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t,load_time_ms:n}})}}class x extends a{constructor(e,t,n,r){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t,load_time_ms:n,error_type:r}})}}class q extends a{constructor(e){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:e}})}}class T extends a{constructor(e,t,n){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{items:e,support_type:t,device_capabilities:n}})}}class b extends a{constructor(e,t,n){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{items:e,button_type:t,button_name:n}})}}class O extends a{constructor(e,t,n,r){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:r}})}}class R extends a{constructor(e,t,n,r){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:r}})}}class D extends a{constructor(e){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:e}})}}class G extends a{constructor(e,t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{items:e,action_performed:t}})}}class k extends a{constructor(e,t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{items:e,interaction_type:t}})}}class M extends a{constructor(e,t,n,r,i){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:e,value:n,currency:r,quantity:i}})}}class j extends a{constructor(e){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:e}})}}class B extends a{constructor(e,t,n){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:e,currency:t,quantity:n}})}}class U extends a{constructor(e,t){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class $ extends a{constructor(e,t,n){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:e,content_type:t,share_destination:n}})}}class z extends a{constructor(e,t,n){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class V extends a{constructor(e,t,n){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:e,value:t,currency:n}})}}class J extends a{constructor(e,t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}class F extends a{constructor(e,t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}class H extends a{constructor(e,t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}/**
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 v=w;const p=Symbol("head");class N{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 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 P{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(),s=n.getGa4Parameters(this.solution,this.experienceID);if(n.customParameters&&Object.assign(s,n.customParameters),JSON.stringify(s).length>459)try{let o=await this.sendGA4LongParameters(s);s.epg_event_tag=o}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.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 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}getGa4Parameters(e,t){let n={solution:e,experience_id:t,interactive_event:this.interactiveEvent,items:[],epg_event_tag:""};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getGTMParameters(){return{}}getNexusParameters(){let e={interactive_event:this.interactiveEvent,items:[]};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 S extends a{constructor(e=[],t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t}})}}class L extends a{constructor(e=[],t,n){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t,load_time_ms:n}})}}class x extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{items:e,is_pre_config:t,load_time_ms:n,error_type:s}})}}class T extends a{constructor(e=[]){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:e}})}}class q extends a{constructor(e=[],t,n={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{items:e,support_type:t,device_capabilities:n}})}}class z extends a{constructor(e=[],t,n){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{items:e,button_type:t,button_name:n}})}}class O extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:s}})}}class G extends a{constructor(e=[],t,n,s){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:e,panel_type:n,trigger_source:s}})}}class R extends a{constructor(e=[]){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:e}})}}class b extends a{constructor(e=[],t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{items:e,action_performed:t}})}}class D extends a{constructor(e=[],t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{items:e,interaction_type:t}})}}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){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:e,currency:t,quantity:n}})}}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 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=[],t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}class J extends a{constructor(e=[],t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}class H extends a{constructor(e=[],t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{items:e,value:t}})}}class X 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(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()===g.OneTrust.toLowerCase()?new f(t):null}}exports.ConsentPluginNames=g;exports.EpigraphAddToFavouritesEvent=D;exports.EpigraphAnalytics=K;exports.EpigraphArRequestedEvent=A;exports.EpigraphButtonClickEvent=b;exports.EpigraphChangeRateEvent=J;exports.EpigraphCheckoutEvent=z;exports.EpigraphCompletionRateEvent=F;exports.EpigraphContentSharedEvent=$;exports.EpigraphConversionEvent=V;exports.EpigraphEngagementRateEvent=H;exports.EpigraphItemAddedEvent=M;exports.EpigraphItemMovedEvent=j;exports.EpigraphItemRemovedEvent=B;exports.EpigraphKeyboardInteractionEvent=G;exports.EpigraphModuleClosedEvent=q;exports.EpigraphModuleFailedEvent=x;exports.EpigraphModuleLoadingEvent=L;exports.EpigraphModuleReadyEvent=I;exports.EpigraphPanelClosedEvent=R;exports.EpigraphPanelOpenedEvent=O;exports.EpigraphSupportDetectedEvent=T;exports.EpigraphTouchInteractionEvent=k;exports.EpigraphVariantChangedEvent=U;exports.GA4AnalyticsPlugin=N;exports.NexusAnalyticsPlugin=S;exports.OneTrustConsentPlugin=f;
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=R;exports.EpigraphAnalytics=K;exports.EpigraphArRequestedEvent=I;exports.EpigraphButtonClickEvent=z;exports.EpigraphChangeRateEvent=V;exports.EpigraphCheckoutEvent=U;exports.EpigraphCompletionRateEvent=J;exports.EpigraphContentSharedEvent=F;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=S;exports.EpigraphModuleReadyEvent=L;exports.EpigraphPanelClosedEvent=G;exports.EpigraphPanelOpenedEvent=O;exports.EpigraphSupportDetectedEvent=q;exports.EpigraphTouchInteractionEvent=D;exports.EpigraphVariantChangedEvent=j;exports.GA4AnalyticsPlugin=P;exports.NexusAnalyticsPlugin=C;exports.OneTrustConsentPlugin=f;
@@ -1,10 +1,10 @@
1
- var o = /* @__PURE__ */ ((s) => (s.UNAVAILABLE = "unavailable", s.AVAILABLE = "available", s.RESTRICTED = "restricted", s))(o || {});
2
- const l = Symbol("data"), d = Symbol("next"), P = class m {
1
+ var u = /* @__PURE__ */ ((s) => (s.UNAVAILABLE = "unavailable", s.AVAILABLE = "available", s.RESTRICTED = "restricted", s))(u || {});
2
+ const p = Symbol("data"), d = Symbol("next"), w = class m {
3
3
  constructor(e) {
4
- this[l] = e, this[d] = null;
4
+ this[p] = e, this[d] = null;
5
5
  }
6
6
  get data() {
7
- return this[l];
7
+ return this[p];
8
8
  }
9
9
  set next(e) {
10
10
  if (!(e instanceof m) && e !== null)
@@ -17,17 +17,17 @@ const l = Symbol("data"), d = Symbol("next"), P = class m {
17
17
  return this[d];
18
18
  }
19
19
  };
20
- let g = P;
21
- const p = Symbol("head");
22
- class C {
20
+ let g = w;
21
+ const l = Symbol("head");
22
+ class A {
23
23
  constructor() {
24
- this[p] = null;
24
+ this[l] = null;
25
25
  }
26
26
  set head(e) {
27
- this[p] = e;
27
+ this[l] = e;
28
28
  }
29
29
  get head() {
30
- return this[p];
30
+ return this[l];
31
31
  }
32
32
  addToTail(e) {
33
33
  let t = this.head;
@@ -44,13 +44,13 @@ class C {
44
44
  return this.head = e.next, e.data;
45
45
  }
46
46
  }
47
- const v = Symbol("queue"), h = Symbol("size");
48
- class _ {
47
+ const _ = Symbol("queue"), h = Symbol("size");
48
+ class v {
49
49
  constructor() {
50
- this[v] = new C(), this[h] = 0;
50
+ this[_] = new A(), this[h] = 0;
51
51
  }
52
52
  get queue() {
53
- return this[v];
53
+ return this[_];
54
54
  }
55
55
  get size() {
56
56
  return this[h];
@@ -63,14 +63,14 @@ class _ {
63
63
  return this[h]--, e;
64
64
  }
65
65
  }
66
- class N {
66
+ class P {
67
67
  constructor({
68
68
  trackingID: e,
69
69
  experienceID: t,
70
70
  solution: n,
71
- verboseLogging: r = !1
71
+ verboseLogging: i = !1
72
72
  }) {
73
- this.__status = o.UNAVAILABLE, this.__sentEventCount = 0, this.name = this.pluginName = "GA4-PLUGIN", this.trackingID = e, this.experienceID = t, this.solution = n, this.verboseLogging = r, this.__queue = new _(), this.dataLayer = window.dataLayer, this.dataLayerName = "dataLayer", this.setupDataLayer(), this.initGtag(this.dataLayerName, this.trackingID);
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 = e, this.experienceID = t, this.solution = n, this.verboseLogging = i, this.__queue = new v(), this.initializePlugin();
74
74
  }
75
75
  getStatus() {
76
76
  return this.__status;
@@ -94,56 +94,126 @@ class N {
94
94
  return `${this.name}-${this.trackingID}`;
95
95
  }
96
96
  setupPlugin() {
97
- this.dataLayer !== void 0 && this.dequeueAndSendEvents();
97
+ this.__isInitialized && this.dataLayer !== void 0 && this.dequeueAndSendEvents();
98
98
  }
99
99
  /**
100
100
  * This function will send an Event to Google Analytics 4.
101
101
  *
102
102
  * @param eventData IAnalyticsEvent The event to be tracked
103
- * @param consentPlugin
103
+ * @param consent boolean Whether consent is granted
104
104
  */
105
105
  async sendEvent(e, t) {
106
106
  if (this.__queue.enqueue(e), !t) {
107
- this.__status = o.RESTRICTED;
107
+ this.__status = u.RESTRICTED;
108
108
  return;
109
109
  }
110
- if (this.dataLayer !== void 0)
111
- try {
112
- await this.dequeueAndSendEvents();
113
- } catch (n) {
114
- this.logger(n);
115
- }
116
- else
117
- this.logger("Cannot send Google Analytics 4 event: dataLayer is not defined.");
110
+ if (!this.__isInitialized) {
111
+ this.logger("Cannot send analytics event: dataLayer not defined or plugin not initialized.");
112
+ return;
113
+ }
114
+ try {
115
+ await this.dequeueAndSendEvents();
116
+ } catch (n) {
117
+ this.logger(n), await this.reportFailureToNexus("EVENT_SEND_ERROR", n?.toString() || "Unknown error");
118
+ }
118
119
  }
119
- setupDataLayer() {
120
- if (this.dataLayer) {
121
- this.__status = o.AVAILABLE;
120
+ async initializePlugin() {
121
+ if (this.__isInitialized)
122
+ return;
123
+ const e = Date.now();
124
+ if (this.__initializationAttempts >= this.__maxInitializationAttempts) {
125
+ this.__nexusFailureReported || (await this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS", "Maximum initialization attempts reached"), this.__nexusFailureReported = !0);
126
+ return;
127
+ }
128
+ if (e - this.__lastInitializationAttempt < this.__initializationRetryDelay)
122
129
  return;
130
+ this.__lastInitializationAttempt = e, this.__initializationAttempts++;
131
+ const t = await this.detectAndSetupAnalytics();
132
+ 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));
133
+ }
134
+ async detectAndSetupAnalytics() {
135
+ const e = this.detectGTM();
136
+ if (e)
137
+ return this.logger(`GTM detected with container ID: ${e.containerId}`), {
138
+ success: !0,
139
+ method: "GTM",
140
+ dataLayerName: e.dataLayerName
141
+ };
142
+ if (window.dataLayer)
143
+ return this.logger("Existing dataLayer found"), {
144
+ success: !0,
145
+ method: "GA4",
146
+ dataLayerName: "dataLayer"
147
+ };
148
+ const t = this.findGA4ScriptInfo(this.trackingID);
149
+ if (t) {
150
+ const n = t.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
+ }
158
+ return this.setupGA4("dataLayer") ? {
159
+ success: !0,
160
+ method: "GA4",
161
+ dataLayerName: "dataLayer"
162
+ } : {
163
+ success: !1,
164
+ method: "NONE",
165
+ dataLayerName: "dataLayer",
166
+ error: "No analytics setup found and unable to create one"
167
+ };
168
+ }
169
+ detectGTM() {
170
+ const e = document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');
171
+ for (const t of Array.from(e)) {
172
+ const n = t.getAttribute("src");
173
+ if (n) {
174
+ const i = n.match(/gtm\.js\?id=([^&]+)/);
175
+ if (i) {
176
+ const r = n.match(/&l=([^&]+)/), o = r ? r[1] : "dataLayer";
177
+ return {
178
+ containerId: i[1],
179
+ dataLayerName: o
180
+ };
181
+ }
182
+ }
123
183
  }
124
- const t = this.findGA4ScriptInfo(this.trackingID)?.l;
125
- t && (this.dataLayerName = t, this.dataLayer = window[t]);
184
+ return null;
126
185
  }
127
- initGtag(e = "dataLayer", t) {
128
- window.epgDataLayerName = e, typeof window.gtag != "function" && (window.gtag = function() {
129
- window[window.epgDataLayerName].push(arguments);
130
- }, window.gtag("js", /* @__PURE__ */ new Date()), window.gtag("config", t, { send_page_view: !1 }));
186
+ setupGA4(e) {
187
+ try {
188
+ return window[e] || (window[e] = []), window.epgDataLayerName = e, typeof window.gtag != "function" && (window.gtag = function() {
189
+ const t = window.epgDataLayerName;
190
+ t && window[t] && Array.isArray(window[t]) && window[t].push(arguments);
191
+ }, window.gtag("js", /* @__PURE__ */ new Date()), window.gtag("config", this.trackingID, { send_page_view: !1 })), !0;
192
+ } catch (t) {
193
+ return this.logger(`Error setting up GA4: ${t}`), !1;
194
+ }
131
195
  }
132
196
  /**
133
197
  * Send all events that are in the queue
134
198
  * @private
135
199
  */
136
200
  async dequeueAndSendEvents() {
201
+ if (!this.__isInitialized || !this.dataLayer)
202
+ return;
137
203
  let e = this.__queue.size;
138
204
  for (let t = 0; t < e; t++) {
139
- const n = this.__queue.dequeue(), r = n.getGa4Parameters(this.solution, this.experienceID);
140
- if (n.customParameters && Object.assign(r, n.customParameters), JSON.stringify(r).length > 459)
205
+ const n = this.__queue.dequeue(), i = n.getGa4Parameters(this.solution, this.experienceID);
206
+ if (n.customParameters && Object.assign(i, n.customParameters), JSON.stringify(i).length > 459)
141
207
  try {
142
- let u = await this.sendGA4LongParameters(r);
143
- r.epg_event_tag = u;
208
+ let o = await this.sendGA4LongParameters(i);
209
+ i.epg_event_tag = o;
144
210
  } catch {
145
211
  }
146
- gtag("event", n.eventName, r), this.__sentEventCount++, this.logger(`Google Analytics 4 event successfully sent: ${n.eventName}`);
212
+ try {
213
+ this.__initializationMethod === "GTM" ? this.sendToGTM(n.eventName, i) : this.__initializationMethod === "GA4" && window.gtag("event", n.eventName, i), this.__sentEventCount++, this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${n.eventName}`);
214
+ } catch (o) {
215
+ this.logger(`Error sending event ${n.eventName}: ${o}`), this.__queue.enqueue(n);
216
+ }
147
217
  }
148
218
  }
149
219
  /**
@@ -154,11 +224,9 @@ class N {
154
224
  this.verboseLogging && console.warn(e);
155
225
  }
156
226
  async sendGA4LongParameters(e) {
157
- const t = "https://api.myepigraph.com/api/analytics/ga4/custom", n = {
158
- parameters: e
159
- };
227
+ const t = "https://api.myepigraph.com/api/analytics/ga4/custom", n = { parameters: e };
160
228
  try {
161
- const r = await fetch(t, {
229
+ const i = await fetch(t, {
162
230
  method: "POST",
163
231
  // Assuming it's a POST request, adjust if necessary
164
232
  headers: {
@@ -167,42 +235,62 @@ class N {
167
235
  },
168
236
  body: JSON.stringify(n)
169
237
  });
170
- if (r.ok) {
171
- const i = await r.json();
172
- return i && i.id ? i.id : "";
173
- } else
174
- return "";
238
+ return i.ok ? (await i.json())?.id ?? "" : "";
175
239
  } catch {
176
240
  return "";
177
241
  }
178
242
  }
243
+ sendToGTM(e, t) {
244
+ this.dataLayer && this.dataLayer.push({
245
+ event: e,
246
+ ...t
247
+ });
248
+ }
249
+ async reportFailureToNexus(e, t) {
250
+ try {
251
+ const n = {
252
+ plugin: "GA4",
253
+ trackingId: this.trackingID,
254
+ solution: this.solution,
255
+ experienceId: this.experienceID,
256
+ failureType: e,
257
+ errorMessage: t,
258
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
259
+ url: window.location.href,
260
+ userAgent: navigator.userAgent
261
+ };
262
+ this.logger(`Failure reported to Nexus: ${JSON.stringify(n)}`);
263
+ } catch (n) {
264
+ this.logger(`Error reporting failure to Nexus: ${n}`);
265
+ }
266
+ }
179
267
  findGA4ScriptInfo(e) {
180
268
  const t = document.querySelectorAll("script[src]");
181
269
  for (const n of t) {
182
- const r = n.getAttribute("src");
183
- if (r && r.includes(e)) {
184
- const i = new URL(r, location.href), u = Object.fromEntries(i.searchParams.entries());
270
+ const i = n.getAttribute("src");
271
+ if (i && i.includes(e)) {
272
+ const r = new URL(i, location.href), o = Object.fromEntries(r.searchParams.entries());
185
273
  return {
186
- fullSrc: i.href,
187
- id: u.id || void 0,
188
- l: u.l || void 0
274
+ fullSrc: r.href,
275
+ id: o.id || void 0,
276
+ l: o.l || void 0
189
277
  };
190
278
  }
191
279
  }
192
280
  return null;
193
281
  }
194
282
  }
195
- class S {
283
+ class I {
196
284
  constructor({
197
285
  trackingID: e,
198
286
  experienceID: t,
199
287
  solution: n,
200
- sessionId: r,
201
- xPath: i,
202
- verboseLogging: u = !1,
288
+ sessionId: i,
289
+ xPath: r,
290
+ verboseLogging: o = !1,
203
291
  sendToStaging: y = !1
204
292
  }) {
205
- this.__status = o.UNAVAILABLE, this.__sentEventCount = 0, this.sessionId = r, this.xPath = i, this.name = this.pluginName = "NEXUS-PLUGIN", this.trackingID = e, this.experienceID = t, this.solution = n, this.verboseLogging = u, this.__queue = new _(), this.url = y ? "https://nexus.epigraph.dev/api/analytics/event" : "https://api.myepigraph.com/api/analytics/event", this.__status = o.AVAILABLE;
293
+ this.__status = u.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 = 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;
206
294
  }
207
295
  getStatus() {
208
296
  return this.__status;
@@ -226,7 +314,7 @@ class S {
226
314
  }
227
315
  async sendEvent(e, t) {
228
316
  if (this.__queue.enqueue(e), !t) {
229
- this.__status = o.RESTRICTED;
317
+ this.__status = u.RESTRICTED;
230
318
  return;
231
319
  }
232
320
  await this.dequeueAndSendEvents();
@@ -262,7 +350,7 @@ class S {
262
350
  return "";
263
351
  }
264
352
  }
265
- class w {
353
+ class N {
266
354
  constructor(e) {
267
355
  this.consentSet = !1, this.consent = !1, this.pluginName = "OneTrustConsentPlugin", this.consentIdentifier = e, this.consent = !1, this.addConsentChangedListener();
268
356
  }
@@ -318,8 +406,8 @@ class a {
318
406
  return e = Object.assign(e, JSON.parse(JSON.stringify(this.customParameters))), e;
319
407
  }
320
408
  }
321
- class L extends a {
322
- constructor(e) {
409
+ class C extends a {
410
+ constructor(e = []) {
323
411
  super({
324
412
  eventName: "epigraph_ar_requested",
325
413
  interactiveEvent: !0,
@@ -329,8 +417,8 @@ class L extends a {
329
417
  });
330
418
  }
331
419
  }
332
- class A extends a {
333
- constructor(e, t) {
420
+ class L extends a {
421
+ constructor(e = [], t) {
334
422
  super({
335
423
  eventName: "epigraph_module_loading",
336
424
  interactiveEvent: !1,
@@ -341,8 +429,8 @@ class A extends a {
341
429
  });
342
430
  }
343
431
  }
344
- class x extends a {
345
- constructor(e, t, n) {
432
+ class S extends a {
433
+ constructor(e = [], t, n) {
346
434
  super({
347
435
  eventName: "epigraph_module_ready",
348
436
  interactiveEvent: !1,
@@ -354,8 +442,8 @@ class x extends a {
354
442
  });
355
443
  }
356
444
  }
357
- class I extends a {
358
- constructor(e, t, n, r) {
445
+ class x extends a {
446
+ constructor(e = [], t, n, i) {
359
447
  super({
360
448
  eventName: "epigraph_module_failed",
361
449
  interactiveEvent: !1,
@@ -363,13 +451,13 @@ class I extends a {
363
451
  items: e,
364
452
  is_pre_config: t,
365
453
  load_time_ms: n,
366
- error_type: r
454
+ error_type: i
367
455
  }
368
456
  });
369
457
  }
370
458
  }
371
- class q extends a {
372
- constructor(e) {
459
+ class T extends a {
460
+ constructor(e = []) {
373
461
  super({
374
462
  eventName: "epigraph_module_closed",
375
463
  interactiveEvent: !0,
@@ -379,8 +467,8 @@ class q extends a {
379
467
  });
380
468
  }
381
469
  }
382
- class T extends a {
383
- constructor(e, t, n) {
470
+ class z extends a {
471
+ constructor(e = [], t, n = {}) {
384
472
  super({
385
473
  eventName: "epigraph_support_detected",
386
474
  interactiveEvent: !1,
@@ -392,8 +480,8 @@ class T extends a {
392
480
  });
393
481
  }
394
482
  }
395
- class b extends a {
396
- constructor(e, t, n) {
483
+ class q extends a {
484
+ constructor(e = [], t, n) {
397
485
  super({
398
486
  eventName: "epigraph_button_click",
399
487
  interactiveEvent: !0,
@@ -405,34 +493,34 @@ class b extends a {
405
493
  });
406
494
  }
407
495
  }
408
- class O extends a {
409
- constructor(e, t, n, r) {
496
+ class G extends a {
497
+ constructor(e = [], t, n, i) {
410
498
  super({
411
499
  eventName: "epigraph_panel_opened",
412
500
  interactiveEvent: t,
413
501
  customParameters: {
414
502
  items: e,
415
503
  panel_type: n,
416
- trigger_source: r
504
+ trigger_source: i
417
505
  }
418
506
  });
419
507
  }
420
508
  }
421
- class D extends a {
422
- constructor(e, t, n, r) {
509
+ class O extends a {
510
+ constructor(e = [], t, n, i) {
423
511
  super({
424
512
  eventName: "epigraph_panel_closed",
425
513
  interactiveEvent: t,
426
514
  customParameters: {
427
515
  items: e,
428
516
  panel_type: n,
429
- trigger_source: r
517
+ trigger_source: i
430
518
  }
431
519
  });
432
520
  }
433
521
  }
434
- class R extends a {
435
- constructor(e) {
522
+ class D extends a {
523
+ constructor(e = []) {
436
524
  super({
437
525
  eventName: "epigraph_add_to_favourites",
438
526
  interactiveEvent: !0,
@@ -442,8 +530,8 @@ class R extends a {
442
530
  });
443
531
  }
444
532
  }
445
- class G extends a {
446
- constructor(e, t) {
533
+ class b extends a {
534
+ constructor(e = [], t) {
447
535
  super({
448
536
  eventName: "epigraph_keyboard_interaction",
449
537
  interactiveEvent: !0,
@@ -454,8 +542,8 @@ class G extends a {
454
542
  });
455
543
  }
456
544
  }
457
- class k extends a {
458
- constructor(e, t) {
545
+ class R extends a {
546
+ constructor(e = [], t) {
459
547
  super({
460
548
  eventName: "epigraph_touch_interaction",
461
549
  interactiveEvent: !0,
@@ -466,22 +554,22 @@ class k extends a {
466
554
  });
467
555
  }
468
556
  }
469
- class j extends a {
470
- constructor(e, t, n, r, i) {
557
+ class M extends a {
558
+ constructor(e = [], t, n, i, r) {
471
559
  super({
472
560
  eventName: "epigraph_item_added",
473
561
  interactiveEvent: t,
474
562
  customParameters: {
475
563
  items: e,
476
564
  value: n,
477
- currency: r,
478
- quantity: i
565
+ currency: i,
566
+ quantity: r
479
567
  }
480
568
  });
481
569
  }
482
570
  }
483
- class U extends a {
484
- constructor(e) {
571
+ class $ extends a {
572
+ constructor(e = []) {
485
573
  super({
486
574
  eventName: "epigraph_item_moved",
487
575
  interactiveEvent: !0,
@@ -491,8 +579,8 @@ class U extends a {
491
579
  });
492
580
  }
493
581
  }
494
- class B extends a {
495
- constructor(e, t, n) {
582
+ class k extends a {
583
+ constructor(e = [], t, n) {
496
584
  super({
497
585
  eventName: "epigraph_item_removed",
498
586
  interactiveEvent: !0,
@@ -504,8 +592,8 @@ class B extends a {
504
592
  });
505
593
  }
506
594
  }
507
- class M extends a {
508
- constructor(e, t) {
595
+ class j extends a {
596
+ constructor(e = [], t) {
509
597
  super({
510
598
  eventName: "epigraph_variant_changed",
511
599
  interactiveEvent: !0,
@@ -516,8 +604,8 @@ class M extends a {
516
604
  });
517
605
  }
518
606
  }
519
- class $ extends a {
520
- constructor(e, t, n) {
607
+ class U extends a {
608
+ constructor(e = [], t, n) {
521
609
  super({
522
610
  eventName: "epigraph_content_shared",
523
611
  interactiveEvent: !0,
@@ -529,8 +617,8 @@ class $ extends a {
529
617
  });
530
618
  }
531
619
  }
532
- class z extends a {
533
- constructor(e, t, n) {
620
+ class F extends a {
621
+ constructor(e = [], t, n) {
534
622
  super({
535
623
  eventName: "epigraph_checkout",
536
624
  interactiveEvent: !0,
@@ -542,8 +630,8 @@ class z extends a {
542
630
  });
543
631
  }
544
632
  }
545
- class J extends a {
546
- constructor(e, t, n) {
633
+ class B extends a {
634
+ constructor(e = [], t, n) {
547
635
  super({
548
636
  eventName: "epigraph_conversion",
549
637
  interactiveEvent: !0,
@@ -555,8 +643,8 @@ class J extends a {
555
643
  });
556
644
  }
557
645
  }
558
- class V extends a {
559
- constructor(e, t) {
646
+ class J extends a {
647
+ constructor(e = [], t) {
560
648
  super({
561
649
  eventName: "epigraph_changeRate",
562
650
  interactiveEvent: !1,
@@ -567,8 +655,8 @@ class V extends a {
567
655
  });
568
656
  }
569
657
  }
570
- class F extends a {
571
- constructor(e, t) {
658
+ class V extends a {
659
+ constructor(e = [], t) {
572
660
  super({
573
661
  eventName: "epigraph_completionRate",
574
662
  interactiveEvent: !1,
@@ -580,7 +668,7 @@ class F extends a {
580
668
  }
581
669
  }
582
670
  class H extends a {
583
- constructor(e, t) {
671
+ constructor(e = [], t) {
584
672
  super({
585
673
  eventName: "epigraph_engagementRate",
586
674
  interactiveEvent: !1,
@@ -591,6 +679,15 @@ class H extends a {
591
679
  });
592
680
  }
593
681
  }
682
+ class X extends a {
683
+ constructor(e, t, n) {
684
+ super({
685
+ eventName: e,
686
+ interactiveEvent: t,
687
+ customParameters: n
688
+ });
689
+ }
690
+ }
594
691
  /**
595
692
  * @license
596
693
  * Copyright (c) 2023 Epigraph LLC. All Rights Reserved.
@@ -610,7 +707,7 @@ class H extends a {
610
707
  var f;
611
708
  const c = Symbol("analyticsPluginsMap");
612
709
  f = c;
613
- class X {
710
+ class K {
614
711
  constructor(e, t) {
615
712
  this[f] = /* @__PURE__ */ new Map(), this.__consentPlugin = null, e && t && (this.__consentPlugin = this.buildConsentPlugin(e, t)), window.addEventListener("epigraphAnalyticsConsentChange", this.__onConsentChangeFromEvent);
616
713
  }
@@ -618,7 +715,7 @@ class X {
618
715
  let t = e;
619
716
  this.__overrideConsent = t.detail.hasConsent;
620
717
  for (const n of this[c].values())
621
- this.__hasConsent() || n.setStatus(o.RESTRICTED);
718
+ this.__hasConsent() || n.setStatus(u.RESTRICTED);
622
719
  }
623
720
  /**
624
721
  * Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
@@ -660,35 +757,36 @@ class X {
660
757
  * @private
661
758
  */
662
759
  buildConsentPlugin(e, t) {
663
- return e.toLowerCase() === E.OneTrust.toLowerCase() ? new w(t) : null;
760
+ return e.toLowerCase() === E.OneTrust.toLowerCase() ? new N(t) : null;
664
761
  }
665
762
  }
666
763
  export {
667
764
  E as ConsentPluginNames,
668
- R as EpigraphAddToFavouritesEvent,
669
- X as EpigraphAnalytics,
670
- L as EpigraphArRequestedEvent,
671
- b as EpigraphButtonClickEvent,
672
- V as EpigraphChangeRateEvent,
673
- z as EpigraphCheckoutEvent,
674
- F as EpigraphCompletionRateEvent,
675
- $ as EpigraphContentSharedEvent,
676
- J as EpigraphConversionEvent,
765
+ D as EpigraphAddToFavouritesEvent,
766
+ K as EpigraphAnalytics,
767
+ C as EpigraphArRequestedEvent,
768
+ q as EpigraphButtonClickEvent,
769
+ J as EpigraphChangeRateEvent,
770
+ F as EpigraphCheckoutEvent,
771
+ V as EpigraphCompletionRateEvent,
772
+ U as EpigraphContentSharedEvent,
773
+ B as EpigraphConversionEvent,
774
+ X as EpigraphCustomEvent,
677
775
  H as EpigraphEngagementRateEvent,
678
- j as EpigraphItemAddedEvent,
679
- U as EpigraphItemMovedEvent,
680
- B as EpigraphItemRemovedEvent,
681
- G as EpigraphKeyboardInteractionEvent,
682
- q as EpigraphModuleClosedEvent,
683
- I as EpigraphModuleFailedEvent,
684
- A as EpigraphModuleLoadingEvent,
685
- x as EpigraphModuleReadyEvent,
686
- D as EpigraphPanelClosedEvent,
687
- O as EpigraphPanelOpenedEvent,
688
- T as EpigraphSupportDetectedEvent,
689
- k as EpigraphTouchInteractionEvent,
690
- M as EpigraphVariantChangedEvent,
691
- N as GA4AnalyticsPlugin,
692
- S as NexusAnalyticsPlugin,
693
- w as OneTrustConsentPlugin
776
+ M as EpigraphItemAddedEvent,
777
+ $ as EpigraphItemMovedEvent,
778
+ k as EpigraphItemRemovedEvent,
779
+ b as EpigraphKeyboardInteractionEvent,
780
+ T as EpigraphModuleClosedEvent,
781
+ x as EpigraphModuleFailedEvent,
782
+ L as EpigraphModuleLoadingEvent,
783
+ S as EpigraphModuleReadyEvent,
784
+ O as EpigraphPanelClosedEvent,
785
+ G as EpigraphPanelOpenedEvent,
786
+ z as EpigraphSupportDetectedEvent,
787
+ R as EpigraphTouchInteractionEvent,
788
+ j as EpigraphVariantChangedEvent,
789
+ P as GA4AnalyticsPlugin,
790
+ I as NexusAnalyticsPlugin,
791
+ N as OneTrustConsentPlugin
694
792
  };
@@ -22,72 +22,72 @@ declare class BaseAnalyticsEvent implements IAnalyticsEvent {
22
22
  };
23
23
  }
24
24
  export declare class EpigraphArRequestedEvent extends BaseAnalyticsEvent {
25
- constructor(items: IAnalyticsParameterItems);
25
+ constructor(items?: IAnalyticsParameterItems);
26
26
  }
27
27
  export declare class EpigraphModuleLoadingEvent extends BaseAnalyticsEvent {
28
- constructor(items: IAnalyticsParameterItems, isPreConfig: boolean);
28
+ constructor(items: IAnalyticsParameterItems | undefined, isPreConfig: boolean);
29
29
  }
30
30
  export declare class EpigraphModuleReadyEvent extends BaseAnalyticsEvent {
31
- constructor(items: IAnalyticsParameterItems, isPreConfig: boolean, loadTimeMs: number);
31
+ constructor(items: IAnalyticsParameterItems | undefined, isPreConfig: boolean, loadTimeMs: number);
32
32
  }
33
33
  export declare class EpigraphModuleFailedEvent extends BaseAnalyticsEvent {
34
- constructor(items: IAnalyticsParameterItems, isPreConfig: boolean, loadTimeMs: number, errorType: string);
34
+ constructor(items: IAnalyticsParameterItems | undefined, isPreConfig: boolean, loadTimeMs: number, errorType: string);
35
35
  }
36
36
  export declare class EpigraphModuleClosedEvent extends BaseAnalyticsEvent {
37
- constructor(items: IAnalyticsParameterItems);
37
+ constructor(items?: IAnalyticsParameterItems);
38
38
  }
39
39
  export declare class EpigraphSupportDetectedEvent extends BaseAnalyticsEvent {
40
- constructor(items: IAnalyticsParameterItems, supportType: string, deviceCapabilities: {
41
- ar_supported: boolean;
42
- camera_access: boolean;
43
- });
40
+ constructor(items: IAnalyticsParameterItems | undefined, supportType: string, deviceCapabilities?: Record<string, unknown>);
44
41
  }
45
42
  export declare class EpigraphButtonClickEvent extends BaseAnalyticsEvent {
46
- constructor(items: IAnalyticsParameterItems, buttonType: string, buttonName: string);
43
+ constructor(items: IAnalyticsParameterItems | undefined, buttonType: string, buttonName: string);
47
44
  }
48
45
  export declare class EpigraphPanelOpenedEvent extends BaseAnalyticsEvent {
49
- constructor(items: IAnalyticsParameterItems, isInteractive: boolean, panelType: string, triggerSource: string);
46
+ constructor(items: IAnalyticsParameterItems | undefined, isInteractive: boolean, panelType: string, triggerSource: string);
50
47
  }
51
48
  export declare class EpigraphPanelClosedEvent extends BaseAnalyticsEvent {
52
- constructor(items: IAnalyticsParameterItems, isInteractive: boolean, panelType: string, triggerSource: string);
49
+ constructor(items: IAnalyticsParameterItems | undefined, isInteractive: boolean, panelType: string, triggerSource: string);
53
50
  }
54
51
  export declare class EpigraphAddToFavouritesEvent extends BaseAnalyticsEvent {
55
- constructor(items: IAnalyticsParameterItems);
52
+ constructor(items?: IAnalyticsParameterItems);
56
53
  }
57
54
  export declare class EpigraphKeyboardInteractionEvent extends BaseAnalyticsEvent {
58
- constructor(items: IAnalyticsParameterItems, actionPerformed: string);
55
+ constructor(items: IAnalyticsParameterItems | undefined, actionPerformed: string);
59
56
  }
60
57
  export declare class EpigraphTouchInteractionEvent extends BaseAnalyticsEvent {
61
- constructor(items: IAnalyticsParameterItems, interactionType: string);
58
+ constructor(items: IAnalyticsParameterItems | undefined, interactionType: string);
62
59
  }
63
60
  export declare class EpigraphItemAddedEvent extends BaseAnalyticsEvent {
64
- constructor(items: IAnalyticsParameterItems, isInteractive: boolean, value: number, currency: string, quantity: number);
61
+ constructor(items: IAnalyticsParameterItems | undefined, isInteractive: boolean, value: number, currency: string, quantity: number);
65
62
  }
66
63
  export declare class EpigraphItemMovedEvent extends BaseAnalyticsEvent {
67
- constructor(items: IAnalyticsParameterItems);
64
+ constructor(items?: IAnalyticsParameterItems);
68
65
  }
69
66
  export declare class EpigraphItemRemovedEvent extends BaseAnalyticsEvent {
70
- constructor(items: IAnalyticsParameterItems, currency: string, quantity: number);
67
+ constructor(items: IAnalyticsParameterItems | undefined, currency: string, quantity: number);
71
68
  }
72
69
  export declare class EpigraphVariantChangedEvent extends BaseAnalyticsEvent {
73
- constructor(items: IAnalyticsParameterItems, changeType: string);
70
+ constructor(items: IAnalyticsParameterItems | undefined, changeType: string);
74
71
  }
75
72
  export declare class EpigraphContentSharedEvent extends BaseAnalyticsEvent {
76
- constructor(items: IAnalyticsParameterItems, contentType: string, shareDestination: string);
73
+ constructor(items: IAnalyticsParameterItems | undefined, contentType: string, shareDestination: string);
77
74
  }
78
75
  export declare class EpigraphCheckoutEvent extends BaseAnalyticsEvent {
79
- constructor(items: IAnalyticsParameterItems, value: number, currency: string);
76
+ constructor(items: Array<any> | undefined, value: number, currency: string);
80
77
  }
81
78
  export declare class EpigraphConversionEvent extends BaseAnalyticsEvent {
82
- constructor(items: IAnalyticsParameterItems, value: number, currency: string);
79
+ constructor(items: IAnalyticsParameterItems | undefined, value: number, currency: string);
83
80
  }
84
81
  export declare class EpigraphChangeRateEvent extends BaseAnalyticsEvent {
85
- constructor(items: IAnalyticsParameterItems, value: number);
82
+ constructor(items: IAnalyticsParameterItems | undefined, value: number);
86
83
  }
87
84
  export declare class EpigraphCompletionRateEvent extends BaseAnalyticsEvent {
88
- constructor(items: IAnalyticsParameterItems, value: number);
85
+ constructor(items: IAnalyticsParameterItems | undefined, value: number);
89
86
  }
90
87
  export declare class EpigraphEngagementRateEvent extends BaseAnalyticsEvent {
91
- constructor(items: IAnalyticsParameterItems, value: number);
88
+ constructor(items: IAnalyticsParameterItems | undefined, value: number);
89
+ }
90
+ export declare class EpigraphCustomEvent extends BaseAnalyticsEvent {
91
+ constructor(eventName: string, interactiveEvent: boolean, customParameters: Record<string, unknown>);
92
92
  }
93
93
  export {};
@@ -3,6 +3,9 @@ import { IAnalyticsEvent } from '../analytics-event-interface';
3
3
  declare global {
4
4
  interface Window {
5
5
  [key: string]: any;
6
+ gtag?: (...args: any[]) => void;
7
+ dataLayer?: Array<Record<string, any>>;
8
+ epgDataLayerName?: string;
6
9
  }
7
10
  }
8
11
  export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
@@ -12,11 +15,18 @@ export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
12
15
  solution: string;
13
16
  experienceID: string;
14
17
  verboseLogging: boolean;
15
- dataLayer: Array<Record<string, any>>;
16
- dataLayerName: string | undefined;
18
+ dataLayer: Array<Record<string, any>> | undefined;
19
+ dataLayerName: string;
17
20
  private __queue;
18
21
  private __status;
19
22
  private __sentEventCount;
23
+ private __initializationAttempts;
24
+ private __lastInitializationAttempt;
25
+ private __maxInitializationAttempts;
26
+ private __initializationRetryDelay;
27
+ private __isInitialized;
28
+ private __initializationMethod;
29
+ private __nexusFailureReported;
20
30
  constructor({ trackingID, experienceID, solution, verboseLogging }: {
21
31
  trackingID: string;
22
32
  experienceID: string;
@@ -37,11 +47,13 @@ export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
37
47
  * This function will send an Event to Google Analytics 4.
38
48
  *
39
49
  * @param eventData IAnalyticsEvent The event to be tracked
40
- * @param consentPlugin
50
+ * @param consent boolean Whether consent is granted
41
51
  */
42
52
  sendEvent(analyticsEvent: IAnalyticsEvent, consent: boolean): Promise<void>;
43
- private setupDataLayer;
44
- private initGtag;
53
+ private initializePlugin;
54
+ private detectAndSetupAnalytics;
55
+ private detectGTM;
56
+ private setupGA4;
45
57
  /**
46
58
  * Send all events that are in the queue
47
59
  * @private
@@ -53,5 +65,7 @@ export declare class GA4AnalyticsPlugin implements IAnalyticsPlugin {
53
65
  */
54
66
  private logger;
55
67
  private sendGA4LongParameters;
68
+ private sendToGTM;
69
+ private reportFailureToNexus;
56
70
  private findGA4ScriptInfo;
57
71
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./Epigraph/epigraph.cjs"),E=require("./Epigraph/epigraphBaseSolutions.cjs"),e=require("./EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.cjs"),r=require("./EpigraphLibs/EpigraphLogger/epigraphLogger.cjs"),p=require("./EpigraphLibs/EpigraphNexusApi/epigraphNexusApi.cjs"),g=require("./EpigraphLibs/EpigraphQrCodeGenerator/epigraphQrCodeGenerator.cjs"),i=require("./EpigraphLibs/EpigraphResultFactory/epigraphResultFactory.cjs"),t=require("./EpigraphLibs/EpigraphUnitsConverter/epigraphUnitsConverter.cjs"),a=require("./EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.cjs");exports.ENVIRONMENT_TYPE=n.ENVIRONMENT_TYPE;exports.Epigraph=n.Epigraph;exports.EpigraphBaseSolutionHtmlElement=E.EpigraphBaseSolutionHtmlElement;exports.EpigraphBaseSolutionLitElement=E.EpigraphBaseSolutionLitElement;exports.ConsentPluginNames=e.ConsentPluginNames;exports.EpigraphAddToFavouritesEvent=e.EpigraphAddToFavouritesEvent;exports.EpigraphAnalytics=e.EpigraphAnalytics;exports.EpigraphArRequestedEvent=e.EpigraphArRequestedEvent;exports.EpigraphButtonClickEvent=e.EpigraphButtonClickEvent;exports.EpigraphChangeRateEvent=e.EpigraphChangeRateEvent;exports.EpigraphCheckoutEvent=e.EpigraphCheckoutEvent;exports.EpigraphCompletionRateEvent=e.EpigraphCompletionRateEvent;exports.EpigraphContentSharedEvent=e.EpigraphContentSharedEvent;exports.EpigraphConversionEvent=e.EpigraphConversionEvent;exports.EpigraphEngagementRateEvent=e.EpigraphEngagementRateEvent;exports.EpigraphItemAddedEvent=e.EpigraphItemAddedEvent;exports.EpigraphItemMovedEvent=e.EpigraphItemMovedEvent;exports.EpigraphItemRemovedEvent=e.EpigraphItemRemovedEvent;exports.EpigraphKeyboardInteractionEvent=e.EpigraphKeyboardInteractionEvent;exports.EpigraphModuleClosedEvent=e.EpigraphModuleClosedEvent;exports.EpigraphModuleFailedEvent=e.EpigraphModuleFailedEvent;exports.EpigraphModuleLoadingEvent=e.EpigraphModuleLoadingEvent;exports.EpigraphModuleReadyEvent=e.EpigraphModuleReadyEvent;exports.EpigraphPanelClosedEvent=e.EpigraphPanelClosedEvent;exports.EpigraphPanelOpenedEvent=e.EpigraphPanelOpenedEvent;exports.EpigraphSupportDetectedEvent=e.EpigraphSupportDetectedEvent;exports.EpigraphTouchInteractionEvent=e.EpigraphTouchInteractionEvent;exports.EpigraphVariantChangedEvent=e.EpigraphVariantChangedEvent;exports.GA4AnalyticsPlugin=e.GA4AnalyticsPlugin;exports.NexusAnalyticsPlugin=e.NexusAnalyticsPlugin;exports.OneTrustConsentPlugin=e.OneTrustConsentPlugin;exports.EpigraphLogger=r.EpigraphLogger;exports.LogTypes=r.LogTypes;exports.LoggerModeNames=r.LoggerModeNames;exports.EpigraphNexusAPI=p.EpigraphNexusAPI;exports.HTTPMethod=p.HTTPMethod;exports.NexusAPIResourceIdentifier=p.NexusAPIResourceIdentifier;exports.NexusAPIRoutes=p.NexusAPIRoutes;exports.NexusAPIVersions=p.NexusAPIVersions;exports.NexusEndpoints=p.NexusEndpoints;exports.EpigraphQrCodeGenerator=g.EpigraphQrCodeGenerator;exports.Result=i.Result;exports.failureResult=i.failureResult;exports.successResult=i.successResult;exports.Distance=t.Distance;exports.DistanceUnits=t.DistanceUnits;exports.UnitTypes=t.UnitTypes;exports.EpigraphUrlProcessor=a.EpigraphUrlProcessor;exports.QUERY_PARAMETER_ACTION_NAMES=a.QUERY_PARAMETER_ACTION_NAMES;exports.QUERY_PARAMETER_NAMES=a.QUERY_PARAMETER_NAMES;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./Epigraph/epigraph.cjs"),E=require("./Epigraph/epigraphBaseSolutions.cjs"),e=require("./EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.cjs"),r=require("./EpigraphLibs/EpigraphLogger/epigraphLogger.cjs"),p=require("./EpigraphLibs/EpigraphNexusApi/epigraphNexusApi.cjs"),g=require("./EpigraphLibs/EpigraphQrCodeGenerator/epigraphQrCodeGenerator.cjs"),t=require("./EpigraphLibs/EpigraphResultFactory/epigraphResultFactory.cjs"),i=require("./EpigraphLibs/EpigraphUnitsConverter/epigraphUnitsConverter.cjs"),a=require("./EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.cjs");exports.ENVIRONMENT_TYPE=n.ENVIRONMENT_TYPE;exports.Epigraph=n.Epigraph;exports.EpigraphBaseSolutionHtmlElement=E.EpigraphBaseSolutionHtmlElement;exports.EpigraphBaseSolutionLitElement=E.EpigraphBaseSolutionLitElement;exports.ConsentPluginNames=e.ConsentPluginNames;exports.EpigraphAddToFavouritesEvent=e.EpigraphAddToFavouritesEvent;exports.EpigraphAnalytics=e.EpigraphAnalytics;exports.EpigraphArRequestedEvent=e.EpigraphArRequestedEvent;exports.EpigraphButtonClickEvent=e.EpigraphButtonClickEvent;exports.EpigraphChangeRateEvent=e.EpigraphChangeRateEvent;exports.EpigraphCheckoutEvent=e.EpigraphCheckoutEvent;exports.EpigraphCompletionRateEvent=e.EpigraphCompletionRateEvent;exports.EpigraphContentSharedEvent=e.EpigraphContentSharedEvent;exports.EpigraphConversionEvent=e.EpigraphConversionEvent;exports.EpigraphCustomEvent=e.EpigraphCustomEvent;exports.EpigraphEngagementRateEvent=e.EpigraphEngagementRateEvent;exports.EpigraphItemAddedEvent=e.EpigraphItemAddedEvent;exports.EpigraphItemMovedEvent=e.EpigraphItemMovedEvent;exports.EpigraphItemRemovedEvent=e.EpigraphItemRemovedEvent;exports.EpigraphKeyboardInteractionEvent=e.EpigraphKeyboardInteractionEvent;exports.EpigraphModuleClosedEvent=e.EpigraphModuleClosedEvent;exports.EpigraphModuleFailedEvent=e.EpigraphModuleFailedEvent;exports.EpigraphModuleLoadingEvent=e.EpigraphModuleLoadingEvent;exports.EpigraphModuleReadyEvent=e.EpigraphModuleReadyEvent;exports.EpigraphPanelClosedEvent=e.EpigraphPanelClosedEvent;exports.EpigraphPanelOpenedEvent=e.EpigraphPanelOpenedEvent;exports.EpigraphSupportDetectedEvent=e.EpigraphSupportDetectedEvent;exports.EpigraphTouchInteractionEvent=e.EpigraphTouchInteractionEvent;exports.EpigraphVariantChangedEvent=e.EpigraphVariantChangedEvent;exports.GA4AnalyticsPlugin=e.GA4AnalyticsPlugin;exports.NexusAnalyticsPlugin=e.NexusAnalyticsPlugin;exports.OneTrustConsentPlugin=e.OneTrustConsentPlugin;exports.EpigraphLogger=r.EpigraphLogger;exports.LogTypes=r.LogTypes;exports.LoggerModeNames=r.LoggerModeNames;exports.EpigraphNexusAPI=p.EpigraphNexusAPI;exports.HTTPMethod=p.HTTPMethod;exports.NexusAPIResourceIdentifier=p.NexusAPIResourceIdentifier;exports.NexusAPIRoutes=p.NexusAPIRoutes;exports.NexusAPIVersions=p.NexusAPIVersions;exports.NexusEndpoints=p.NexusEndpoints;exports.EpigraphQrCodeGenerator=g.EpigraphQrCodeGenerator;exports.Result=t.Result;exports.failureResult=t.failureResult;exports.successResult=t.successResult;exports.Distance=i.Distance;exports.DistanceUnits=i.DistanceUnits;exports.UnitTypes=i.UnitTypes;exports.EpigraphUrlProcessor=a.EpigraphUrlProcessor;exports.QUERY_PARAMETER_ACTION_NAMES=a.QUERY_PARAMETER_ACTION_NAMES;exports.QUERY_PARAMETER_NAMES=a.QUERY_PARAMETER_NAMES;
@@ -1,16 +1,16 @@
1
1
  import { ENVIRONMENT_TYPE as p, Epigraph as r } from "./Epigraph/epigraph.js";
2
2
  import { EpigraphBaseSolutionHtmlElement as n, EpigraphBaseSolutionLitElement as o } from "./Epigraph/epigraphBaseSolutions.js";
3
- import { ConsentPluginNames as i, EpigraphAddToFavouritesEvent as g, EpigraphAnalytics as s, EpigraphArRequestedEvent as h, EpigraphButtonClickEvent as u, EpigraphChangeRateEvent as l, EpigraphCheckoutEvent as d, EpigraphCompletionRateEvent as v, EpigraphContentSharedEvent as m, EpigraphConversionEvent as A, EpigraphEngagementRateEvent as R, EpigraphItemAddedEvent as c, EpigraphItemMovedEvent as x, EpigraphItemRemovedEvent as P, EpigraphKeyboardInteractionEvent as N, EpigraphModuleClosedEvent as C, EpigraphModuleFailedEvent as I, EpigraphModuleLoadingEvent as M, EpigraphModuleReadyEvent as T, EpigraphPanelClosedEvent as f, EpigraphPanelOpenedEvent as y, EpigraphSupportDetectedEvent as S, EpigraphTouchInteractionEvent as _, EpigraphVariantChangedEvent as L, GA4AnalyticsPlugin as U, NexusAnalyticsPlugin as O, OneTrustConsentPlugin as B } from "./EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.js";
4
- import { EpigraphLogger as Q, LogTypes as V, LoggerModeNames as Y } from "./EpigraphLibs/EpigraphLogger/epigraphLogger.js";
5
- import { EpigraphNexusAPI as F, HTTPMethod as G, NexusAPIResourceIdentifier as H, NexusAPIRoutes as b, NexusAPIVersions as q, NexusEndpoints as K } from "./EpigraphLibs/EpigraphNexusApi/epigraphNexusApi.js";
6
- import { EpigraphQrCodeGenerator as w } from "./EpigraphLibs/EpigraphQrCodeGenerator/epigraphQrCodeGenerator.js";
7
- import { Result as J, failureResult as W, successResult as X } from "./EpigraphLibs/EpigraphResultFactory/epigraphResultFactory.js";
8
- import { Distance as $, DistanceUnits as ee, UnitTypes as te } from "./EpigraphLibs/EpigraphUnitsConverter/epigraphUnitsConverter.js";
9
- import { EpigraphUrlProcessor as re, QUERY_PARAMETER_ACTION_NAMES as Ee, QUERY_PARAMETER_NAMES as ne } from "./EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.js";
3
+ import { ConsentPluginNames as i, EpigraphAddToFavouritesEvent as g, EpigraphAnalytics as s, EpigraphArRequestedEvent as h, EpigraphButtonClickEvent as u, EpigraphChangeRateEvent as l, EpigraphCheckoutEvent as d, EpigraphCompletionRateEvent as v, EpigraphContentSharedEvent as m, EpigraphConversionEvent as A, EpigraphCustomEvent as R, EpigraphEngagementRateEvent as c, EpigraphItemAddedEvent as x, EpigraphItemMovedEvent as P, EpigraphItemRemovedEvent as C, EpigraphKeyboardInteractionEvent as N, EpigraphModuleClosedEvent as I, EpigraphModuleFailedEvent as M, EpigraphModuleLoadingEvent as T, EpigraphModuleReadyEvent as f, EpigraphPanelClosedEvent as y, EpigraphPanelOpenedEvent as S, EpigraphSupportDetectedEvent as _, EpigraphTouchInteractionEvent as L, EpigraphVariantChangedEvent as U, GA4AnalyticsPlugin as O, NexusAnalyticsPlugin as B, OneTrustConsentPlugin as D } from "./EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.js";
4
+ import { EpigraphLogger as V, LogTypes as Y, LoggerModeNames as k } from "./EpigraphLibs/EpigraphLogger/epigraphLogger.js";
5
+ import { EpigraphNexusAPI as G, HTTPMethod as H, NexusAPIResourceIdentifier as b, NexusAPIRoutes as q, NexusAPIVersions as K, NexusEndpoints as j } from "./EpigraphLibs/EpigraphNexusApi/epigraphNexusApi.js";
6
+ import { EpigraphQrCodeGenerator as z } from "./EpigraphLibs/EpigraphQrCodeGenerator/epigraphQrCodeGenerator.js";
7
+ import { Result as W, failureResult as X, successResult as Z } from "./EpigraphLibs/EpigraphResultFactory/epigraphResultFactory.js";
8
+ import { Distance as ee, DistanceUnits as te, UnitTypes as pe } from "./EpigraphLibs/EpigraphUnitsConverter/epigraphUnitsConverter.js";
9
+ import { EpigraphUrlProcessor as Ee, QUERY_PARAMETER_ACTION_NAMES as ne, QUERY_PARAMETER_NAMES as oe } from "./EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.js";
10
10
  export {
11
11
  i as ConsentPluginNames,
12
- $ as Distance,
13
- ee as DistanceUnits,
12
+ ee as Distance,
13
+ te as DistanceUnits,
14
14
  p as ENVIRONMENT_TYPE,
15
15
  r as Epigraph,
16
16
  g as EpigraphAddToFavouritesEvent,
@@ -24,38 +24,39 @@ export {
24
24
  v as EpigraphCompletionRateEvent,
25
25
  m as EpigraphContentSharedEvent,
26
26
  A as EpigraphConversionEvent,
27
- R as EpigraphEngagementRateEvent,
28
- c as EpigraphItemAddedEvent,
29
- x as EpigraphItemMovedEvent,
30
- P as EpigraphItemRemovedEvent,
27
+ R as EpigraphCustomEvent,
28
+ c as EpigraphEngagementRateEvent,
29
+ x as EpigraphItemAddedEvent,
30
+ P as EpigraphItemMovedEvent,
31
+ C as EpigraphItemRemovedEvent,
31
32
  N as EpigraphKeyboardInteractionEvent,
32
- Q as EpigraphLogger,
33
- C as EpigraphModuleClosedEvent,
34
- I as EpigraphModuleFailedEvent,
35
- M as EpigraphModuleLoadingEvent,
36
- T as EpigraphModuleReadyEvent,
37
- F as EpigraphNexusAPI,
38
- f as EpigraphPanelClosedEvent,
39
- y as EpigraphPanelOpenedEvent,
40
- w as EpigraphQrCodeGenerator,
41
- S as EpigraphSupportDetectedEvent,
42
- _ as EpigraphTouchInteractionEvent,
43
- re as EpigraphUrlProcessor,
44
- L as EpigraphVariantChangedEvent,
45
- U as GA4AnalyticsPlugin,
46
- G as HTTPMethod,
47
- V as LogTypes,
48
- Y as LoggerModeNames,
49
- H as NexusAPIResourceIdentifier,
50
- b as NexusAPIRoutes,
51
- q as NexusAPIVersions,
52
- O as NexusAnalyticsPlugin,
53
- K as NexusEndpoints,
54
- B as OneTrustConsentPlugin,
55
- Ee as QUERY_PARAMETER_ACTION_NAMES,
56
- ne as QUERY_PARAMETER_NAMES,
57
- J as Result,
58
- te as UnitTypes,
59
- W as failureResult,
60
- X as successResult
33
+ V as EpigraphLogger,
34
+ I as EpigraphModuleClosedEvent,
35
+ M as EpigraphModuleFailedEvent,
36
+ T as EpigraphModuleLoadingEvent,
37
+ f as EpigraphModuleReadyEvent,
38
+ G as EpigraphNexusAPI,
39
+ y as EpigraphPanelClosedEvent,
40
+ S as EpigraphPanelOpenedEvent,
41
+ z as EpigraphQrCodeGenerator,
42
+ _ as EpigraphSupportDetectedEvent,
43
+ L as EpigraphTouchInteractionEvent,
44
+ Ee as EpigraphUrlProcessor,
45
+ U as EpigraphVariantChangedEvent,
46
+ O as GA4AnalyticsPlugin,
47
+ H as HTTPMethod,
48
+ Y as LogTypes,
49
+ k as LoggerModeNames,
50
+ b as NexusAPIResourceIdentifier,
51
+ q as NexusAPIRoutes,
52
+ K as NexusAPIVersions,
53
+ B as NexusAnalyticsPlugin,
54
+ j as NexusEndpoints,
55
+ D as OneTrustConsentPlugin,
56
+ ne as QUERY_PARAMETER_ACTION_NAMES,
57
+ oe as QUERY_PARAMETER_NAMES,
58
+ W as Result,
59
+ pe as UnitTypes,
60
+ X as failureResult,
61
+ Z as successResult
61
62
  };
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@epigraph/epigraph-std-lib",
3
- "version": "4.5.1-alpha",
4
- "type": "module",
5
- "main": "./dist/epigraph-std-lib.cjs",
6
- "module": "./dist/epigraph-std-lib.js",
7
- "files": [
8
- "dist",
9
- "dist/**/*"
10
- ],
11
- "types": "./dist/epigraph-std-lib.d.ts",
12
- "exports": {
13
- ".": {
14
- "types": "./dist/epigraph-std-lib.d.ts",
15
- "import": "./dist/epigraph-std-lib.js",
16
- "require": "./dist/epigraph-std-lib.cjs"
17
- }
18
- },
19
- "scripts": {
20
- "dev": "vite",
21
- "build": "tsc -b ./tsconfig.lib.json && vite build",
22
- "preview": "vite preview",
23
- "prepublishOnly": "npm run build",
24
- "test": "npm run build && vitest"
25
- },
26
- "dependencies": {},
27
- "peerDependencies": {
28
- "lit": "^3.2.1",
29
- "qr-creator": "^1.0.0"
30
- },
31
- "devDependencies": {
32
- "@types/node": "^22.13.0",
33
- "happy-dom": "^16.8.1",
34
- "typescript": "^5.8.2",
35
- "vite": "^6.0.5",
36
- "vite-plugin-dts": "^4.5.0",
37
- "vitest": "^3.0.5",
38
- "@types/google.analytics": "^0.0.42",
39
- "@types/gtag.js": "^0.0.20"
40
- }
41
- }
1
+ {
2
+ "name": "@epigraph/epigraph-std-lib",
3
+ "version": "4.5.2-alpha",
4
+ "type": "module",
5
+ "main": "./dist/epigraph-std-lib.cjs",
6
+ "module": "./dist/epigraph-std-lib.js",
7
+ "files": [
8
+ "dist",
9
+ "dist/**/*"
10
+ ],
11
+ "types": "./dist/epigraph-std-lib.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/epigraph-std-lib.d.ts",
15
+ "import": "./dist/epigraph-std-lib.js",
16
+ "require": "./dist/epigraph-std-lib.cjs"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "dev": "vite",
21
+ "build": "tsc -b ./tsconfig.lib.json && vite build",
22
+ "preview": "vite preview",
23
+ "prepublishOnly": "npm run build",
24
+ "test": "npm run build && vitest"
25
+ },
26
+ "dependencies": {},
27
+ "peerDependencies": {
28
+ "lit": "^3.2.1",
29
+ "qr-creator": "^1.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.13.0",
33
+ "happy-dom": "^16.8.1",
34
+ "typescript": "^5.8.2",
35
+ "vite": "^6.0.5",
36
+ "vite-plugin-dts": "^4.5.0",
37
+ "vitest": "^3.0.5",
38
+ "@types/google.analytics": "^0.0.42",
39
+ "@types/gtag.js": "^0.0.20"
40
+ }
41
+ }