@availity/analytics-core 4.0.3 → 4.0.4
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/CHANGELOG.md +45 -0
- package/dist/index.d.mts +82 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +134 -122
- package/dist/index.mjs +125 -121
- package/package.json +5 -5
- package/project.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [4.0.4](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@4.0.3...@availity/analytics-core@4.0.4) (2023-08-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# 1.0.0 (2023-08-23)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add browser field for output ([0ce7170](https://github.com/Availity/sdk-js/commit/0ce717075a82675b8707e4db0cc07cd4af370f3d))
|
|
15
|
+
* **analytics-core:** added dynamic length of attr key for slicing ([18df607](https://github.com/Availity/sdk-js/commit/18df6076fc38c2f5ab368e8415a5ee531bfde7e0))
|
|
16
|
+
* **analytics-core:** fix non-click events ([fce9b26](https://github.com/Availity/sdk-js/commit/fce9b269534d490e29d3a06d4751b2ce27b0833f))
|
|
17
|
+
* **analytics-core:** fixed function call not found ([2a7af7e](https://github.com/Availity/sdk-js/commit/2a7af7edc37b0e24adf2b2e2506414e3c7ea4cd4))
|
|
18
|
+
* **analytics-core:** moved extra assignments out ([23130f1](https://github.com/Availity/sdk-js/commit/23130f186cdecee22595cb0abe31d293cbb03328))
|
|
19
|
+
* **analytics-core:** recursive getComposedPath calls should be spread ([e39d180](https://github.com/Availity/sdk-js/commit/e39d180d7a0a348b52367bea8a87e6e9b0a98252))
|
|
20
|
+
* **analytics-core:** remove camelcase dep ([fc1be33](https://github.com/Availity/sdk-js/commit/fc1be33682c1de4befc46fa9692816fa5782aa5f))
|
|
21
|
+
* **analytics-core:** revert analytics invalid event method ([e823d2e](https://github.com/Availity/sdk-js/commit/e823d2e92b153bff64e73a45618f26cfe1385e8e))
|
|
22
|
+
* **analytics-core:** update types and error msg ([8c03422](https://github.com/Availity/sdk-js/commit/8c03422b8ced4c60738616905ce98b1523663f83))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Code Refactoring
|
|
26
|
+
|
|
27
|
+
* **analytics-core,api-core,authorizations-core,message-core,native-form,upload-core:** eslint fixes ([00e3395](https://github.com/Availity/sdk-js/commit/00e339595962501c96acf2895650f104d4c49809))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
* build!: switch from lerna to nx and compile to esm with tsup ([c586085](https://github.com/Availity/sdk-js/commit/c5860856ca96b743a0653d335ea00f0889132f7f))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* **analytics-core:** add autotrack ([849909e](https://github.com/Availity/sdk-js/commit/849909e60bc2b7dd521d072029f7d8a6f3653eae))
|
|
36
|
+
* **analytics-core:** add types and tests for util ([62cd19b](https://github.com/Availity/sdk-js/commit/62cd19b5c09cfc74830cae236bb48e18acf9fd42))
|
|
37
|
+
* **analytics-core:** added config object with attribute prefix and recursive ([4b5b9fa](https://github.com/Availity/sdk-js/commit/4b5b9fa0d76bdab1e55d2f18c788bcbbfc6338bc))
|
|
38
|
+
* **analytics-core:** added dma logging service ([18ee923](https://github.com/Availity/sdk-js/commit/18ee923f022caebb81cf9db3c32f016c7420af2f))
|
|
39
|
+
* **analytics-core:** adding dynamic event modifiers ([4d54f43](https://github.com/Availity/sdk-js/commit/4d54f4364ce37437b1ba9186c2e365e8b27e8cd5))
|
|
40
|
+
* **docs:** init commit getting things setup ([f525ff4](https://github.com/Availity/sdk-js/commit/f525ff407f5c807c2aafa4c7dadca1d43034d408))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### BREAKING CHANGES
|
|
44
|
+
|
|
45
|
+
* Drop Internet Explorer support
|
|
46
|
+
* **analytics-core,api-core,authorizations-core,message-core,native-form,upload-core:** .filter()[0] replaced with .find(), .forEach() replaced with for...of
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
5
50
|
## [4.0.3](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@4.0.2...@availity/analytics-core@4.0.3) (2022-06-15)
|
|
6
51
|
|
|
7
52
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
declare class AvAnalytics {
|
|
4
|
+
plugins: any[];
|
|
5
|
+
|
|
6
|
+
attributePrefix: string;
|
|
7
|
+
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
|
|
10
|
+
pageTracking: boolean;
|
|
11
|
+
|
|
12
|
+
isPageTracking: boolean;
|
|
13
|
+
|
|
14
|
+
hasInit: boolean;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
plugins: any | any[],
|
|
18
|
+
promise?: PromiseConstructor,
|
|
19
|
+
pageTracking?: boolean,
|
|
20
|
+
autoTrack?: boolean,
|
|
21
|
+
options?: Record<string, any>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
startAutoTrack(): void;
|
|
25
|
+
|
|
26
|
+
stopAutoTrack(): void;
|
|
27
|
+
|
|
28
|
+
handleEvent(event: any): void;
|
|
29
|
+
|
|
30
|
+
invalidEvent(event: any): boolean;
|
|
31
|
+
|
|
32
|
+
getAnalyticAttrs(elem: any): any;
|
|
33
|
+
|
|
34
|
+
startPageTracking(): void;
|
|
35
|
+
|
|
36
|
+
stopPageTracking(): void;
|
|
37
|
+
|
|
38
|
+
init(): void;
|
|
39
|
+
|
|
40
|
+
setPageTracking(value?: any): void;
|
|
41
|
+
|
|
42
|
+
trackEvent(properties: any): Promise<any[]>;
|
|
43
|
+
|
|
44
|
+
trackPageView(url?: string): Promise<any[]>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
48
|
+
declare class AvAnalyticsPlugin {
|
|
49
|
+
constructor(enabled?: boolean);
|
|
50
|
+
|
|
51
|
+
trackEvent(): any;
|
|
52
|
+
|
|
53
|
+
trackPageView(): any;
|
|
54
|
+
|
|
55
|
+
isEnabled(): boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
59
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
declare class AvSplunkAnalytics extends AvAnalyticsPlugin {
|
|
63
|
+
constructor(AvLogMessages: any, enabled?: boolean);
|
|
64
|
+
|
|
65
|
+
trackEvent(properties: any): any;
|
|
66
|
+
|
|
67
|
+
trackPageView(url: string): any;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
71
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
declare class AvDmaAnalytics extends AvAnalyticsPlugin {
|
|
75
|
+
constructor(AvLogMessages: any, enabled?: boolean);
|
|
76
|
+
|
|
77
|
+
trackEvent(properties: any): any;
|
|
78
|
+
|
|
79
|
+
trackPageView(url: string): any;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { AvAnalytics, AvAnalyticsPlugin, AvDmaAnalytics, AvSplunkAnalytics };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ declare class AvAnalyticsPlugin {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
59
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
declare class AvSplunkAnalytics extends AvAnalyticsPlugin {
|
|
@@ -67,6 +68,7 @@ declare class AvSplunkAnalytics extends AvAnalyticsPlugin {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
71
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
declare class AvDmaAnalytics extends AvAnalyticsPlugin {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -30,8 +31,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
31
|
}
|
|
31
32
|
return to;
|
|
32
33
|
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
34
42
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
|
+
var __publicField = (obj, key, value) => {
|
|
44
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
35
47
|
|
|
36
48
|
// src/index.js
|
|
37
49
|
var src_exports = {};
|
|
@@ -73,6 +85,127 @@ var getComposedPath = (node) => {
|
|
|
73
85
|
// src/analytics.js
|
|
74
86
|
var AvAnalytics = class {
|
|
75
87
|
constructor(plugins, promise = Promise, pageTracking, autoTrack = true, options = {}) {
|
|
88
|
+
__publicField(this, "startAutoTrack", () => {
|
|
89
|
+
document.body.addEventListener("click", this.handleEvent, true);
|
|
90
|
+
document.body.addEventListener("focus", this.handleEvent, true);
|
|
91
|
+
document.body.addEventListener("blur", this.handleEvent, true);
|
|
92
|
+
});
|
|
93
|
+
__publicField(this, "stopAutoTrack", () => {
|
|
94
|
+
document.body.removeEventListener("click", this.handleEvent, true);
|
|
95
|
+
document.body.removeEventListener("focus", this.handleEvent, true);
|
|
96
|
+
document.body.removeEventListener("blur", this.handleEvent, true);
|
|
97
|
+
});
|
|
98
|
+
__publicField(this, "handleEvent", (event) => {
|
|
99
|
+
if (this.invalidEvent(event)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const target = event.target || event.srcElement;
|
|
103
|
+
const path = getComposedPath(event.target);
|
|
104
|
+
let analyticAttrs = {};
|
|
105
|
+
if (this.recursive) {
|
|
106
|
+
for (const pth of path.reverse()) {
|
|
107
|
+
const attrs = this.getAnalyticAttrs(pth);
|
|
108
|
+
analyticAttrs = __spreadValues(__spreadValues({}, analyticAttrs), attrs);
|
|
109
|
+
if (Object.keys(attrs).length > 0) {
|
|
110
|
+
analyticAttrs.elemId = pth.getAttribute("id") || pth.getAttribute("name") || void 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
analyticAttrs = this.getAnalyticAttrs(target);
|
|
115
|
+
}
|
|
116
|
+
const actions = analyticAttrs ? this.eventModifiers.filter((mod) => analyticAttrs[mod] === event.type) : [];
|
|
117
|
+
if (Object.keys(analyticAttrs).length === 0 || this.recursive && actions.length === 0 || actions.length === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
analyticAttrs.action = analyticAttrs.action || event.type;
|
|
121
|
+
analyticAttrs.event = event.type;
|
|
122
|
+
analyticAttrs.elemId = analyticAttrs.elemId || target.getAttribute("id") || target.getAttribute("name") || void 0;
|
|
123
|
+
if (analyticAttrs.elemId === void 0) {
|
|
124
|
+
delete analyticAttrs.elemId;
|
|
125
|
+
}
|
|
126
|
+
for (const key of actions) {
|
|
127
|
+
if (key !== "action" && key !== "event") {
|
|
128
|
+
delete analyticAttrs[key];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.trackEvent(analyticAttrs);
|
|
132
|
+
});
|
|
133
|
+
__publicField(this, "invalidEvent", (event) => isModifiedEvent(event) || event.type === "click" && !isLeftClickEvent(event) || !isValidEventTypeOnTarget(event));
|
|
134
|
+
__publicField(this, "getAnalyticAttrs", (elem) => {
|
|
135
|
+
if (!elem.attributes) {
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
const attrs = elem.attributes;
|
|
139
|
+
const analyticAttrs = {};
|
|
140
|
+
if (elem.nodeType === 1) {
|
|
141
|
+
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
142
|
+
const { name } = attrs[i];
|
|
143
|
+
if (name.indexOf(`${this.attributePrefix}-`) === 0) {
|
|
144
|
+
const camelName = camelCase(name.slice(this.attributePrefix.length + 1));
|
|
145
|
+
analyticAttrs[camelName] = elem.getAttribute(name);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return analyticAttrs;
|
|
150
|
+
});
|
|
151
|
+
__publicField(this, "startPageTracking", () => {
|
|
152
|
+
if (!this.pageListener) {
|
|
153
|
+
this.pageListener = this.trackPageView;
|
|
154
|
+
window.addEventListener("hashchange", this.pageListener, false);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
__publicField(this, "stopPageTracking", () => {
|
|
158
|
+
if (this.pageListener) {
|
|
159
|
+
window.removeEventListener("hashchange", this.pageListener, false);
|
|
160
|
+
delete this.pageListener;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
__publicField(this, "init", () => {
|
|
164
|
+
this.setPageTracking();
|
|
165
|
+
for (const plugin of this.plugins) {
|
|
166
|
+
if (isPluginEnabled(plugin) && typeof plugin.init === "function") {
|
|
167
|
+
plugin.init();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
__publicField(this, "setPageTracking", (value) => {
|
|
172
|
+
if (value != void 0) {
|
|
173
|
+
this.pageTracking = !!value;
|
|
174
|
+
}
|
|
175
|
+
const canPageTrack = typeof this.startPageTracking === "function" && typeof this.stopPageTracking === "function";
|
|
176
|
+
if (canPageTrack && this.pageTracking !== this.isPageTracking) {
|
|
177
|
+
if (this.pageTracking) {
|
|
178
|
+
this.startPageTracking();
|
|
179
|
+
} else {
|
|
180
|
+
this.stopPageTracking();
|
|
181
|
+
}
|
|
182
|
+
this.isPageTracking = this.pageTracking;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
__publicField(this, "trackEvent", (properties) => {
|
|
186
|
+
const promises = [];
|
|
187
|
+
properties.url = properties.url || window.location.href || "N/A";
|
|
188
|
+
for (const plugin of this.plugins) {
|
|
189
|
+
const props = __spreadValues({}, properties);
|
|
190
|
+
if (isPluginEnabled(plugin) && typeof plugin.trackEvent === "function") {
|
|
191
|
+
promises.push(plugin.trackEvent(props));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return this.Promise.all(promises);
|
|
195
|
+
});
|
|
196
|
+
__publicField(this, "trackPageView", (url) => {
|
|
197
|
+
if (typeof url === "object") {
|
|
198
|
+
url = url.newURL;
|
|
199
|
+
}
|
|
200
|
+
url = url || window.location.href;
|
|
201
|
+
const promises = [];
|
|
202
|
+
for (const plugin of this.plugins) {
|
|
203
|
+
if (isPluginEnabled(plugin) && typeof plugin.trackPageView === "function") {
|
|
204
|
+
promises.push(plugin.trackPageView(url));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return this.Promise.all(promises);
|
|
208
|
+
});
|
|
76
209
|
if (!plugins || !promise) {
|
|
77
210
|
throw new Error("[plugins] and [promise] must be defined");
|
|
78
211
|
}
|
|
@@ -92,127 +225,6 @@ var AvAnalytics = class {
|
|
|
92
225
|
this.startAutoTrack();
|
|
93
226
|
}
|
|
94
227
|
}
|
|
95
|
-
startAutoTrack = () => {
|
|
96
|
-
document.body.addEventListener("click", this.handleEvent, true);
|
|
97
|
-
document.body.addEventListener("focus", this.handleEvent, true);
|
|
98
|
-
document.body.addEventListener("blur", this.handleEvent, true);
|
|
99
|
-
};
|
|
100
|
-
stopAutoTrack = () => {
|
|
101
|
-
document.body.removeEventListener("click", this.handleEvent, true);
|
|
102
|
-
document.body.removeEventListener("focus", this.handleEvent, true);
|
|
103
|
-
document.body.removeEventListener("blur", this.handleEvent, true);
|
|
104
|
-
};
|
|
105
|
-
handleEvent = (event) => {
|
|
106
|
-
if (this.invalidEvent(event)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const target = event.target || event.srcElement;
|
|
110
|
-
const path = getComposedPath(event.target);
|
|
111
|
-
let analyticAttrs = {};
|
|
112
|
-
if (this.recursive) {
|
|
113
|
-
for (const pth of path.reverse()) {
|
|
114
|
-
const attrs = this.getAnalyticAttrs(pth);
|
|
115
|
-
analyticAttrs = __spreadValues(__spreadValues({}, analyticAttrs), attrs);
|
|
116
|
-
if (Object.keys(attrs).length > 0) {
|
|
117
|
-
analyticAttrs.elemId = pth.getAttribute("id") || pth.getAttribute("name") || void 0;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
analyticAttrs = this.getAnalyticAttrs(target);
|
|
122
|
-
}
|
|
123
|
-
const actions = analyticAttrs ? this.eventModifiers.filter((mod) => analyticAttrs[mod] === event.type) : [];
|
|
124
|
-
if (Object.keys(analyticAttrs).length === 0 || this.recursive && actions.length === 0 || actions.length === 0) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
analyticAttrs.action = analyticAttrs.action || event.type;
|
|
128
|
-
analyticAttrs.event = event.type;
|
|
129
|
-
analyticAttrs.elemId = analyticAttrs.elemId || target.getAttribute("id") || target.getAttribute("name") || void 0;
|
|
130
|
-
if (analyticAttrs.elemId === void 0) {
|
|
131
|
-
delete analyticAttrs.elemId;
|
|
132
|
-
}
|
|
133
|
-
for (const key of actions) {
|
|
134
|
-
if (key !== "action" && key !== "event") {
|
|
135
|
-
delete analyticAttrs[key];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
this.trackEvent(analyticAttrs);
|
|
139
|
-
};
|
|
140
|
-
invalidEvent = (event) => isModifiedEvent(event) || event.type === "click" && !isLeftClickEvent(event) || !isValidEventTypeOnTarget(event);
|
|
141
|
-
getAnalyticAttrs = (elem) => {
|
|
142
|
-
if (!elem.attributes) {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
const attrs = elem.attributes;
|
|
146
|
-
const analyticAttrs = {};
|
|
147
|
-
if (elem.nodeType === 1) {
|
|
148
|
-
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
149
|
-
const { name } = attrs[i];
|
|
150
|
-
if (name.indexOf(`${this.attributePrefix}-`) === 0) {
|
|
151
|
-
const camelName = camelCase(name.slice(this.attributePrefix.length + 1));
|
|
152
|
-
analyticAttrs[camelName] = elem.getAttribute(name);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return analyticAttrs;
|
|
157
|
-
};
|
|
158
|
-
startPageTracking = () => {
|
|
159
|
-
if (!this.pageListener) {
|
|
160
|
-
this.pageListener = this.trackPageView;
|
|
161
|
-
window.addEventListener("hashchange", this.pageListener, false);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
stopPageTracking = () => {
|
|
165
|
-
if (this.pageListener) {
|
|
166
|
-
window.removeEventListener("hashchange", this.pageListener, false);
|
|
167
|
-
delete this.pageListener;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
init = () => {
|
|
171
|
-
this.setPageTracking();
|
|
172
|
-
for (const plugin of this.plugins) {
|
|
173
|
-
if (isPluginEnabled(plugin) && typeof plugin.init === "function") {
|
|
174
|
-
plugin.init();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
setPageTracking = (value) => {
|
|
179
|
-
if (value != void 0) {
|
|
180
|
-
this.pageTracking = !!value;
|
|
181
|
-
}
|
|
182
|
-
const canPageTrack = typeof this.startPageTracking === "function" && typeof this.stopPageTracking === "function";
|
|
183
|
-
if (canPageTrack && this.pageTracking !== this.isPageTracking) {
|
|
184
|
-
if (this.pageTracking) {
|
|
185
|
-
this.startPageTracking();
|
|
186
|
-
} else {
|
|
187
|
-
this.stopPageTracking();
|
|
188
|
-
}
|
|
189
|
-
this.isPageTracking = this.pageTracking;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
trackEvent = (properties) => {
|
|
193
|
-
const promises = [];
|
|
194
|
-
properties.url = properties.url || window.location.href || "N/A";
|
|
195
|
-
for (const plugin of this.plugins) {
|
|
196
|
-
const props = __spreadValues({}, properties);
|
|
197
|
-
if (isPluginEnabled(plugin) && typeof plugin.trackEvent === "function") {
|
|
198
|
-
promises.push(plugin.trackEvent(props));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return this.Promise.all(promises);
|
|
202
|
-
};
|
|
203
|
-
trackPageView = (url) => {
|
|
204
|
-
if (typeof url === "object") {
|
|
205
|
-
url = url.newURL;
|
|
206
|
-
}
|
|
207
|
-
url = url || window.location.href;
|
|
208
|
-
const promises = [];
|
|
209
|
-
for (const plugin of this.plugins) {
|
|
210
|
-
if (isPluginEnabled(plugin) && typeof plugin.trackPageView === "function") {
|
|
211
|
-
promises.push(plugin.trackPageView(url));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return this.Promise.all(promises);
|
|
215
|
-
};
|
|
216
228
|
};
|
|
217
229
|
|
|
218
230
|
// src/plugin.js
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,10 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
+
var __publicField = (obj, key, value) => {
|
|
18
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
17
21
|
|
|
18
22
|
// src/util.js
|
|
19
23
|
var isLeftClickEvent = (event) => event.button === 0;
|
|
@@ -45,6 +49,127 @@ var getComposedPath = (node) => {
|
|
|
45
49
|
// src/analytics.js
|
|
46
50
|
var AvAnalytics = class {
|
|
47
51
|
constructor(plugins, promise = Promise, pageTracking, autoTrack = true, options = {}) {
|
|
52
|
+
__publicField(this, "startAutoTrack", () => {
|
|
53
|
+
document.body.addEventListener("click", this.handleEvent, true);
|
|
54
|
+
document.body.addEventListener("focus", this.handleEvent, true);
|
|
55
|
+
document.body.addEventListener("blur", this.handleEvent, true);
|
|
56
|
+
});
|
|
57
|
+
__publicField(this, "stopAutoTrack", () => {
|
|
58
|
+
document.body.removeEventListener("click", this.handleEvent, true);
|
|
59
|
+
document.body.removeEventListener("focus", this.handleEvent, true);
|
|
60
|
+
document.body.removeEventListener("blur", this.handleEvent, true);
|
|
61
|
+
});
|
|
62
|
+
__publicField(this, "handleEvent", (event) => {
|
|
63
|
+
if (this.invalidEvent(event)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const target = event.target || event.srcElement;
|
|
67
|
+
const path = getComposedPath(event.target);
|
|
68
|
+
let analyticAttrs = {};
|
|
69
|
+
if (this.recursive) {
|
|
70
|
+
for (const pth of path.reverse()) {
|
|
71
|
+
const attrs = this.getAnalyticAttrs(pth);
|
|
72
|
+
analyticAttrs = __spreadValues(__spreadValues({}, analyticAttrs), attrs);
|
|
73
|
+
if (Object.keys(attrs).length > 0) {
|
|
74
|
+
analyticAttrs.elemId = pth.getAttribute("id") || pth.getAttribute("name") || void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
analyticAttrs = this.getAnalyticAttrs(target);
|
|
79
|
+
}
|
|
80
|
+
const actions = analyticAttrs ? this.eventModifiers.filter((mod) => analyticAttrs[mod] === event.type) : [];
|
|
81
|
+
if (Object.keys(analyticAttrs).length === 0 || this.recursive && actions.length === 0 || actions.length === 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
analyticAttrs.action = analyticAttrs.action || event.type;
|
|
85
|
+
analyticAttrs.event = event.type;
|
|
86
|
+
analyticAttrs.elemId = analyticAttrs.elemId || target.getAttribute("id") || target.getAttribute("name") || void 0;
|
|
87
|
+
if (analyticAttrs.elemId === void 0) {
|
|
88
|
+
delete analyticAttrs.elemId;
|
|
89
|
+
}
|
|
90
|
+
for (const key of actions) {
|
|
91
|
+
if (key !== "action" && key !== "event") {
|
|
92
|
+
delete analyticAttrs[key];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.trackEvent(analyticAttrs);
|
|
96
|
+
});
|
|
97
|
+
__publicField(this, "invalidEvent", (event) => isModifiedEvent(event) || event.type === "click" && !isLeftClickEvent(event) || !isValidEventTypeOnTarget(event));
|
|
98
|
+
__publicField(this, "getAnalyticAttrs", (elem) => {
|
|
99
|
+
if (!elem.attributes) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
const attrs = elem.attributes;
|
|
103
|
+
const analyticAttrs = {};
|
|
104
|
+
if (elem.nodeType === 1) {
|
|
105
|
+
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
106
|
+
const { name } = attrs[i];
|
|
107
|
+
if (name.indexOf(`${this.attributePrefix}-`) === 0) {
|
|
108
|
+
const camelName = camelCase(name.slice(this.attributePrefix.length + 1));
|
|
109
|
+
analyticAttrs[camelName] = elem.getAttribute(name);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return analyticAttrs;
|
|
114
|
+
});
|
|
115
|
+
__publicField(this, "startPageTracking", () => {
|
|
116
|
+
if (!this.pageListener) {
|
|
117
|
+
this.pageListener = this.trackPageView;
|
|
118
|
+
window.addEventListener("hashchange", this.pageListener, false);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
__publicField(this, "stopPageTracking", () => {
|
|
122
|
+
if (this.pageListener) {
|
|
123
|
+
window.removeEventListener("hashchange", this.pageListener, false);
|
|
124
|
+
delete this.pageListener;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
__publicField(this, "init", () => {
|
|
128
|
+
this.setPageTracking();
|
|
129
|
+
for (const plugin of this.plugins) {
|
|
130
|
+
if (isPluginEnabled(plugin) && typeof plugin.init === "function") {
|
|
131
|
+
plugin.init();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
__publicField(this, "setPageTracking", (value) => {
|
|
136
|
+
if (value != void 0) {
|
|
137
|
+
this.pageTracking = !!value;
|
|
138
|
+
}
|
|
139
|
+
const canPageTrack = typeof this.startPageTracking === "function" && typeof this.stopPageTracking === "function";
|
|
140
|
+
if (canPageTrack && this.pageTracking !== this.isPageTracking) {
|
|
141
|
+
if (this.pageTracking) {
|
|
142
|
+
this.startPageTracking();
|
|
143
|
+
} else {
|
|
144
|
+
this.stopPageTracking();
|
|
145
|
+
}
|
|
146
|
+
this.isPageTracking = this.pageTracking;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
__publicField(this, "trackEvent", (properties) => {
|
|
150
|
+
const promises = [];
|
|
151
|
+
properties.url = properties.url || window.location.href || "N/A";
|
|
152
|
+
for (const plugin of this.plugins) {
|
|
153
|
+
const props = __spreadValues({}, properties);
|
|
154
|
+
if (isPluginEnabled(plugin) && typeof plugin.trackEvent === "function") {
|
|
155
|
+
promises.push(plugin.trackEvent(props));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return this.Promise.all(promises);
|
|
159
|
+
});
|
|
160
|
+
__publicField(this, "trackPageView", (url) => {
|
|
161
|
+
if (typeof url === "object") {
|
|
162
|
+
url = url.newURL;
|
|
163
|
+
}
|
|
164
|
+
url = url || window.location.href;
|
|
165
|
+
const promises = [];
|
|
166
|
+
for (const plugin of this.plugins) {
|
|
167
|
+
if (isPluginEnabled(plugin) && typeof plugin.trackPageView === "function") {
|
|
168
|
+
promises.push(plugin.trackPageView(url));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return this.Promise.all(promises);
|
|
172
|
+
});
|
|
48
173
|
if (!plugins || !promise) {
|
|
49
174
|
throw new Error("[plugins] and [promise] must be defined");
|
|
50
175
|
}
|
|
@@ -64,127 +189,6 @@ var AvAnalytics = class {
|
|
|
64
189
|
this.startAutoTrack();
|
|
65
190
|
}
|
|
66
191
|
}
|
|
67
|
-
startAutoTrack = () => {
|
|
68
|
-
document.body.addEventListener("click", this.handleEvent, true);
|
|
69
|
-
document.body.addEventListener("focus", this.handleEvent, true);
|
|
70
|
-
document.body.addEventListener("blur", this.handleEvent, true);
|
|
71
|
-
};
|
|
72
|
-
stopAutoTrack = () => {
|
|
73
|
-
document.body.removeEventListener("click", this.handleEvent, true);
|
|
74
|
-
document.body.removeEventListener("focus", this.handleEvent, true);
|
|
75
|
-
document.body.removeEventListener("blur", this.handleEvent, true);
|
|
76
|
-
};
|
|
77
|
-
handleEvent = (event) => {
|
|
78
|
-
if (this.invalidEvent(event)) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const target = event.target || event.srcElement;
|
|
82
|
-
const path = getComposedPath(event.target);
|
|
83
|
-
let analyticAttrs = {};
|
|
84
|
-
if (this.recursive) {
|
|
85
|
-
for (const pth of path.reverse()) {
|
|
86
|
-
const attrs = this.getAnalyticAttrs(pth);
|
|
87
|
-
analyticAttrs = __spreadValues(__spreadValues({}, analyticAttrs), attrs);
|
|
88
|
-
if (Object.keys(attrs).length > 0) {
|
|
89
|
-
analyticAttrs.elemId = pth.getAttribute("id") || pth.getAttribute("name") || void 0;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
analyticAttrs = this.getAnalyticAttrs(target);
|
|
94
|
-
}
|
|
95
|
-
const actions = analyticAttrs ? this.eventModifiers.filter((mod) => analyticAttrs[mod] === event.type) : [];
|
|
96
|
-
if (Object.keys(analyticAttrs).length === 0 || this.recursive && actions.length === 0 || actions.length === 0) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
analyticAttrs.action = analyticAttrs.action || event.type;
|
|
100
|
-
analyticAttrs.event = event.type;
|
|
101
|
-
analyticAttrs.elemId = analyticAttrs.elemId || target.getAttribute("id") || target.getAttribute("name") || void 0;
|
|
102
|
-
if (analyticAttrs.elemId === void 0) {
|
|
103
|
-
delete analyticAttrs.elemId;
|
|
104
|
-
}
|
|
105
|
-
for (const key of actions) {
|
|
106
|
-
if (key !== "action" && key !== "event") {
|
|
107
|
-
delete analyticAttrs[key];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
this.trackEvent(analyticAttrs);
|
|
111
|
-
};
|
|
112
|
-
invalidEvent = (event) => isModifiedEvent(event) || event.type === "click" && !isLeftClickEvent(event) || !isValidEventTypeOnTarget(event);
|
|
113
|
-
getAnalyticAttrs = (elem) => {
|
|
114
|
-
if (!elem.attributes) {
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
const attrs = elem.attributes;
|
|
118
|
-
const analyticAttrs = {};
|
|
119
|
-
if (elem.nodeType === 1) {
|
|
120
|
-
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
121
|
-
const { name } = attrs[i];
|
|
122
|
-
if (name.indexOf(`${this.attributePrefix}-`) === 0) {
|
|
123
|
-
const camelName = camelCase(name.slice(this.attributePrefix.length + 1));
|
|
124
|
-
analyticAttrs[camelName] = elem.getAttribute(name);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return analyticAttrs;
|
|
129
|
-
};
|
|
130
|
-
startPageTracking = () => {
|
|
131
|
-
if (!this.pageListener) {
|
|
132
|
-
this.pageListener = this.trackPageView;
|
|
133
|
-
window.addEventListener("hashchange", this.pageListener, false);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
stopPageTracking = () => {
|
|
137
|
-
if (this.pageListener) {
|
|
138
|
-
window.removeEventListener("hashchange", this.pageListener, false);
|
|
139
|
-
delete this.pageListener;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
init = () => {
|
|
143
|
-
this.setPageTracking();
|
|
144
|
-
for (const plugin of this.plugins) {
|
|
145
|
-
if (isPluginEnabled(plugin) && typeof plugin.init === "function") {
|
|
146
|
-
plugin.init();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
setPageTracking = (value) => {
|
|
151
|
-
if (value != void 0) {
|
|
152
|
-
this.pageTracking = !!value;
|
|
153
|
-
}
|
|
154
|
-
const canPageTrack = typeof this.startPageTracking === "function" && typeof this.stopPageTracking === "function";
|
|
155
|
-
if (canPageTrack && this.pageTracking !== this.isPageTracking) {
|
|
156
|
-
if (this.pageTracking) {
|
|
157
|
-
this.startPageTracking();
|
|
158
|
-
} else {
|
|
159
|
-
this.stopPageTracking();
|
|
160
|
-
}
|
|
161
|
-
this.isPageTracking = this.pageTracking;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
trackEvent = (properties) => {
|
|
165
|
-
const promises = [];
|
|
166
|
-
properties.url = properties.url || window.location.href || "N/A";
|
|
167
|
-
for (const plugin of this.plugins) {
|
|
168
|
-
const props = __spreadValues({}, properties);
|
|
169
|
-
if (isPluginEnabled(plugin) && typeof plugin.trackEvent === "function") {
|
|
170
|
-
promises.push(plugin.trackEvent(props));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return this.Promise.all(promises);
|
|
174
|
-
};
|
|
175
|
-
trackPageView = (url) => {
|
|
176
|
-
if (typeof url === "object") {
|
|
177
|
-
url = url.newURL;
|
|
178
|
-
}
|
|
179
|
-
url = url || window.location.href;
|
|
180
|
-
const promises = [];
|
|
181
|
-
for (const plugin of this.plugins) {
|
|
182
|
-
if (isPluginEnabled(plugin) && typeof plugin.trackPageView === "function") {
|
|
183
|
-
promises.push(plugin.trackPageView(url));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return this.Promise.all(promises);
|
|
187
|
-
};
|
|
188
192
|
};
|
|
189
193
|
|
|
190
194
|
// src/plugin.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/analytics-core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Analytics base configuration for sdk-js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"availity",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"publish": "yarn npm publish --tolerate-republish --access public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"yup": "^0.32.
|
|
32
|
+
"yup": "^0.32.11"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@availity/api-axios": "
|
|
36
|
-
"tsup": "^
|
|
37
|
-
"typescript": "^
|
|
35
|
+
"@availity/api-axios": "8.0.3",
|
|
36
|
+
"tsup": "^7.2.0",
|
|
37
|
+
"typescript": "^5.1.6"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
package/project.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"projectType": "library",
|
|
4
4
|
"targets": {
|
|
5
5
|
"test": {
|
|
6
|
-
"executor": "@
|
|
6
|
+
"executor": "@nx/jest:jest",
|
|
7
7
|
"outputs": ["coverage/analytics-core"],
|
|
8
8
|
"options": {
|
|
9
9
|
"jestConfig": "packages/analytics-core/jest.config.js",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"executor": "@jscutlery/semver:version",
|
|
15
15
|
"options": {
|
|
16
16
|
"preset": "angular",
|
|
17
|
-
"commitMessageFormat": "chore(
|
|
18
|
-
"tagPrefix": "@availity
|
|
17
|
+
"commitMessageFormat": "chore({projectName}): release version ${version} [skip ci]",
|
|
18
|
+
"tagPrefix": "@availity/{projectName}@",
|
|
19
19
|
"baseBranch": "master"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"lint": {
|
|
23
|
-
"executor": "@
|
|
23
|
+
"executor": "@nx/linter:eslint",
|
|
24
24
|
"options": {
|
|
25
25
|
"eslintConfig": ".eslintrc.yaml",
|
|
26
26
|
"lintFilePatterns": ["packages/analytics-core/**/*.{js,ts}"],
|