@epigraph/epigraph-std-lib 4.5.4-alpha → 4.6.0
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 +68 -68
- package/dist/EpigraphLibs/EpigraphAnalytics/analytics-event-interface.d.ts +7 -14
- package/dist/EpigraphLibs/EpigraphAnalytics/analytics-plugin-interface.d.ts +4 -15
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.cjs +2 -2
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.d.ts +7 -14
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.js +188 -629
- package/dist/EpigraphLibs/EpigraphAnalytics/generics/queue.d.ts +3 -3
- package/dist/EpigraphLibs/EpigraphAnalytics/plugins/ga3-analytics-plugin.d.ts +44 -0
- package/dist/EpigraphLibs/EpigraphAnalytics/plugins/ga4-analytics-plugin.d.ts +18 -81
- package/dist/EpigraphLibs/EpigraphAnalytics/plugins/nexus-analytics-plugin.d.ts +7 -23
- package/dist/epigraph-std-lib.cjs +1 -1
- package/dist/epigraph-std-lib.js +38 -60
- package/package.json +41 -41
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalyticsEventLibrary.d.ts +0 -98
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,15 +1,8 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export interface AnalyticsEvent {
|
|
2
|
+
type: string;
|
|
3
|
+
category: string;
|
|
4
|
+
action: string;
|
|
5
|
+
label: string;
|
|
6
|
+
interaction: object;
|
|
7
|
+
parameters?: object;
|
|
8
8
|
}
|
|
9
|
-
export interface IAnalyticsParameterItem {
|
|
10
|
-
item_id: string;
|
|
11
|
-
item_name: string;
|
|
12
|
-
price: number;
|
|
13
|
-
quantity: number;
|
|
14
|
-
}
|
|
15
|
-
export type IAnalyticsParameterItems = Array<IAnalyticsParameterItem>;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
UNAVAILABLE = "unavailable",
|
|
4
|
-
AVAILABLE = "available",
|
|
5
|
-
RESTRICTED = "restricted"
|
|
6
|
-
}
|
|
1
|
+
import { AnalyticsEvent } from './analytics-event-interface';
|
|
2
|
+
import { IConsentPlugin } from './consent-plugin-interface';
|
|
7
3
|
export interface IAnalyticsPlugin {
|
|
8
4
|
trackingID: string;
|
|
9
|
-
experienceID: string;
|
|
10
|
-
solution: string;
|
|
11
5
|
pluginName: string;
|
|
12
|
-
|
|
13
|
-
setStatus(newStatus: AnalyticsStatus): void;
|
|
14
|
-
getPendingEventCount(): number;
|
|
15
|
-
getSentEventCount(): number;
|
|
16
|
-
getTotalEventCount(): number;
|
|
17
|
-
setupPlugin(): void;
|
|
18
|
-
sendEvent(event: IAnalyticsEvent, consent: boolean): void;
|
|
6
|
+
sendEvent(event: AnalyticsEvent, consentPlugin: IConsentPlugin | null): void;
|
|
19
7
|
getUniquePluginIdentifier(): string;
|
|
8
|
+
setupPlugin(): void;
|
|
20
9
|
}
|
|
@@ -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 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,sendTo: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,items:[],sendTo: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})}}/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=Symbol("data"),u=Symbol("next"),m=class p{constructor(e){this[g]=e,this[u]=null}get data(){return this[g]}set next(e){if(!(e instanceof p)&&e!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[u]=e}get next(){return this[u]}};let f=m;const l=Symbol("head");class q{constructor(){this[l]=null}set head(e){this[l]=e}get head(){return this[l]}addToTail(e){let t=this.head;if(t){for(;t.next!==null;)t=t?.next;return t.next=new f(e)}return this.head=new f(e)}removeHead(){const e=this.head;if(e)return this.head=e.next,e.data}}const y=Symbol("queue"),o=Symbol("size");class h{constructor(){this[y]=new q,this[o]=0}get queue(){return this[y]}get size(){return this[o]}enqueue(e){this.queue.addToTail(e),this[o]++}dequeue(){const e=this.queue.removeHead();return this[o]--,e}}class A{constructor(e,t,n,s){this.name=this.pluginName="GA3-PLUGIN",this.trackingID=e,this.verboseLogging=t,this.user=n,this.trackerName=s,this.queue=new h,this.trackerInterval=0,this.trackerCreated=!1}sendEvent(e){if(this.queue.enqueue(e),window.ga!==void 0&&typeof ga=="function")try{this.dequeueAndSendEvents()}catch(t){this.logger(t)}else this.logger("Cannot send Google Analytics 3 event: ga function is not defined.");return!0}dequeueAndSendEvents(){if(this.trackerCreated){let e=this.queue.size;for(let t=0;t<e;t++){const n=this.queue.dequeue();ga(`${this.trackerName}.send`,n.type,n.category,n.action,n.label,n.interaction),this.logger(`Google Analytics 3 event successfully sent: ${n.action}`)}}else this.logger("Cannot sent Google Analytics 3 event: tracker was not created.")}async createTracker(){if(window.ga!==void 0&&typeof ga=="function")try{ga("create",this.trackingID,"auto",this.trackerName,{userId:this.user});const e=new URL(window.location.href);ga(`${this.trackerName}.set`,"page",e.pathname),ga(`${this.trackerName}.set`,"location",e.href),this.trackerCreated=!0,this.logger("Google Analytics 3 tracker successfully created."),this.dequeueAndSendEvents(),window.clearInterval(this.trackerInterval)}catch(e){this.logger(e)}else this.logger("Error: Cannot create tracker, ga function is not defined.")}logger(e){this.verboseLogging&&console.warn(e)}getUniquePluginIdentifier(){return this.pluginName+"-"+this.trackingID}setupPlugin(){var e=0;this.trackerInterval=window.setInterval(()=>{this.createTracker(),++e===10&&(window.clearInterval(this.trackerInterval),this.logger("Error: Failed to create Google Analytics tracker in the allotted timeframe."))},1e3)}}class P{constructor(e,t){this.name=this.pluginName="GA4-PLUGIN",this.trackingID=e,this.verboseLogging=t,this.queue=new h,this.dataLayer=window.dataLayer,this.dataLayerName="dataLayer",this.setupDataLayer(),this.initGtag(this.dataLayerName,this.trackingID)}setupDataLayer(){if(this.dataLayer)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 sendEvent(e,t){this.queue.enqueue(e);let n=!0;if(t&&(n=t.hasConsent()),this.dataLayer!==void 0&&n)try{await this.dequeueAndSendEvents()}catch(s){this.logger(s)}else this.logger("Cannot send Google Analytics 4 event: dataLayer is not defined.")}async dequeueAndSendEvents(){let e=this.queue.size;for(let t=0;t<e;t++){const n=this.queue.dequeue();let s={send_to:this.trackingID,event_action:n.action,event_category:n.category,event_label:n.label,epg_event_tag:""};if("parameters"in n&&Object.assign(s,n.parameters),JSON.stringify(s).length>459)try{let r=await this.sendGA4LongParameters(s);s={send_to:this.trackingID,event_action:n.action,event_category:n.category,event_label:n.label,epg_event_tag:r}}catch{}gtag("event",n.action,s),this.logger(`Google Analytics 4 event successfully sent: ${n.action}`)}}logger(e){this.verboseLogging&&console.warn(e)}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){this.dataLayer!==void 0&&this.dequeueAndSendEvents()}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)});if(s.ok){const a=await s.json();return a&&a.id?a.id:""}else return""}catch{return""}}findGA4ScriptInfo(e){const t=document.querySelectorAll("script[src]");for(const n of t){const s=n.getAttribute("src");if(s&&s.includes(e)){const a=new URL(s,location.href),r=Object.fromEntries(a.searchParams.entries());return{fullSrc:a.href,id:r.id||void 0,l:r.l||void 0}}}return null}}class L{constructor(e,t,n,s,a=!1){this.sessionId=t,this.xPath=n,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=e,this.verboseLogging=s,this.queue=new h,this.url=a?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event"}async sendEvent(e,t){this.queue.enqueue(e);let n=!0;t&&(n=t.hasConsent()),n&&await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let e=0;e<this.queue.size;e++){const t=this.queue.dequeue(),n={experience_id:this.trackingID,action:t.action,parameters:t.parameters};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===204,""}catch{return""}}return""}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}}class w{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 d=(i=>(i.OneTrust="onetrust",i))(d||{});/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright (c) 2023 Epigraph LLC. All Rights Reserved.
|
|
4
4
|
*
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var
|
|
16
|
+
*/var v;const c=Symbol("analyticsPluginsMap");v=c;class S{constructor(e,t){this[v]=new Map,this._consentPlugin=null,e&&t&&(this._consentPlugin=this.buildConsentPlugin(e,t))}addEventPlugin(e){this[c].has(e.getUniquePluginIdentifier())||(this[c].set(e.getUniquePluginIdentifier(),e),e.setupPlugin())}sendEvent(e){this[c].forEach(t=>{t.sendEvent(e,this._consentPlugin)})}buildConsentPlugin(e,t){return e.toLowerCase()===d.OneTrust.toLowerCase()?new w(t):null}}exports.ConsentPluginNames=d;exports.EpigraphAnalytics=S;exports.GA3AnalyticsPlugin=A;exports.GA4AnalyticsPlugin=P;exports.NexusAnalyticsPlugin=L;exports.OneTrustConsentPlugin=w;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { IAnalyticsPlugin } from './analytics-plugin-interface';
|
|
2
|
-
import {
|
|
2
|
+
import { AnalyticsEvent } from './analytics-event-interface';
|
|
3
|
+
import { GA3AnalyticsPlugin } from './plugins/ga3-analytics-plugin';
|
|
3
4
|
import { GA4AnalyticsPlugin } from './plugins/ga4-analytics-plugin';
|
|
4
5
|
import { NexusAnalyticsPlugin } from './plugins/nexus-analytics-plugin';
|
|
6
|
+
import { IConsentPlugin } from './consent-plugin-interface';
|
|
5
7
|
import { OneTrustConsentPlugin } from './consent-plugins/one-trust-consent-plugin';
|
|
6
8
|
import { ConsentPluginNames } from './consent-plugins/consent-plugin-names';
|
|
7
9
|
declare const $analyticsPluginsMap: unique symbol;
|
|
8
10
|
export type AnalyticsTrackerMap = Map<string, IAnalyticsPlugin>;
|
|
9
|
-
export type {
|
|
10
|
-
export
|
|
11
|
+
export type { AnalyticsEvent };
|
|
12
|
+
export { GA3AnalyticsPlugin };
|
|
11
13
|
export { GA4AnalyticsPlugin };
|
|
12
14
|
export { NexusAnalyticsPlugin };
|
|
13
15
|
export { OneTrustConsentPlugin };
|
|
14
16
|
export { ConsentPluginNames };
|
|
15
17
|
export declare class EpigraphAnalytics {
|
|
16
18
|
private [$analyticsPluginsMap];
|
|
17
|
-
|
|
18
|
-
private __overrideConsent;
|
|
19
|
+
_consentPlugin: IConsentPlugin | null;
|
|
19
20
|
constructor(consentPluginName: string | null, consentIdentifier: string | null);
|
|
20
|
-
private __onConsentChangeFromEvent;
|
|
21
21
|
/**
|
|
22
22
|
* Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
|
|
23
23
|
* by implementing the IAnalyticsPlugin and then adding it via this function. This will also hold only a single
|
|
@@ -26,19 +26,12 @@ export declare class EpigraphAnalytics {
|
|
|
26
26
|
* @param plugin
|
|
27
27
|
*/
|
|
28
28
|
addEventPlugin(plugin: IAnalyticsPlugin): void;
|
|
29
|
-
/**
|
|
30
|
-
* Resolves session consent by prioritizing this._overrideConsent and if not found,
|
|
31
|
-
* getting the value from the consent plugin, if available.
|
|
32
|
-
*
|
|
33
|
-
* @returns {boolean} Whether the session has consent to track analytics or not.
|
|
34
|
-
*/
|
|
35
|
-
private __hasConsent;
|
|
36
29
|
/**
|
|
37
30
|
* Send an Event to all plugins
|
|
38
31
|
*
|
|
39
32
|
* @param eventData
|
|
40
33
|
*/
|
|
41
|
-
sendEvent(eventData:
|
|
34
|
+
sendEvent(eventData: AnalyticsEvent): void;
|
|
42
35
|
/**
|
|
43
36
|
* Returns an IConsentPlugin if something is passed to it. Returns null if we can't find the plugin named.
|
|
44
37
|
* @param consentPluginName
|