@epigraph/epigraph-std-lib 4.7.0-alpha → 4.7.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/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 +228 -812
- 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 -82
- package/dist/EpigraphLibs/EpigraphAnalytics/plugins/nexus-analytics-plugin.d.ts +7 -24
- package/dist/epigraph-std-lib.cjs +1 -1
- package/dist/epigraph-std-lib.js +38 -60
- package/package.json +1 -1
- package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalyticsEventLibrary.d.ts +0 -196
- package/dist/EpigraphLibs/EpigraphAnalytics/generics/epigraph-notifier.d.ts +0 -17
|
@@ -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 h=(s=>(s.UNAVAILABLE="unavailable",s.AVAILABLE="available",s.RESTRICTED="restricted",s))(h||{});const E=Symbol("data"),l=Symbol("next"),C=class N{constructor(t){this[E]=t,this[l]=null}get data(){return this[E]}set next(t){if(!(t instanceof N)&&t!==null)throw new Error("This node is not an instance of the custom class 'Node'.");this[l]=t}get next(){return this[l]}};let v=C;const d=Symbol("head");class O{constructor(){this[d]=null}set head(t){this[d]=t}get head(){return this[d]}addToTail(t){let e=this.head;if(e){for(;e.next!==null;)e=e?.next;return e.next=new v(t)}return this.head=new v(t)}removeHead(){const t=this.head;if(t)return this.head=t.next,t.data}}const m=Symbol("queue"),p=Symbol("size");class f{constructor(){this[m]=new O,this[p]=0}get queue(){return this[m]}get size(){return this[p]}enqueue(t){this.queue.addToTail(t),this[p]++}dequeue(){const t=this.queue.removeHead();return this[p]--,t}}class u{static{this.NOTIFICATION_NAME="epg-notification"}static{this.ACTION_SEND_EVENT="send-event"}static{this.ACTION_INITIALIZED="initialized"}static{this.ACTION_FAILED_INITIALIZATION="initialization-failed"}constructor(t,e,i,n,r,o){this._pluginName=t,this._trackingId=e,this._experienceId=i,this._solution=n,this._initializer=r,this._status=o}updateStatus(t){this._status=t}updateInitializer(t){this._initializer=t}notify(t,e){console.log("Notifying",t,e);const i={pluginName:this._pluginName,trackingId:this._trackingId,experienceId:this._experienceId,solution:this._solution,initializer:this._initializer,status:this._status,action:t,eventDetails:e};window.dispatchEvent(new CustomEvent("epg-notification",{detail:i}))}}class S{constructor({trackingID:t,experienceID:e,solution:i,verboseLogging:n=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.__initializationAttempts=0,this.__lastInitializationAttempt=performance.now(),this.__maxInitializationAttempts=10,this.__initializationRetryDelay=2e3,this.__isInitialized=!1,this.__initializationMethod="NONE",this.__nexusFailureReported=!1,this.name=this.pluginName="GA4-PLUGIN",this.trackingID=t,this.experienceID=e,this.solution=i,this.verboseLogging=n,this.__queue=new f,this.__epigraphNotifier=new u(this.pluginName,this.pluginName,this.experienceID,this.solution,this.__initializationMethod,this.__status),this.initializePlugin()}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return`${this.name}-${this.trackingID}`}setupPlugin(){this.__isInitialized&&this.dataLayer!==void 0&&this.dequeueAndSendEvents()}async sendEvent(t,e){if(this.__queue.enqueue(t),!e){this.__status=h.RESTRICTED;return}if(!this.__isInitialized){this.logger("Cannot send analytics event: dataLayer not defined or plugin not initialized.");return}try{await this.dequeueAndSendEvents()}catch(i){this.logger(i),await this.reportFailureToNexus("EVENT_SEND_ERROR",i?.toString()||"Unknown error")}}initializePlugin(){if(this.__isInitialized)return;if(this.__initializationAttempts>=this.__maxInitializationAttempts){this.__nexusFailureReported||(this.reportFailureToNexus("MAX_INITIALIZATION_ATTEMPTS","Maximum initialization attempts reached"),this.__nexusFailureReported=!0,this.__epigraphNotifier.notify(u.ACTION_FAILED_INITIALIZATION,{}));return}const t=performance.now();if(this.__initializationAttempts>0&&t-this.__lastInitializationAttempt<this.__initializationRetryDelay)return;this.__lastInitializationAttempt=t,this.__initializationAttempts++;const e=this.detectAndSetupAnalytics();e.success?(this.__isInitialized=!0,this.__status=h.AVAILABLE,this.__initializationMethod=e.method,this.dataLayerName=e.dataLayerName,this.dataLayer=window[this.dataLayerName],this.logger(`Successfully initialized ${e.method} with dataLayer: ${this.dataLayerName}`),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{}),this.__queue.size>0&&this.dequeueAndSendEvents()):(this.logger(`Initialization attempt ${this.__initializationAttempts} failed: ${e.error}`),this.__initializationAttempts<this.__maxInitializationAttempts&&setTimeout(()=>{this.initializePlugin()},this.__initializationRetryDelay))}detectAndSetupAnalytics(){const t=this.detectGTM();if(t)return this.logger(`GTM detected with container ID: ${t.containerId}`),this.__epigraphNotifier.updateInitializer("GTM"),{success:!0,method:"GTM",dataLayerName:t.dataLayerName};const e=this.findGA4Info(this.trackingID);if(e){const i=e.l||"dataLayer";return this.logger(`GA4 script found, setting up with dataLayer: ${i}`),this.__epigraphNotifier.updateInitializer("GA4"),{success:!0,method:"GA4",dataLayerName:i}}return{success:!1,method:"NONE",dataLayerName:"dataLayer",error:"No analytics setup found and unable to create one"}}detectGTM(){const t=document.querySelectorAll('script[src*="googletagmanager.com/gtm"]');for(const e of Array.from(t)){const i=e.getAttribute("src");if(i){const n=i.match(/gtm\.js\?id=([^&]+)/);if(n&&n.length>0){const r=i.match(/&l=([^&]+)/),o=r?r[1]:"dataLayer";return{containerId:n[1],dataLayerName:o}}}}return null}async dequeueAndSendEvents(){if(!this.__isInitialized||!this.dataLayer)return;let t=this.__queue.size;for(let e=0;e<t;e++){const i=this.__queue.dequeue();try{this.__initializationMethod==="GTM"?(this.sendGTMEvent(i),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${i.eventName}`)):this.__initializationMethod==="GA4"?(this.sendGA4Event(i),this.__sentEventCount++,this.logger(`Analytics event successfully sent via ${this.__initializationMethod}: ${i.eventName}`)):this.__queue.enqueue(i)}catch(n){this.logger(`Error sending event ${i.eventName}: ${n}`),this.__queue.enqueue(i)}}}async sendGTMEvent(t){let e=t.getGTMParameters(this.solution,this.experienceID,this.trackingID);const i=e;this.isValidPayload(e)||(e=await this.convertGTMParametersToEpgEventTag(t.eventName,e)),this.dataLayer&&(this.dataLayer.push(e),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i))}async sendGA4Event(t){let e=t.getGa4Parameters(this.solution,this.experienceID,this.trackingID);const i=e;this.isValidPayload(e)||(e=await this.convertGA4ParametersToEpgEventTag(e)),window.gtag("event",t.eventName,e),this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i)}isValidPayload(t){if(Object.keys(t).length>=25)return!1;for(const[n,r]of Object.entries(t))if(n!=="items"&&(n.length>40||String(r).length>100))return!1;return!0}async convertGTMParametersToEpgEventTag(t,e){try{let i=await this.sendGA4LongParameters(e);return{event:t,epg_event_tag:i,send_to:this.trackingID}}catch{return e}}async convertGA4ParametersToEpgEventTag(t){try{return{epg_event_tag:await this.sendGA4LongParameters(t),send_to:this.trackingID}}catch{return t}}logger(t){this.verboseLogging&&console.warn(t)}async sendGA4LongParameters(t){const e="https://api.myepigraph.com/api/analytics/ga4/custom",i={parameters:t};try{const n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(i)});return n.ok?(await n.json())?.id??"":""}catch{return""}}async reportFailureToNexus(t,e){try{const i={plugin:"GA4",trackingId:this.trackingID,solution:this.solution,experienceId:this.experienceID,failureType:t,errorMessage:e,timestamp:new Date().toISOString(),url:window.location.href,userAgent:navigator.userAgent};this.logger(`Failure reported to Nexus: ${JSON.stringify(i)}`)}catch(i){this.logger(`Error reporting failure to Nexus: ${i}`)}}findGA4Info(t){if(window.google_tag_manager&&window.google_tag_manager[t]){const i=window.google_tag_manager[t];if(i&&i.dataLayerName)return{fullSrc:"",id:t,l:i.dataLayerName}}const e=document.querySelectorAll("script[src]");for(const i of e){const n=i.getAttribute("src");if(n&&n.includes(t)){const r=new URL(n,location.href),o=Object.fromEntries(r.searchParams.entries());return{fullSrc:r.href,id:o.id||void 0,l:o.l||void 0}}}return null}}class R{constructor({trackingID:t,experienceID:e,solution:i,sessionId:n,xPath:r,verboseLogging:o=!1,sendToStaging:P=!1}){this.__status=h.UNAVAILABLE,this.__sentEventCount=0,this.sessionId=n,this.xPath=r,this.name=this.pluginName="NEXUS-PLUGIN",this.trackingID=t,this.experienceID=e,this.solution=i,this.verboseLogging=o,this.__queue=new f,this.url=P?"https://nexus.epigraph.dev/api/analytics/event":"https://api.myepigraph.com/api/analytics/event",this.__status=h.AVAILABLE,this.__epigraphNotifier=new u(this.pluginName,this.trackingID,this.experienceID,this.solution,"NEXUS",this.__status),this.__epigraphNotifier.notify(u.ACTION_INITIALIZED,{})}getStatus(){return this.__status}setStatus(t){this.__status=t,this.__epigraphNotifier.updateStatus(t)}getPendingEventCount(){return this.__queue.size}getSentEventCount(){return this.__sentEventCount}getTotalEventCount(){return this.getPendingEventCount()+this.getSentEventCount()}getUniquePluginIdentifier(){return this.name+"-"+this.trackingID}setupPlugin(){}async sendEvent(t,e){if(this.__queue.enqueue(t),!e){this.__status=h.RESTRICTED,this.__epigraphNotifier.updateStatus(this.__status);return}await this.dequeueAndSendEvents()}async dequeueAndSendEvents(){for(let t=0;t<this.__queue.size;t++){const e=this.__queue.dequeue(),i={send_to:this.trackingID,experience_id:this.experienceID,solution:this.solution,event:e.eventName,parameters:e.getNexusParameters()};try{return(await fetch(this.url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","EPG-SESSION-ID":this.sessionId,"EPG-XPATH":this.xPath,Origin:typeof window<"u"?window.location.origin:""},body:JSON.stringify(i)})).ok&&this.__epigraphNotifier.notify(u.ACTION_SEND_EVENT,i),""}catch{return""}this.__sentEventCount++}return""}}class I{constructor(t){this.consentSet=!1,this.consent=!1,this.pluginName="OneTrustConsentPlugin",this.consentIdentifier=t,this.consent=!1,this.addConsentChangedListener()}hasConsent(){if(this.consentSet)return this.consent;if(window.OnetrustActiveGroups!==void 0){let t=window.OnetrustActiveGroups;t!==void 0&&t.split(",").forEach(i=>{i===this.consentIdentifier&&(this.consent=!0,this.consentSet=!0)})}return this.consent}addConsentChangedListener(){window.addEventListener("load",()=>{this.hasConsent(),window.OneTrust!==void 0&&typeof window.OneTrust=="object"&&window.OneTrust.OnConsentChanged(()=>{this.consentSet=!1,this.hasConsent()})})}}var g=(s=>(s.OneTrust="onetrust",s))(g||{});class a{constructor({eventName:t,interactiveEvent:e,customParameters:i}){this.eventName=t,this.interactiveEvent=e,this.customParameters=i}getGa4Parameters(t,e,i){let n={solution:t,experience_id:e,interactive_event:this.interactiveEvent,send_to:i};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getGTMParameters(t,e,i){let n={solution:t,experience_id:e,event:this.eventName,interactive_event:this.interactiveEvent,send_to:i};return n=Object.assign(n,JSON.parse(JSON.stringify(this.customParameters))),n}getNexusParameters(){let t={interactive_event:this.interactiveEvent};return t=Object.assign(t,JSON.parse(JSON.stringify(this.customParameters))),t}}const A={AR:"ar",QR:"qr",INFO:"info",DOWNLOAD:"download",PREVIEW_CART:"preview_cart",HOTSPOT_PANEL:"hotspot_panel",SHARE_MODAL:"share_modal",RESTART_MODAL:"restart_modal",REMOVE_MODAL:"remove_modal",LOAD_PRECONFIG_MODAL:"load_preconfig_modal",MOVE_MODAL:"move_modal",OUT_OF_STOCK_MODAL:"out_of_stock_modal"},T={AUTO:"auto",BUTTON:"button",HOTSPOT:"hotspot",GESTURE:"gesture"},_={USD:"USD",EUR:"EUR",GBP:"GBP",CAD:"CAD"};class L extends a{constructor(t){super({eventName:"epigraph_ar_requested",interactiveEvent:!0,customParameters:{items:t}})}}class w extends a{constructor(t){super({eventName:"epigraph_module_loading",interactiveEvent:!1,customParameters:{is_pre_config:t}})}}class x extends a{constructor(t,e){super({eventName:"epigraph_module_ready",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e}})}}class D extends a{constructor(t,e,i){super({eventName:"epigraph_module_failed",interactiveEvent:!1,customParameters:{is_pre_config:t,load_time_ms:e,error_type:i}})}}class z extends a{constructor(t){super({eventName:"epigraph_module_closed",interactiveEvent:!0,customParameters:{items:t}})}}class M extends a{static{this.SUPPORT_TYPE={AR:"ar",QR:"qr",WEBGL2:"webgl2"}}constructor(t,e={}){super({eventName:"epigraph_support_detected",interactiveEvent:!1,customParameters:{support_type:t,device_capabilities:e}})}}class G extends a{static{this.BUTTON_TYPE={AR_VIEW:"ar_view",DIMENSION_SHOW:"dimension_show",DIMENSION_HIDE:"dimension_hide",HOTSPOTS_SHOW:"hotspots_show",HOTSPOTS_HIDE:"hotspots_hide",HELP_SHOW:"help_show",HELP_HIDE:"help_hide",HOTSPOT_ENTER:"hotspot_enter",HOTSPOT_EXIT:"hotspot_exit",SHARE:"share",PDF_DOWNLOAD:"pdf_download",COPY:"copy",RESTART:"restart",INSTRUCTIONS_SHOW:"show_instructions",REVIEW_CART:"review_cart",SHOP_NOW:"shop_now",SUB_CATEGORY:"sub_category",NEXT_STEP:"next_step",PREVIOUS_STEP:"previous_step"}}constructor(t,e){super({eventName:"epigraph_button_click",interactiveEvent:!0,customParameters:{button_type:t,button_name:e}})}}class q extends a{static{this.PANEL_TYPE=A}static{this.TRIGGER_SOURCE=T}constructor(t,e,i,n){super({eventName:"epigraph_panel_opened",interactiveEvent:t,customParameters:{items:n,panel_type:e,trigger_source:i}})}}class b extends a{static{this.PANEL_TYPE=A}static{this.TRIGGER_SOURCE=T}constructor(t,e,i,n){super({eventName:"epigraph_panel_closed",interactiveEvent:t,customParameters:{items:n,panel_type:e,trigger_source:i}})}}class U extends a{constructor(t){super({eventName:"epigraph_add_to_favourites",interactiveEvent:!0,customParameters:{items:t}})}}class k extends a{static{this.ACTION_PERFORMED={ZOOM:"zoom",ROTATE:"rotate"}}constructor(t){super({eventName:"epigraph_keyboard_interaction",interactiveEvent:!0,customParameters:{action_performed:t}})}}class V extends a{static{this.INTERACTION_TYPE={ROTATE:"rotate",ZOOM:"zoom",PAN:"pan"}}constructor(t){super({eventName:"epigraph_touch_interaction",interactiveEvent:!0,customParameters:{interaction_type:t}})}}class $ extends a{static{this.CURRENCY=_}constructor(t,e,i,n,r){super({eventName:"epigraph_item_added",interactiveEvent:t,customParameters:{items:r,value:e,currency:i,quantity:n}})}}class F extends a{constructor(t){super({eventName:"epigraph_item_moved",interactiveEvent:!0,customParameters:{items:t}})}}class H extends a{static{this.CURRENCY=_}constructor(t,e,i,n){super({eventName:"epigraph_item_removed",interactiveEvent:!0,customParameters:{items:n,value:t,currency:e,quantity:i}})}}class B extends a{constructor(t,e){super({eventName:"epigraph_variant_changed",interactiveEvent:!0,customParameters:{items:e,change_type:t}})}}class j extends a{constructor(t,e,i){super({eventName:"epigraph_content_shared",interactiveEvent:!0,customParameters:{items:i,content_type:t,share_destination:e}})}}class Y extends a{static{this.CURRENCY=_}constructor(t,e,i){super({eventName:"epigraph_checkout",interactiveEvent:!0,customParameters:{items:i,value:t,currency:e}})}}class W extends a{static{this.CURRENCY=_}constructor(t,e,i){super({eventName:"epigraph_conversion",interactiveEvent:!0,customParameters:{items:i,value:t,currency:e}})}}class J extends a{constructor(t){super({eventName:"epigraph_changeRate",interactiveEvent:!1,customParameters:{value:t}})}}class Z extends a{constructor(t){super({eventName:"epigraph_completionRate",interactiveEvent:!1,customParameters:{value:t}})}}class X extends a{constructor(t){super({eventName:"epigraph_engagementRate",interactiveEvent:!1,customParameters:{value:t}})}}class K extends a{constructor(t,e,i){super({eventName:t,interactiveEvent:e,customParameters:i})}}/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});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
|