@epigraph/epigraph-std-lib 3.3.1-alpha → 4.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -6
- package/dist/Epigraph/epigraph.d.ts +2 -2
- package/dist/Epigraph/epigraph.js +178 -0
- package/dist/EpigraphLibs/EpigraphLogger/epigraphLogger.d.ts +3 -4
- package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.d.ts +1 -1
- package/dist/EpigraphLibs/epigraphAnalytics.js +399 -0
- package/dist/EpigraphLibs/epigraphLogger.js +199 -0
- package/dist/EpigraphLibs/epigraphNexusApi.js +153 -0
- package/dist/EpigraphLibs/epigraphQrCodeGenerator.js +938 -0
- package/dist/EpigraphLibs/epigraphResultFactory.js +28 -0
- package/dist/EpigraphLibs/epigraphUnitsConverter.js +88 -0
- package/dist/EpigraphLibs/epigraphUrlProcessor.js +76 -0
- package/dist/ThirdPartyLibs/modelViewer.d.ts +2 -0
- package/dist/ThirdPartyLibs/modelViewer.js +8608 -0
- package/dist/ThirdPartyLibs/{thirdPartyLibs.d.ts → threejs.d.ts} +0 -2
- package/dist/ThirdPartyLibs/threejs.js +800 -0
- package/dist/chunks/VerticalBlurShader.B0rdEBFu.js +26381 -0
- package/dist/epigraph-std-lib.d.ts +1 -3
- package/dist/epigraph-std-lib.js +0 -37462
- package/package.json +76 -11
- package/dist/EpigraphLibs/epigraphLibs.d.ts +0 -9
- /package/dist/EpigraphLibs/EpigraphAnalytics/{EpigraphAnalytics.d.ts → epigraphAnalytics.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ A global object that must only be initialized once per session and provides some
|
|
|
13
13
|
| EpigraphBaseSolutionLitElement | A base class intended to enforce some common functionalities across our solutions, built by extending the LitElement |
|
|
14
14
|
| EpigraphLogger | A logger class that provides a convenient way for logging info, warning or errors in any given session |
|
|
15
15
|
| EpigraphQrCoreGenerator | A Utility class that allows the generation of a QR code from a give string input |
|
|
16
|
-
| EpigraphUnitsConverter |
|
|
17
|
-
| EpigraphUrlProcessor |
|
|
16
|
+
| EpigraphUnitsConverter | |
|
|
17
|
+
| EpigraphUrlProcessor | |
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
### 3rd PARTY LIBRARY EXPORTS
|
|
@@ -23,8 +23,6 @@ A global object that must only be initialized once per session and provides some
|
|
|
23
23
|
|---|---|
|
|
24
24
|
| [three](https://threejs.org/) |  |
|
|
25
25
|
| [model-viewer](https://modelviewer.dev/) |  |
|
|
26
|
-
| [@epigraph/epigraph-analytics](https://www.npmjs.com/package/@epigraph/epigraph-analytics) ||
|
|
27
|
-
| [qr-creator](https://www.npmjs.com/package/qr-creator) ||
|
|
28
26
|
|
|
29
27
|
|
|
30
28
|
# HOW TO:
|
|
@@ -32,8 +30,42 @@ A global object that must only be initialized once per session and provides some
|
|
|
32
30
|
### Add a new EpigraphLibrary:
|
|
33
31
|
1. Create a new directory under lib/EpigraphLibs/`<MyEpigraphLibrary>`
|
|
34
32
|
2. Create the module file/s. Ensure that the names of these files are in camelCase.
|
|
35
|
-
3.
|
|
36
|
-
4.
|
|
33
|
+
3. Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
|
|
34
|
+
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.
|
|
35
|
+
5. Go to package.json:
|
|
36
|
+
- Add the new module entry under exports similar to other entries in that field.
|
|
37
|
+
- Add the new module entry under typesVersions similar to other entries in that field.
|
|
38
|
+
|
|
39
|
+
### Use the library
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// Epigraph Object
|
|
44
|
+
import { Epigraph } from "@epigraph/epigraph-std-lib/dist/Epigraph/epigraph";
|
|
45
|
+
|
|
46
|
+
// Epigraph libs
|
|
47
|
+
import { EpigraphAnalytics } from "@epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics";
|
|
48
|
+
|
|
49
|
+
// Third Party libs
|
|
50
|
+
import { Scene } from "@epigraph/epigraph-std-lib/dist/ThirdPartyLibs/threejs";
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Exported Submodules:
|
|
55
|
+
| Name | Description |
|
|
56
|
+
|---|---|
|
|
57
|
+
| @epigraph/epigraph-std-lib/dist/Epigraph/epigraph | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
|
|
58
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics | An Analytics modules that exports handy ways to log analytics across our solutions |
|
|
59
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphLogger | A Logger modules that exports handy ways to log across our solutions |
|
|
60
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphNexusApi | A Nexus API modules that exports handy ways to interact with the Nexus API across our solutions |
|
|
61
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphQrCodeGenerator | A QR Code generator modules that exports handy ways to generate QR Codes across our solutions |
|
|
62
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphResultFactory | A Result Factory modules that exports handy ways to generate Result objects across our solutions |
|
|
63
|
+
| @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. |
|
|
64
|
+
| @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
|
|
65
|
+
| @epigraph/epigraph-std-lib/dist/ThirdPartyLibs/threejs | A three.js modules that exports the three.js library |
|
|
66
|
+
| @epigraph/epigraph-std-lib/dist/ThirdPartyLibs/modelViewer | A model-viewer modules that exports the model-viewer library |
|
|
67
|
+
|
|
68
|
+
|
|
37
69
|
|
|
38
70
|
### Write a test:
|
|
39
71
|
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:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EpigraphLogger, LoggerModeNames } from '../EpigraphLibs/EpigraphLogger/epigraphLogger';
|
|
2
2
|
import { ENVIRONMENT_TYPE } from './constants/enums';
|
|
3
|
-
import {
|
|
3
|
+
import { EpigraphUrlProcessor } from '../EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor';
|
|
4
4
|
import { EpigraphBaseSolutionTypes, EpigraphBaseSolutionHtmlElement, EpigraphBaseSolutionLitElement } from './epigraphBaseSolution';
|
|
5
5
|
/**
|
|
6
6
|
* Epigraph component is intended to be a global source of truth/tracker in a given session for all of our components.
|
|
@@ -24,7 +24,7 @@ export declare class Epigraph {
|
|
|
24
24
|
constructor(initializer: EpigraphBaseSolutionTypes);
|
|
25
25
|
get isReady(): boolean;
|
|
26
26
|
get logger(): EpigraphLogger;
|
|
27
|
-
get urlProcessor():
|
|
27
|
+
get urlProcessor(): EpigraphUrlProcessor;
|
|
28
28
|
get epigraphSessionId(): string;
|
|
29
29
|
get environment(): ENVIRONMENT_TYPE;
|
|
30
30
|
get initializer(): EpigraphBaseSolutionTypes;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { EpigraphLogger as h, LoggerModeNames as g } from "../EpigraphLibs/epigraphLogger.js";
|
|
2
|
+
import { EpigraphUrlProcessor as l, QUERY_PARAMETER_NAMES as d } from "../EpigraphLibs/epigraphUrlProcessor.js";
|
|
3
|
+
import { LitElement as p } from "lit";
|
|
4
|
+
var o = /* @__PURE__ */ ((r) => (r.DEVELOPMENT = "development", r.STAGING = "staging", r.PRODUCTION = "production", r))(o || {});
|
|
5
|
+
class w extends HTMLElement {
|
|
6
|
+
constructor(e, t) {
|
|
7
|
+
super(), this._isReady = !1, this._elementName = "epigraph-base-solution-html", this._solutionVersion = "", this._loggerContextOverride = "[EPIGRAPH BASE SOLUTION]", this.attachShadow({ mode: "open" }), this._environment = t, this._solutionVersion = e, this._xPath = i.generateXPath(this), this._uuid = i.safeGenerateUuid() ?? this._xPath, new i(this), window.epigraph.logger.info({
|
|
8
|
+
title: "Epigraph Base Solution Ready",
|
|
9
|
+
contextOverride: this._loggerContextOverride
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
get isReady() {
|
|
13
|
+
return this._isReady;
|
|
14
|
+
}
|
|
15
|
+
get environment() {
|
|
16
|
+
return this._environment;
|
|
17
|
+
}
|
|
18
|
+
get elementName() {
|
|
19
|
+
return this._elementName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* This is the npm package version of this solution.
|
|
23
|
+
*/
|
|
24
|
+
get solutionVersion() {
|
|
25
|
+
return this._solutionVersion;
|
|
26
|
+
}
|
|
27
|
+
get uuid() {
|
|
28
|
+
return this._uuid;
|
|
29
|
+
}
|
|
30
|
+
get xPath() {
|
|
31
|
+
return this._xPath;
|
|
32
|
+
}
|
|
33
|
+
disconnectedCallback() {
|
|
34
|
+
window.epigraph.deregisterActiveComponent(this);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class C extends p {
|
|
38
|
+
constructor(e, t) {
|
|
39
|
+
super(), this._isReady = !1, this._elementName = "epigraph-base-solution-lit", this._solutionVersion = "", this._loggerContextOverride = "[EPIGRAPH BASE SOLUTION]", this._environment = t, this._solutionVersion = e, this._xPath = i.generateXPath(this), this._uuid = i.safeGenerateUuid() ?? this._xPath, new i(this), this._isReady = !0, window.epigraph.logger.info({
|
|
40
|
+
title: "Epigraph Base Solution Ready",
|
|
41
|
+
contextOverride: this._loggerContextOverride
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
get isReady() {
|
|
45
|
+
return this._isReady;
|
|
46
|
+
}
|
|
47
|
+
get environment() {
|
|
48
|
+
return this._environment;
|
|
49
|
+
}
|
|
50
|
+
get elementName() {
|
|
51
|
+
return this._elementName;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* This is the npm package version of this solution.
|
|
55
|
+
*/
|
|
56
|
+
get solutionVersion() {
|
|
57
|
+
return this._solutionVersion;
|
|
58
|
+
}
|
|
59
|
+
get uuid() {
|
|
60
|
+
return this._uuid;
|
|
61
|
+
}
|
|
62
|
+
get xPath() {
|
|
63
|
+
return this._xPath;
|
|
64
|
+
}
|
|
65
|
+
disconnectedCallback() {
|
|
66
|
+
window.epigraph.deregisterActiveComponent(this);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class i {
|
|
70
|
+
constructor(e) {
|
|
71
|
+
if (this._loggerContext = "EPIGRAPH", this._isReady = !1, this._logger = new h("EPIGRAPH LOGGER"), this._environment = o.DEVELOPMENT, this._activeComponentsInSession = /* @__PURE__ */ new Map(), this._staleComponentsInSession = /* @__PURE__ */ new Map(), window.epigraph)
|
|
72
|
+
return window.epigraph.registerActiveComponent(e), window.epigraph;
|
|
73
|
+
window.epigraph = this, window.epigraph.registerActiveComponent(e), this.logBranding(), this._initializer = e, this._environment = this._initializer.environment;
|
|
74
|
+
const t = this.getLoggerModeNameFromEnvironment();
|
|
75
|
+
this._logger.setCurrentMode(t), this._urlProcessor = new l(), this.id = i.safeGenerateUuid();
|
|
76
|
+
const n = this._urlProcessor.getParameterInUrl(d.epigraphSessionId);
|
|
77
|
+
this._epigraphSessionId = n ?? i.safeGenerateUuid(), this._logger.info({ title: "Epigraph Object Ready!!", details: this, contextOverride: this._loggerContext }), this._isReady = !0;
|
|
78
|
+
}
|
|
79
|
+
get isReady() {
|
|
80
|
+
return this._isReady;
|
|
81
|
+
}
|
|
82
|
+
get logger() {
|
|
83
|
+
return this._logger;
|
|
84
|
+
}
|
|
85
|
+
get urlProcessor() {
|
|
86
|
+
return this._urlProcessor;
|
|
87
|
+
}
|
|
88
|
+
get epigraphSessionId() {
|
|
89
|
+
return this._epigraphSessionId;
|
|
90
|
+
}
|
|
91
|
+
get environment() {
|
|
92
|
+
return this._environment;
|
|
93
|
+
}
|
|
94
|
+
get initializer() {
|
|
95
|
+
return this._initializer;
|
|
96
|
+
}
|
|
97
|
+
get activeComponentsInSession() {
|
|
98
|
+
return this._activeComponentsInSession;
|
|
99
|
+
}
|
|
100
|
+
get staleComponentsInSession() {
|
|
101
|
+
return this._staleComponentsInSession;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Logs Epigraph Branding in the console to help redirect potential interests in the right direction.
|
|
105
|
+
*/
|
|
106
|
+
logBranding() {
|
|
107
|
+
console.group("Powered by: "), console.log("%cEPIGRAPH", "font-weight: bold; font-size: 50px; text-shadow: 3px 3px 0 rgb(100,100,100)"), console.log("Visit for more details: www.epigraph.us"), console.groupEnd();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Registers a new component that was initialized on this page.
|
|
111
|
+
* This is optional from the perspective of the initialization flow but highly recommend
|
|
112
|
+
* registering any component that gets initialized in this session.
|
|
113
|
+
* Any component that inherits from EpigraphBaseSolution should automatically register itself on initialization.
|
|
114
|
+
*
|
|
115
|
+
* @param {EpigraphBaseSolutionTypes} solutionRef A type of Epigraph base component that is initialized in the session.
|
|
116
|
+
*/
|
|
117
|
+
registerActiveComponent(e) {
|
|
118
|
+
this._activeComponentsInSession.set(e.uuid, e), this._logger.info({ title: "Registered a new Active Component", details: e, contextOverride: this._loggerContext });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* De-Registers a component that was initialized on this page.
|
|
122
|
+
* This is optional from the perspective of the unmount flow but highly recommend
|
|
123
|
+
* de-registering any component that gets removed in this session.
|
|
124
|
+
* Any component that inherits from EpigraphBaseSolution should automatically de-register itself on unmount.
|
|
125
|
+
*
|
|
126
|
+
* @param {EpigraphBaseSolutionTypes} solutionRef A type of Epigraph base component that is initialized in the session.
|
|
127
|
+
*/
|
|
128
|
+
deregisterActiveComponent(e) {
|
|
129
|
+
const t = this._activeComponentsInSession.get(e.uuid);
|
|
130
|
+
t && (this._staleComponentsInSession.set(t.uuid, t), this._activeComponentsInSession.delete(t.uuid), this._logger.info({ title: "Deregistered a new Active Component", details: e, contextOverride: this._loggerContext }));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Gets the mode that the logger should be executed in, based on the runtime environment.
|
|
134
|
+
*
|
|
135
|
+
* @returns {LoggerModeNames} A valid logger mode name.
|
|
136
|
+
*/
|
|
137
|
+
getLoggerModeNameFromEnvironment() {
|
|
138
|
+
let e = g.Dev;
|
|
139
|
+
return this._environment === o.STAGING ? e = g.Staging : this._environment === o.PRODUCTION && (e = g.Release), e;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Generates a random UUID using crypto.randomUUID with a fallback on custom generator,
|
|
143
|
+
* if the first option fails for any reason in an environment.1
|
|
144
|
+
*
|
|
145
|
+
* @returns {string} A random generated ID.
|
|
146
|
+
*/
|
|
147
|
+
static safeGenerateUuid() {
|
|
148
|
+
let e = "";
|
|
149
|
+
try {
|
|
150
|
+
e = crypto.randomUUID();
|
|
151
|
+
} catch {
|
|
152
|
+
console.error("crypto not available. Not generating a UUID");
|
|
153
|
+
}
|
|
154
|
+
return e;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Generates an XPath based on a DOM nodes location on the page.
|
|
158
|
+
*
|
|
159
|
+
* @param {HTMLElement} element The element that we need the XPath for.
|
|
160
|
+
* @returns {string} The generated XPath.
|
|
161
|
+
*/
|
|
162
|
+
static generateXPath(e) {
|
|
163
|
+
let t = "", n = e;
|
|
164
|
+
for (; n; ) {
|
|
165
|
+
let a = 1, s = n.previousSibling;
|
|
166
|
+
for (; s; )
|
|
167
|
+
s.nodeName === n.nodeName && a++, s = s.previousSibling;
|
|
168
|
+
t = `/${n.nodeName.toLowerCase() + (a > 1 ? `[${a}]` : "")}${t}`, n = n.parentNode;
|
|
169
|
+
}
|
|
170
|
+
return t;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
o as ENVIRONMENT_TYPE,
|
|
175
|
+
i as Epigraph,
|
|
176
|
+
w as EpigraphBaseSolutionHtmlElement,
|
|
177
|
+
C as EpigraphBaseSolutionLitElement
|
|
178
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
interface LoggerMode {
|
|
1
|
+
export interface LoggerMode {
|
|
2
2
|
name: string;
|
|
3
3
|
allows: Array<string>;
|
|
4
4
|
}
|
|
5
|
-
interface LoggerModes {
|
|
5
|
+
export interface LoggerModes {
|
|
6
6
|
release: LoggerMode;
|
|
7
7
|
staging: LoggerMode;
|
|
8
8
|
dev: LoggerMode;
|
|
@@ -51,7 +51,7 @@ export interface ILoggerGroup {
|
|
|
51
51
|
* Mode: A logger's mode defines what log types would be automatically executed and
|
|
52
52
|
* what would be ignored.
|
|
53
53
|
*/
|
|
54
|
-
declare class EpigraphLogger {
|
|
54
|
+
export declare class EpigraphLogger {
|
|
55
55
|
context: string;
|
|
56
56
|
private _allModes;
|
|
57
57
|
private _currentMode;
|
|
@@ -153,4 +153,3 @@ declare class EpigraphLogger {
|
|
|
153
153
|
*/
|
|
154
154
|
groupEnd(): void;
|
|
155
155
|
}
|
|
156
|
-
export { EpigraphLogger };
|
|
@@ -8,7 +8,7 @@ export declare const enum QUERY_PARAMETER_NAMES {
|
|
|
8
8
|
epigraphSessionId = "eid",
|
|
9
9
|
action = "a"
|
|
10
10
|
}
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class EpigraphUrlProcessor {
|
|
12
12
|
private _baseUrl;
|
|
13
13
|
constructor(baseUrl?: string);
|
|
14
14
|
get baseUrl(): string;
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
const l = Symbol("data"), u = Symbol("next"), v = class y {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
this[l] = e, this[u] = null;
|
|
4
|
+
}
|
|
5
|
+
get data() {
|
|
6
|
+
return this[l];
|
|
7
|
+
}
|
|
8
|
+
set next(e) {
|
|
9
|
+
if (!(e instanceof y) && e !== null)
|
|
10
|
+
throw new Error(
|
|
11
|
+
"This node is not an instance of the custom class 'Node'."
|
|
12
|
+
);
|
|
13
|
+
this[u] = e;
|
|
14
|
+
}
|
|
15
|
+
get next() {
|
|
16
|
+
return this[u];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
let g = v;
|
|
20
|
+
const h = Symbol("head");
|
|
21
|
+
class m {
|
|
22
|
+
constructor() {
|
|
23
|
+
this[h] = null;
|
|
24
|
+
}
|
|
25
|
+
set head(e) {
|
|
26
|
+
this[h] = e;
|
|
27
|
+
}
|
|
28
|
+
get head() {
|
|
29
|
+
return this[h];
|
|
30
|
+
}
|
|
31
|
+
addToTail(e) {
|
|
32
|
+
let t = this.head;
|
|
33
|
+
if (t) {
|
|
34
|
+
for (; t.next !== null; )
|
|
35
|
+
t = t == null ? void 0 : t.next;
|
|
36
|
+
return t.next = new g(e);
|
|
37
|
+
}
|
|
38
|
+
return this.head = new g(e);
|
|
39
|
+
}
|
|
40
|
+
removeHead() {
|
|
41
|
+
const e = this.head;
|
|
42
|
+
if (e)
|
|
43
|
+
return this.head = e.next, e.data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const f = Symbol("queue"), o = Symbol("size");
|
|
47
|
+
class d {
|
|
48
|
+
constructor() {
|
|
49
|
+
this[f] = new m(), this[o] = 0;
|
|
50
|
+
}
|
|
51
|
+
get queue() {
|
|
52
|
+
return this[f];
|
|
53
|
+
}
|
|
54
|
+
get size() {
|
|
55
|
+
return this[o];
|
|
56
|
+
}
|
|
57
|
+
enqueue(e) {
|
|
58
|
+
this.queue.addToTail(e), this[o]++;
|
|
59
|
+
}
|
|
60
|
+
dequeue() {
|
|
61
|
+
const e = this.queue.removeHead();
|
|
62
|
+
return this[o]--, e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class I {
|
|
66
|
+
constructor(e, t, n, s) {
|
|
67
|
+
this.name = this.pluginName = "GA3-PLUGIN", this.trackingID = e, this.verboseLogging = t, this.user = n, this.trackerName = s, this.queue = new d(), this.trackerInterval = 0, this.trackerCreated = !1;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* This function will send an Event to GA3.
|
|
71
|
+
*
|
|
72
|
+
* @param eventData AnalyticsEvent The event to be tracked
|
|
73
|
+
*/
|
|
74
|
+
sendEvent(e) {
|
|
75
|
+
if (this.queue.enqueue(e), window.ga !== void 0 && typeof ga == "function")
|
|
76
|
+
try {
|
|
77
|
+
this.dequeueAndSendEvents();
|
|
78
|
+
} catch (t) {
|
|
79
|
+
this.logger(t);
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
this.logger("Cannot send Google Analytics 3 event: ga function is not defined.");
|
|
83
|
+
return !0;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Send all events that are in the queue
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
dequeueAndSendEvents() {
|
|
90
|
+
if (this.trackerCreated) {
|
|
91
|
+
let e = this.queue.size;
|
|
92
|
+
for (let t = 0; t < e; t++) {
|
|
93
|
+
const n = this.queue.dequeue();
|
|
94
|
+
ga(
|
|
95
|
+
`${this.trackerName}.send`,
|
|
96
|
+
n.type,
|
|
97
|
+
n.category,
|
|
98
|
+
n.action,
|
|
99
|
+
n.label,
|
|
100
|
+
n.interaction
|
|
101
|
+
), this.logger(`Google Analytics 3 event successfully sent: ${n.action}`);
|
|
102
|
+
}
|
|
103
|
+
} else
|
|
104
|
+
this.logger("Cannot sent Google Analytics 3 event: tracker was not created.");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* GA3 requires that a tracker be created prior to being sent. This is called from the constructor. It is
|
|
108
|
+
* important to note that the promise that is inherently returned is ignored in the constructor at this
|
|
109
|
+
* time. This is due to the events that are added will be queued from the page. This script requires
|
|
110
|
+
* that the GA script has been imported on the page already as it does not check for it today.
|
|
111
|
+
*
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
async createTracker() {
|
|
115
|
+
if (window.ga !== void 0 && typeof ga == "function")
|
|
116
|
+
try {
|
|
117
|
+
ga("create", this.trackingID, "auto", this.trackerName, {
|
|
118
|
+
userId: this.user
|
|
119
|
+
});
|
|
120
|
+
const e = new URL(window.location.href);
|
|
121
|
+
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);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
this.logger(e);
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
this.logger("Error: Cannot create tracker, ga function is not defined.");
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks if verboseLogging is enabled, then logs the error
|
|
130
|
+
* @param err
|
|
131
|
+
*/
|
|
132
|
+
logger(e) {
|
|
133
|
+
this.verboseLogging && console.warn(e);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns a unique plugin identifier so that tracking ID's can be the same across multiple plugins.
|
|
137
|
+
*/
|
|
138
|
+
getUniquePluginIdentifier() {
|
|
139
|
+
return this.pluginName + "-" + this.trackingID;
|
|
140
|
+
}
|
|
141
|
+
setupPlugin() {
|
|
142
|
+
var e = 0;
|
|
143
|
+
this.trackerInterval = window.setInterval(() => {
|
|
144
|
+
this.createTracker(), ++e === 10 && (window.clearInterval(this.trackerInterval), this.logger("Error: Failed to create Google Analytics tracker in the allotted timeframe."));
|
|
145
|
+
}, 1e3);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class A {
|
|
149
|
+
constructor(e, t) {
|
|
150
|
+
this.name = this.pluginName = "GA4-PLUGIN", this.trackingID = e, this.verboseLogging = t, this.queue = new d(), this.dataLayer = window.dataLayer, this.dataLayerName = "dataLayer", this.setupDataLayer(), this.initGtag(this.dataLayerName, this.trackingID);
|
|
151
|
+
}
|
|
152
|
+
setupDataLayer() {
|
|
153
|
+
if (this.dataLayer) return;
|
|
154
|
+
const e = this.findGA4ScriptInfo(this.trackingID), t = e == null ? void 0 : e.l;
|
|
155
|
+
t && (this.dataLayerName = t, this.dataLayer = window[t]);
|
|
156
|
+
}
|
|
157
|
+
initGtag(e = "dataLayer", t) {
|
|
158
|
+
typeof window.gtag != "function" && (window.gtag = function() {
|
|
159
|
+
window[e].push(arguments), gtag("js", /* @__PURE__ */ new Date()), gtag("config", t);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* This function will send an Event to GA3.
|
|
164
|
+
*
|
|
165
|
+
* @param eventData AnalyticsEvent The event to be tracked
|
|
166
|
+
* @param consentPlugin
|
|
167
|
+
*/
|
|
168
|
+
async sendEvent(e, t) {
|
|
169
|
+
this.queue.enqueue(e);
|
|
170
|
+
let n = !0;
|
|
171
|
+
if (t && (n = t.hasConsent()), this.dataLayer !== void 0 && n)
|
|
172
|
+
try {
|
|
173
|
+
await this.dequeueAndSendEvents();
|
|
174
|
+
} catch (s) {
|
|
175
|
+
this.logger(s);
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
this.logger("Cannot send Google Analytics 4 event: dataLayer is not defined.");
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Send all events that are in the queue
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
async dequeueAndSendEvents() {
|
|
185
|
+
let e = this.queue.size;
|
|
186
|
+
for (let t = 0; t < e; t++) {
|
|
187
|
+
const n = this.queue.dequeue();
|
|
188
|
+
let s = {
|
|
189
|
+
send_to: this.trackingID,
|
|
190
|
+
event_action: n.action,
|
|
191
|
+
event_category: n.category,
|
|
192
|
+
event_label: n.label,
|
|
193
|
+
epg_event_tag: ""
|
|
194
|
+
};
|
|
195
|
+
if ("parameters" in n && (s = {
|
|
196
|
+
...s,
|
|
197
|
+
...n.parameters
|
|
198
|
+
}), JSON.stringify(s).length > 459)
|
|
199
|
+
try {
|
|
200
|
+
let a = await this.sendGA4LongParameters(s);
|
|
201
|
+
s = {
|
|
202
|
+
send_to: this.trackingID,
|
|
203
|
+
event_action: n.action,
|
|
204
|
+
event_category: n.category,
|
|
205
|
+
event_label: n.label,
|
|
206
|
+
epg_event_tag: a
|
|
207
|
+
};
|
|
208
|
+
} catch {
|
|
209
|
+
}
|
|
210
|
+
gtag("event", n.action, s), this.logger(`Google Analytics 4 event successfully sent: ${n.action}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Checks if verboseLogging is enabled, then logs the error
|
|
215
|
+
* @param err
|
|
216
|
+
*/
|
|
217
|
+
logger(e) {
|
|
218
|
+
this.verboseLogging && console.warn(e);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Returns a unique plugin identifier so that tracking ID's can be the same across multiple plugins.
|
|
222
|
+
*/
|
|
223
|
+
getUniquePluginIdentifier() {
|
|
224
|
+
return this.name + "-" + this.trackingID;
|
|
225
|
+
}
|
|
226
|
+
setupPlugin() {
|
|
227
|
+
this.dataLayer !== void 0 && this.dequeueAndSendEvents();
|
|
228
|
+
}
|
|
229
|
+
async sendGA4LongParameters(e) {
|
|
230
|
+
const t = "https://api.myepigraph.com/api/analytics/ga4/custom", n = {
|
|
231
|
+
parameters: e
|
|
232
|
+
};
|
|
233
|
+
try {
|
|
234
|
+
const s = await fetch(t, {
|
|
235
|
+
method: "POST",
|
|
236
|
+
// Assuming it's a POST request, adjust if necessary
|
|
237
|
+
headers: {
|
|
238
|
+
"Content-Type": "application/json",
|
|
239
|
+
Accept: "application/json"
|
|
240
|
+
},
|
|
241
|
+
body: JSON.stringify(n)
|
|
242
|
+
});
|
|
243
|
+
if (s.ok) {
|
|
244
|
+
const r = await s.json();
|
|
245
|
+
return r && r.id ? r.id : "";
|
|
246
|
+
} else
|
|
247
|
+
return "";
|
|
248
|
+
} catch {
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
findGA4ScriptInfo(e) {
|
|
253
|
+
const t = document.querySelectorAll("script[src]");
|
|
254
|
+
for (const n of t) {
|
|
255
|
+
const s = n.getAttribute("src");
|
|
256
|
+
if (s && s.includes(e)) {
|
|
257
|
+
const r = new URL(s, location.href), a = Object.fromEntries(r.searchParams.entries());
|
|
258
|
+
return {
|
|
259
|
+
fullSrc: r.href,
|
|
260
|
+
id: a.id || void 0,
|
|
261
|
+
l: a.l || void 0
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
class L {
|
|
269
|
+
constructor(e, t, n, s, r = !1) {
|
|
270
|
+
this.sessionId = t, this.xPath = n, this.name = this.pluginName = "NEXUS-PLUGIN", this.trackingID = e, this.verboseLogging = s, this.queue = new d(), this.url = r ? "https://nexus.epigraph.dev/api/analytics/event" : "https://api.myepigraph.com/api/analytics/event";
|
|
271
|
+
}
|
|
272
|
+
async sendEvent(e, t) {
|
|
273
|
+
this.queue.enqueue(e);
|
|
274
|
+
let n = !0;
|
|
275
|
+
t && (n = t.hasConsent()), n && await this.dequeueAndSendEvents();
|
|
276
|
+
}
|
|
277
|
+
async dequeueAndSendEvents() {
|
|
278
|
+
for (let e = 0; e < this.queue.size; e++) {
|
|
279
|
+
const t = this.queue.dequeue(), n = {
|
|
280
|
+
experience_id: this.trackingID,
|
|
281
|
+
action: t.action,
|
|
282
|
+
parameters: t.parameters
|
|
283
|
+
};
|
|
284
|
+
try {
|
|
285
|
+
return (await fetch(this.url, {
|
|
286
|
+
method: "POST",
|
|
287
|
+
// Assuming it's a POST request, adjust if necessary
|
|
288
|
+
headers: {
|
|
289
|
+
"Content-Type": "application/json",
|
|
290
|
+
Accept: "application/json",
|
|
291
|
+
"EPG-SESSION-ID": this.sessionId,
|
|
292
|
+
"EPG-XPATH": this.xPath,
|
|
293
|
+
Origin: typeof window < "u" ? window.location.origin : ""
|
|
294
|
+
},
|
|
295
|
+
body: JSON.stringify(n)
|
|
296
|
+
})).status === 204, "";
|
|
297
|
+
} catch {
|
|
298
|
+
return "";
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return "";
|
|
302
|
+
}
|
|
303
|
+
getUniquePluginIdentifier() {
|
|
304
|
+
return this.name + "-" + this.trackingID;
|
|
305
|
+
}
|
|
306
|
+
setupPlugin() {
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
class q {
|
|
310
|
+
constructor(e) {
|
|
311
|
+
this.consentSet = !1, this.consent = !1, this.pluginName = "OneTrustConsentPlugin", this.consentIdentifier = e, this.consent = !1, this.addConsentChangedListener();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Checks to see if the user has consented. If this is false, it will block all analytics
|
|
315
|
+
*/
|
|
316
|
+
hasConsent() {
|
|
317
|
+
if (this.consentSet)
|
|
318
|
+
return this.consent;
|
|
319
|
+
if (window.OnetrustActiveGroup !== void 0) {
|
|
320
|
+
let e = window.OnetrustActiveGroup;
|
|
321
|
+
e !== void 0 && e.split(",").forEach((n) => {
|
|
322
|
+
n === this.consentIdentifier && (this.consent = !0, this.consentSet = !0);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return this.consent;
|
|
326
|
+
}
|
|
327
|
+
addConsentChangedListener() {
|
|
328
|
+
window.addEventListener("load", () => {
|
|
329
|
+
this.hasConsent(), window.OneTrust !== void 0 && typeof window.OneTrust == "object" && window.OneTrust.OnConsentChanged(() => {
|
|
330
|
+
this.consentSet = !1, this.hasConsent();
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
var p = /* @__PURE__ */ ((i) => (i.OneTrust = "onetrust", i))(p || {});
|
|
336
|
+
/**
|
|
337
|
+
* @license
|
|
338
|
+
* Copyright (c) 2023 Epigraph LLC. All Rights Reserved.
|
|
339
|
+
*
|
|
340
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
341
|
+
* you may not use this file except in compliance with the License.
|
|
342
|
+
* You may obtain a copy of the License at
|
|
343
|
+
*
|
|
344
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
345
|
+
*
|
|
346
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
347
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
348
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
349
|
+
* See the License for the specific language governing permissions and
|
|
350
|
+
* limitations under the License.
|
|
351
|
+
*/
|
|
352
|
+
var w;
|
|
353
|
+
const c = Symbol("analyticsPluginsMap");
|
|
354
|
+
w = c;
|
|
355
|
+
class S {
|
|
356
|
+
constructor(e, t) {
|
|
357
|
+
this[w] = /* @__PURE__ */ new Map(), this._consentPlugin = null, e && t && (this._consentPlugin = this.buildConsentPlugin(e, t));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
|
|
361
|
+
* by implementing the IAnalyticsPlugin and then adding it via this function. This will also hold only a single
|
|
362
|
+
* instance of a plugin with a given Tracking Identifier.
|
|
363
|
+
*
|
|
364
|
+
* @param plugin
|
|
365
|
+
*/
|
|
366
|
+
addEventPlugin(e) {
|
|
367
|
+
this[c].has(e.getUniquePluginIdentifier()) || (this[c].set(
|
|
368
|
+
e.getUniquePluginIdentifier(),
|
|
369
|
+
e
|
|
370
|
+
), e.setupPlugin());
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Send an Event to all plugins
|
|
374
|
+
*
|
|
375
|
+
* @param eventData
|
|
376
|
+
*/
|
|
377
|
+
sendEvent(e) {
|
|
378
|
+
this[c].forEach((t) => {
|
|
379
|
+
t.sendEvent(e, this._consentPlugin);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Returns an IConsentPlugin if something is passed to it. Returns null if we can't find the plugin named.
|
|
384
|
+
* @param consentPluginName
|
|
385
|
+
* @param consentIdentifier
|
|
386
|
+
* @private
|
|
387
|
+
*/
|
|
388
|
+
buildConsentPlugin(e, t) {
|
|
389
|
+
return e.toLowerCase() === p.OneTrust.toLowerCase() ? new q(t) : null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
export {
|
|
393
|
+
p as ConsentPluginNames,
|
|
394
|
+
S as EpigraphAnalytics,
|
|
395
|
+
I as GA3AnalyticsPlugin,
|
|
396
|
+
A as GA4AnalyticsPlugin,
|
|
397
|
+
L as NexusAnalyticsPlugin,
|
|
398
|
+
q as OneTrustConsentPlugin
|
|
399
|
+
};
|