@epigraph/epigraph-std-lib 4.2.0 → 4.3.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
|
|
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.OnetrustActiveGroup!==void 0){let e=window.OnetrustActiveGroup;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,4 +1,4 @@
|
|
|
1
|
-
const d = Symbol("data"), u = Symbol("next"),
|
|
1
|
+
const d = Symbol("data"), u = Symbol("next"), v = class y {
|
|
2
2
|
constructor(e) {
|
|
3
3
|
this[d] = e, this[u] = null;
|
|
4
4
|
}
|
|
@@ -16,7 +16,7 @@ const d = Symbol("data"), u = Symbol("next"), w = class y {
|
|
|
16
16
|
return this[u];
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
let g =
|
|
19
|
+
let g = v;
|
|
20
20
|
const h = Symbol("head");
|
|
21
21
|
class m {
|
|
22
22
|
constructor() {
|
|
@@ -62,7 +62,7 @@ class l {
|
|
|
62
62
|
return this[o]--, e;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
class
|
|
65
|
+
class L {
|
|
66
66
|
constructor(e, t, n, s) {
|
|
67
67
|
this.name = this.pluginName = "GA3-PLUGIN", this.trackingID = e, this.verboseLogging = t, this.user = n, this.trackerName = s, this.queue = new l(), this.trackerInterval = 0, this.trackerCreated = !1;
|
|
68
68
|
}
|
|
@@ -145,7 +145,7 @@ class I {
|
|
|
145
145
|
}, 1e3);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
class
|
|
148
|
+
class I {
|
|
149
149
|
constructor(e, t) {
|
|
150
150
|
this.name = this.pluginName = "GA4-PLUGIN", this.trackingID = e, this.verboseLogging = t, this.queue = new l(), this.dataLayer = window.dataLayer, this.dataLayerName = "dataLayer", this.setupDataLayer(), this.initGtag(this.dataLayerName, this.trackingID);
|
|
151
151
|
}
|
|
@@ -155,9 +155,9 @@ class A {
|
|
|
155
155
|
t && (this.dataLayerName = t, this.dataLayer = window[t]);
|
|
156
156
|
}
|
|
157
157
|
initGtag(e = "dataLayer", t) {
|
|
158
|
-
typeof window.gtag != "function" && (window.gtag = function() {
|
|
159
|
-
window[
|
|
160
|
-
});
|
|
158
|
+
window.epgDataLayerName = e, typeof window.gtag != "function" && (window.gtag = function() {
|
|
159
|
+
window[window.epgDataLayerName].push(arguments);
|
|
160
|
+
}, window.gtag("js", /* @__PURE__ */ new Date()), window.gtag("config", t, { send_page_view: !1 }));
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* This function will send an Event to GA3.
|
|
@@ -194,13 +194,13 @@ class A {
|
|
|
194
194
|
};
|
|
195
195
|
if ("parameters" in n && Object.assign(s, n.parameters), JSON.stringify(s).length > 459)
|
|
196
196
|
try {
|
|
197
|
-
let
|
|
197
|
+
let r = await this.sendGA4LongParameters(s);
|
|
198
198
|
s = {
|
|
199
199
|
send_to: this.trackingID,
|
|
200
200
|
event_action: n.action,
|
|
201
201
|
event_category: n.category,
|
|
202
202
|
event_label: n.label,
|
|
203
|
-
epg_event_tag:
|
|
203
|
+
epg_event_tag: r
|
|
204
204
|
};
|
|
205
205
|
} catch {
|
|
206
206
|
}
|
|
@@ -238,8 +238,8 @@ class A {
|
|
|
238
238
|
body: JSON.stringify(n)
|
|
239
239
|
});
|
|
240
240
|
if (s.ok) {
|
|
241
|
-
const
|
|
242
|
-
return
|
|
241
|
+
const a = await s.json();
|
|
242
|
+
return a && a.id ? a.id : "";
|
|
243
243
|
} else
|
|
244
244
|
return "";
|
|
245
245
|
} catch {
|
|
@@ -251,20 +251,20 @@ class A {
|
|
|
251
251
|
for (const n of t) {
|
|
252
252
|
const s = n.getAttribute("src");
|
|
253
253
|
if (s && s.includes(e)) {
|
|
254
|
-
const
|
|
254
|
+
const a = new URL(s, location.href), r = Object.fromEntries(a.searchParams.entries());
|
|
255
255
|
return {
|
|
256
|
-
fullSrc:
|
|
257
|
-
id:
|
|
258
|
-
l:
|
|
256
|
+
fullSrc: a.href,
|
|
257
|
+
id: r.id || void 0,
|
|
258
|
+
l: r.l || void 0
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
return null;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
class
|
|
266
|
-
constructor(e, t, n, s,
|
|
267
|
-
this.sessionId = t, this.xPath = n, this.name = this.pluginName = "NEXUS-PLUGIN", this.trackingID = e, this.verboseLogging = s, this.queue = new l(), this.url =
|
|
265
|
+
class A {
|
|
266
|
+
constructor(e, t, n, s, a = !1) {
|
|
267
|
+
this.sessionId = t, this.xPath = n, this.name = this.pluginName = "NEXUS-PLUGIN", this.trackingID = e, this.verboseLogging = s, this.queue = new l(), this.url = a ? "https://nexus.epigraph.dev/api/analytics/event" : "https://api.myepigraph.com/api/analytics/event";
|
|
268
268
|
}
|
|
269
269
|
async sendEvent(e, t) {
|
|
270
270
|
this.queue.enqueue(e);
|
|
@@ -346,12 +346,12 @@ var p = /* @__PURE__ */ ((i) => (i.OneTrust = "onetrust", i))(p || {});
|
|
|
346
346
|
* See the License for the specific language governing permissions and
|
|
347
347
|
* limitations under the License.
|
|
348
348
|
*/
|
|
349
|
-
var
|
|
349
|
+
var w;
|
|
350
350
|
const c = Symbol("analyticsPluginsMap");
|
|
351
|
-
|
|
351
|
+
w = c;
|
|
352
352
|
class S {
|
|
353
353
|
constructor(e, t) {
|
|
354
|
-
this[
|
|
354
|
+
this[w] = /* @__PURE__ */ new Map(), this._consentPlugin = null, e && t && (this._consentPlugin = this.buildConsentPlugin(e, t));
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
357
|
* Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
|
|
@@ -389,8 +389,8 @@ class S {
|
|
|
389
389
|
export {
|
|
390
390
|
p as ConsentPluginNames,
|
|
391
391
|
S as EpigraphAnalytics,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
L as GA3AnalyticsPlugin,
|
|
393
|
+
I as GA4AnalyticsPlugin,
|
|
394
|
+
A as NexusAnalyticsPlugin,
|
|
395
395
|
q as OneTrustConsentPlugin
|
|
396
396
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare enum QUERY_PARAMETER_ACTION_NAMES {
|
|
2
2
|
AR = "ar"
|
|
3
3
|
}
|
|
4
|
-
export declare
|
|
4
|
+
export declare enum QUERY_PARAMETER_NAMES {
|
|
5
5
|
type = "t",
|
|
6
6
|
identifierType = "idt",
|
|
7
7
|
identifier = "id",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epigraph/epigraph-std-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/epigraph-std-lib.cjs",
|
|
6
6
|
"module": "./dist/epigraph-std-lib.js",
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
"@types/google.analytics": "^0.0.42",
|
|
39
39
|
"@types/gtag.js": "^0.0.20"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|