@epigraph/epigraph-std-lib 4.4.0 → 4.4.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
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.
|
|
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
|
*
|
|
@@ -313,8 +313,8 @@ class q {
|
|
|
313
313
|
hasConsent() {
|
|
314
314
|
if (this.consentSet)
|
|
315
315
|
return this.consent;
|
|
316
|
-
if (window.
|
|
317
|
-
let e = window.
|
|
316
|
+
if (window.OnetrustActiveGroups !== void 0) {
|
|
317
|
+
let e = window.OnetrustActiveGroups;
|
|
318
318
|
e !== void 0 && e.split(",").forEach((n) => {
|
|
319
319
|
n === this.consentIdentifier && (this.consent = !0, this.consentSet = !0);
|
|
320
320
|
});
|