@availity/analytics-core 3.0.0-alpha.6 → 3.1.2
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 +159 -49
- package/README.md +13 -2
- package/lib/analytics.js +230 -149
- package/lib/dma.js +76 -55
- package/lib/index.js +10 -10
- package/lib/plugin.js +25 -12
- package/lib/splunk.js +38 -18
- package/lib/util.js +73 -0
- package/package.json +11 -2
- package/src/analytics.js +59 -89
- package/src/dma.js +27 -42
- package/src/index.js +4 -6
- package/src/tests/analytics.test.js +4 -4
- package/src/tests/dma.test.js +12 -13
- package/src/tests/util.test.js +53 -0
- package/src/util.js +39 -0
- package/types/analytics.d.ts +33 -0
- package/types/dma.d.ts +11 -0
- package/types/index.d.ts +4 -0
- package/types/plugin.d.ts +11 -0
- package/types/splunk.d.ts +11 -0
- package/lib/tests/analytics.test.js +0 -200
- package/lib/tests/dma.test.js +0 -36
- package/lib/tests/plugin.test.js +0 -21
- package/lib/tests/splunk.test.js +0 -75
package/lib/plugin.js
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports
|
|
8
|
+
exports["default"] = void 0;
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
constructor(enabled = true) {
|
|
10
|
-
this.enabled = !!enabled;
|
|
11
|
-
}
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
var AvAnalyticsPlugin = /*#__PURE__*/function () {
|
|
15
|
+
function AvAnalyticsPlugin() {
|
|
16
|
+
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
17
|
+
(0, _classCallCheck2["default"])(this, AvAnalyticsPlugin);
|
|
18
|
+
this.enabled = !!enabled;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
(0, _createClass2["default"])(AvAnalyticsPlugin, [{
|
|
22
|
+
key: "trackEvent",
|
|
23
|
+
value: function trackEvent() {}
|
|
24
|
+
}, {
|
|
25
|
+
key: "trackPageView",
|
|
26
|
+
value: function trackPageView() {}
|
|
27
|
+
}, {
|
|
28
|
+
key: "isEnabled",
|
|
29
|
+
value: function isEnabled() {
|
|
30
|
+
return this.enabled;
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
return AvAnalyticsPlugin;
|
|
34
|
+
}();
|
|
22
35
|
|
|
23
|
-
exports
|
|
36
|
+
exports["default"] = AvAnalyticsPlugin;
|
package/lib/splunk.js
CHANGED
|
@@ -5,28 +5,48 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
9
17
|
|
|
10
18
|
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
super(enabled);
|
|
15
|
-
this.AvLogMessages = AvLogMessages;
|
|
16
|
-
}
|
|
20
|
+
var AvSplunkAnalytics = /*#__PURE__*/function (_AvAnalyticsPlugin) {
|
|
21
|
+
(0, _inherits2["default"])(AvSplunkAnalytics, _AvAnalyticsPlugin);
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
properties.level = properties.level || 'info';
|
|
20
|
-
return this.AvLogMessages[properties.level](properties);
|
|
21
|
-
}
|
|
23
|
+
var _super = (0, _createSuper2["default"])(AvSplunkAnalytics);
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
event: 'page',
|
|
26
|
-
url: url
|
|
27
|
-
});
|
|
28
|
-
}
|
|
25
|
+
function AvSplunkAnalytics(AvLogMessages, enabled) {
|
|
26
|
+
var _this;
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
(0, _classCallCheck2["default"])(this, AvSplunkAnalytics);
|
|
29
|
+
_this = _super.call(this, enabled);
|
|
30
|
+
_this.AvLogMessages = AvLogMessages;
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
(0, _createClass2["default"])(AvSplunkAnalytics, [{
|
|
35
|
+
key: "trackEvent",
|
|
36
|
+
value: function trackEvent(properties) {
|
|
37
|
+
properties.level = properties.level || 'info';
|
|
38
|
+
return this.AvLogMessages[properties.level](properties);
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
key: "trackPageView",
|
|
42
|
+
value: function trackPageView(url) {
|
|
43
|
+
return this.trackEvent({
|
|
44
|
+
event: 'page',
|
|
45
|
+
url: url
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return AvSplunkAnalytics;
|
|
50
|
+
}(_plugin["default"]);
|
|
51
|
+
|
|
52
|
+
exports["default"] = AvSplunkAnalytics;
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.regexp.exec");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.isValidEventTypeOnTarget = exports.isPluginEnabled = exports.isModifiedEvent = exports.isLeftClickEvent = exports.getComposedPath = exports.camelCase = void 0;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.string.replace.js");
|
|
11
|
+
|
|
12
|
+
var isLeftClickEvent = function isLeftClickEvent(event) {
|
|
13
|
+
return event.button === 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.isLeftClickEvent = isLeftClickEvent;
|
|
17
|
+
|
|
18
|
+
var isModifiedEvent = function isModifiedEvent(event) {
|
|
19
|
+
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.isModifiedEvent = isModifiedEvent;
|
|
23
|
+
var trackMap = {
|
|
24
|
+
select: ['focus', 'blur'],
|
|
25
|
+
textarea: ['focus', 'blur'],
|
|
26
|
+
input: ['focus', 'blur'],
|
|
27
|
+
"default": ['click']
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var isValidEventTypeOnTarget = function isValidEventTypeOnTarget(event) {
|
|
31
|
+
return (trackMap[event.target.nodeName.toLowerCase()] || trackMap["default"]).indexOf(event.type) > -1;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.isValidEventTypeOnTarget = isValidEventTypeOnTarget;
|
|
35
|
+
|
|
36
|
+
var isPluginEnabled = function isPluginEnabled(plugin) {
|
|
37
|
+
return typeof plugin.isEnabled === 'function' ? plugin.isEnabled() : plugin.isEnabled;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.isPluginEnabled = isPluginEnabled;
|
|
41
|
+
|
|
42
|
+
var camelCase = function camelCase(str) {
|
|
43
|
+
return str.replace(/-([\da-z])/gi, function (match, _char) {
|
|
44
|
+
return _char.toUpperCase();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Polyfill for [`Event.composedPath()`][1].
|
|
49
|
+
* https://gist.github.com/kleinfreund/e9787d73776c0e3750dcfcdc89f100ec
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.camelCase = camelCase;
|
|
54
|
+
|
|
55
|
+
var getComposedPath = function getComposedPath(node) {
|
|
56
|
+
var parent;
|
|
57
|
+
|
|
58
|
+
if (node.parentNode) {
|
|
59
|
+
parent = node.parentNode;
|
|
60
|
+
} else if (node.host) {
|
|
61
|
+
parent = node.host;
|
|
62
|
+
} else if (node.defaultView) {
|
|
63
|
+
parent = node.defaultView;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (parent !== undefined) {
|
|
67
|
+
return [node, getComposedPath(parent)];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return [node];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.getComposedPath = getComposedPath;
|
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/analytics-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Analytics base configuration for sdk-js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
7
8
|
"author": "Kasey Powers <kasey.powers@availity.com>",
|
|
8
9
|
"license": "MIT",
|
|
9
10
|
"publishConfig": {
|
|
10
11
|
"access": "public"
|
|
11
12
|
},
|
|
12
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "a247c20c27816eb3e3b68b983d12631a6cadd72b",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@babel/runtime": "^7.10.2",
|
|
16
|
+
"core-js": "^3.12.1",
|
|
17
|
+
"yup": "^0.28.4"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@availity/api-axios": "^6.0.4"
|
|
21
|
+
}
|
|
13
22
|
}
|
package/src/analytics.js
CHANGED
|
@@ -1,57 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
input: ['focus', 'blur'],
|
|
10
|
-
default: ['click'],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const isValidEventTypeOnTarget = event =>
|
|
14
|
-
(trackMap[event.target.nodeName.toLowerCase()] || trackMap.default).indexOf(
|
|
15
|
-
event.type
|
|
16
|
-
) > -1;
|
|
17
|
-
|
|
18
|
-
const isPluginEnabled = plugin =>
|
|
19
|
-
typeof plugin.isEnabled === 'function'
|
|
20
|
-
? plugin.isEnabled()
|
|
21
|
-
: plugin.isEnabled;
|
|
22
|
-
|
|
23
|
-
const camelCase = str =>
|
|
24
|
-
str.replace(/-([a-z\d])/gi, (match, char) => char.toUpperCase());
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Polyfill for [`Event.composedPath()`][1].
|
|
28
|
-
* https://gist.github.com/kleinfreund/e9787d73776c0e3750dcfcdc89f100ec
|
|
29
|
-
*/
|
|
30
|
-
const getComposedPath = node => {
|
|
31
|
-
let parent;
|
|
32
|
-
if (node.parentNode) {
|
|
33
|
-
parent = node.parentNode;
|
|
34
|
-
} else if (node.host) {
|
|
35
|
-
parent = node.host;
|
|
36
|
-
} else if (node.defaultView) {
|
|
37
|
-
parent = node.defaultView;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (parent !== undefined) {
|
|
41
|
-
return [node].concat(getComposedPath(parent));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return [node];
|
|
45
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
camelCase,
|
|
3
|
+
getComposedPath,
|
|
4
|
+
isLeftClickEvent,
|
|
5
|
+
isModifiedEvent,
|
|
6
|
+
isPluginEnabled,
|
|
7
|
+
isValidEventTypeOnTarget,
|
|
8
|
+
} from './util';
|
|
46
9
|
|
|
47
10
|
export default class AvAnalytics {
|
|
48
|
-
constructor(
|
|
49
|
-
plugins,
|
|
50
|
-
promise = Promise,
|
|
51
|
-
pageTracking,
|
|
52
|
-
autoTrack = true,
|
|
53
|
-
options = {}
|
|
54
|
-
) {
|
|
11
|
+
constructor(plugins, promise = Promise, pageTracking, autoTrack = true, options = {}) {
|
|
55
12
|
// if plugins or promise are undefined,
|
|
56
13
|
// or if either is skipped and pageTracking boolean is used in their place
|
|
57
14
|
if (!plugins || !promise) {
|
|
@@ -61,6 +18,12 @@ export default class AvAnalytics {
|
|
|
61
18
|
this.plugins = Array.isArray(plugins) ? plugins : [plugins];
|
|
62
19
|
this.pageTracking = !!pageTracking;
|
|
63
20
|
|
|
21
|
+
if (options.eventModifiers) {
|
|
22
|
+
this.eventModifiers = Array.isArray(options.eventModifiers) ? options.eventModifiers : [options.eventModifiers];
|
|
23
|
+
} else {
|
|
24
|
+
this.eventModifiers = ['action'];
|
|
25
|
+
}
|
|
26
|
+
|
|
64
27
|
this.Promise = promise;
|
|
65
28
|
this.recursive = !!options.recursive;
|
|
66
29
|
this.attributePrefix = options.attributePrefix || 'data-analytics';
|
|
@@ -85,7 +48,7 @@ export default class AvAnalytics {
|
|
|
85
48
|
document.body.removeEventListener('blur', this.handleEvent, true);
|
|
86
49
|
};
|
|
87
50
|
|
|
88
|
-
handleEvent = event => {
|
|
51
|
+
handleEvent = (event) => {
|
|
89
52
|
if (this.invalidEvent(event)) {
|
|
90
53
|
return;
|
|
91
54
|
}
|
|
@@ -96,44 +59,49 @@ export default class AvAnalytics {
|
|
|
96
59
|
|
|
97
60
|
if (this.recursive) {
|
|
98
61
|
// Reverse the array so we pull attributes from top down
|
|
99
|
-
path.reverse()
|
|
62
|
+
for (const pth of path.reverse()) {
|
|
100
63
|
const attrs = this.getAnalyticAttrs(pth);
|
|
101
64
|
|
|
102
65
|
analyticAttrs = { ...analyticAttrs, ...attrs };
|
|
103
66
|
|
|
104
67
|
// To consider using the element it has to have analytics attrs
|
|
105
68
|
if (Object.keys(attrs).length > 0) {
|
|
106
|
-
analyticAttrs.elemId =
|
|
107
|
-
pth.getAttribute('id') || pth.getAttribute('name');
|
|
69
|
+
analyticAttrs.elemId = pth.getAttribute('id') || pth.getAttribute('name') || undefined;
|
|
108
70
|
}
|
|
109
|
-
}
|
|
71
|
+
}
|
|
110
72
|
} else {
|
|
111
73
|
analyticAttrs = this.getAnalyticAttrs(target);
|
|
112
74
|
}
|
|
113
75
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
) {
|
|
76
|
+
const actions = analyticAttrs ? this.eventModifiers.filter((mod) => analyticAttrs[mod] === event.type) : [];
|
|
77
|
+
|
|
78
|
+
if (Object.keys(analyticAttrs).length === 0 || (this.recursive && actions.length === 0) || actions.length === 0) {
|
|
118
79
|
return;
|
|
119
80
|
}
|
|
120
81
|
|
|
121
82
|
analyticAttrs.action = analyticAttrs.action || event.type;
|
|
122
83
|
analyticAttrs.event = event.type;
|
|
123
84
|
analyticAttrs.elemId =
|
|
124
|
-
analyticAttrs.elemId ||
|
|
125
|
-
|
|
126
|
-
|
|
85
|
+
analyticAttrs.elemId || target.getAttribute('id') || target.getAttribute('name') || undefined;
|
|
86
|
+
|
|
87
|
+
if (analyticAttrs.elemId === undefined) {
|
|
88
|
+
delete analyticAttrs.elemId;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// remove keys for the click listeners
|
|
92
|
+
for (const key of actions) {
|
|
93
|
+
if (key !== 'action' && key !== 'event') {
|
|
94
|
+
delete analyticAttrs[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
127
97
|
|
|
128
98
|
this.trackEvent(analyticAttrs);
|
|
129
99
|
};
|
|
130
100
|
|
|
131
|
-
invalidEvent = event =>
|
|
132
|
-
isModifiedEvent(event) ||
|
|
133
|
-
(event.type === 'click' && !isLeftClickEvent(event)) ||
|
|
134
|
-
!isValidEventTypeOnTarget(event);
|
|
101
|
+
invalidEvent = (event) =>
|
|
102
|
+
isModifiedEvent(event) || (event.type === 'click' && !isLeftClickEvent(event)) || !isValidEventTypeOnTarget(event);
|
|
135
103
|
|
|
136
|
-
getAnalyticAttrs = elem => {
|
|
104
|
+
getAnalyticAttrs = (elem) => {
|
|
137
105
|
if (!elem.attributes) {
|
|
138
106
|
return {};
|
|
139
107
|
}
|
|
@@ -145,9 +113,7 @@ export default class AvAnalytics {
|
|
|
145
113
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
146
114
|
const { name } = attrs[i];
|
|
147
115
|
if (name.indexOf(`${this.attributePrefix}-`) === 0) {
|
|
148
|
-
const camelName = camelCase(
|
|
149
|
-
name.slice(this.attributePrefix.length + 1)
|
|
150
|
-
);
|
|
116
|
+
const camelName = camelCase(name.slice(this.attributePrefix.length + 1));
|
|
151
117
|
analyticAttrs[camelName] = elem.getAttribute(name);
|
|
152
118
|
}
|
|
153
119
|
}
|
|
@@ -172,22 +138,20 @@ export default class AvAnalytics {
|
|
|
172
138
|
init = () => {
|
|
173
139
|
this.setPageTracking();
|
|
174
140
|
|
|
175
|
-
this.plugins
|
|
141
|
+
for (const plugin of this.plugins) {
|
|
176
142
|
if (isPluginEnabled(plugin) && typeof plugin.init === 'function') {
|
|
177
143
|
plugin.init();
|
|
178
144
|
}
|
|
179
|
-
}
|
|
145
|
+
}
|
|
180
146
|
};
|
|
181
147
|
|
|
182
|
-
setPageTracking = value => {
|
|
148
|
+
setPageTracking = (value) => {
|
|
183
149
|
// eslint-disable-next-line eqeqeq
|
|
184
150
|
if (value != undefined) {
|
|
185
151
|
this.pageTracking = !!value;
|
|
186
152
|
}
|
|
187
153
|
|
|
188
|
-
const canPageTrack =
|
|
189
|
-
typeof this.startPageTracking === 'function' &&
|
|
190
|
-
typeof this.stopPageTracking === 'function';
|
|
154
|
+
const canPageTrack = typeof this.startPageTracking === 'function' && typeof this.stopPageTracking === 'function';
|
|
191
155
|
|
|
192
156
|
if (canPageTrack && this.pageTracking !== this.isPageTracking) {
|
|
193
157
|
if (this.pageTracking) {
|
|
@@ -199,29 +163,35 @@ export default class AvAnalytics {
|
|
|
199
163
|
}
|
|
200
164
|
};
|
|
201
165
|
|
|
202
|
-
trackEvent = properties => {
|
|
166
|
+
trackEvent = (properties) => {
|
|
203
167
|
const promises = [];
|
|
204
168
|
properties.url = properties.url || window.location.href || 'N/A';
|
|
205
169
|
|
|
206
|
-
this.plugins
|
|
170
|
+
for (const plugin of this.plugins) {
|
|
171
|
+
const props = {
|
|
172
|
+
...properties,
|
|
173
|
+
};
|
|
174
|
+
|
|
207
175
|
if (isPluginEnabled(plugin) && typeof plugin.trackEvent === 'function') {
|
|
208
|
-
promises.push(plugin.trackEvent(
|
|
176
|
+
promises.push(plugin.trackEvent(props));
|
|
209
177
|
}
|
|
210
|
-
}
|
|
178
|
+
}
|
|
211
179
|
return this.Promise.all(promises);
|
|
212
180
|
};
|
|
213
181
|
|
|
214
|
-
trackPageView = url => {
|
|
182
|
+
trackPageView = (url) => {
|
|
183
|
+
// hashchanges are an object so we want to grab the new url from it
|
|
184
|
+
if (typeof url === 'object') {
|
|
185
|
+
url = url.newURL;
|
|
186
|
+
}
|
|
187
|
+
|
|
215
188
|
url = url || window.location.href;
|
|
216
189
|
const promises = [];
|
|
217
|
-
this.plugins
|
|
218
|
-
if (
|
|
219
|
-
isPluginEnabled(plugin) &&
|
|
220
|
-
typeof plugin.trackPageView === 'function'
|
|
221
|
-
) {
|
|
190
|
+
for (const plugin of this.plugins) {
|
|
191
|
+
if (isPluginEnabled(plugin) && typeof plugin.trackPageView === 'function') {
|
|
222
192
|
promises.push(plugin.trackPageView(url));
|
|
223
193
|
}
|
|
224
|
-
}
|
|
194
|
+
}
|
|
225
195
|
return this.Promise.all(promises);
|
|
226
196
|
};
|
|
227
197
|
}
|
package/src/dma.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
1
2
|
import AvAnalyticsPlugin from './plugin';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const schema = yup
|
|
5
|
+
.object()
|
|
6
|
+
.shape({
|
|
7
|
+
level: yup.string().optional(),
|
|
8
|
+
applicationId: yup.string().optional(),
|
|
9
|
+
payerSpaceId: yup.string().optional(),
|
|
10
|
+
label: yup.string().optional(),
|
|
11
|
+
appName: yup.string().optional(),
|
|
12
|
+
category: yup.string().optional(),
|
|
13
|
+
section: yup.string().optional(),
|
|
14
|
+
url: yup.string().optional(),
|
|
15
|
+
value: yup.string().optional(),
|
|
16
|
+
raw: yup.string().optional(),
|
|
17
|
+
feed: yup.string().optional(),
|
|
18
|
+
feedback: yup.string().optional(),
|
|
19
|
+
feedbackName: yup.string().optional(),
|
|
20
|
+
additionalFeedback: yup.string().optional(),
|
|
21
|
+
smile: yup.string().optional(),
|
|
22
|
+
surveyId: yup.string().optional(),
|
|
23
|
+
})
|
|
24
|
+
.noUnknown(true);
|
|
9
25
|
|
|
10
26
|
export default class AvDmaAnalytics extends AvAnalyticsPlugin {
|
|
11
27
|
constructor(AvLogMessages, enabled) {
|
|
@@ -14,44 +30,13 @@ export default class AvDmaAnalytics extends AvAnalyticsPlugin {
|
|
|
14
30
|
}
|
|
15
31
|
|
|
16
32
|
trackEvent(properties) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (properties.ApplicationId) {
|
|
22
|
-
properties.applicationId = properties.ApplicationId;
|
|
23
|
-
delete properties.ApplicationId;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (properties.Category) {
|
|
27
|
-
properties.category = properties.Category;
|
|
28
|
-
delete properties.Category;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (properties.tradingPartnerId || properties.TradingPartnerId) {
|
|
32
|
-
properties.tradingPartnerId =
|
|
33
|
-
properties.tradingPartnerId || properties.TradingPartnerId;
|
|
34
|
-
delete properties.TradingPartnerId;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (properties.customerId || properties.CustomerId) {
|
|
38
|
-
properties.customerId = properties.customerId || properties.CustomerId;
|
|
39
|
-
delete properties.CustomerId;
|
|
40
|
-
} else {
|
|
41
|
-
properties.customerId = 'NA';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
Object.keys(properties).forEach(key => {
|
|
45
|
-
const isRequiredField = requiredFields.filter(field => key === field)
|
|
46
|
-
.length;
|
|
47
|
-
if (!isRequiredField) {
|
|
48
|
-
data[key] = properties[key];
|
|
49
|
-
|
|
50
|
-
delete properties[key];
|
|
51
|
-
}
|
|
33
|
+
properties.level = properties.level || 'info';
|
|
34
|
+
// joi validate the properties
|
|
35
|
+
schema.validateSync(properties, {
|
|
36
|
+
strict: true,
|
|
52
37
|
});
|
|
53
38
|
|
|
54
|
-
return this.AvLogMessages.
|
|
39
|
+
return this.AvLogMessages[properties.level](properties);
|
|
55
40
|
}
|
|
56
41
|
|
|
57
42
|
trackPageView(url) {
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { AvAnalytics, AvAnalyticsPlugin, AvSplunkAnalytics, AvDmaAnalytics };
|
|
1
|
+
export { default as AvAnalytics } from './analytics';
|
|
2
|
+
export { default as AvAnalyticsPlugin } from './plugin';
|
|
3
|
+
export { default as AvSplunkAnalytics } from './splunk';
|
|
4
|
+
export { default as AvDmaAnalytics } from './dma';
|
|
@@ -123,16 +123,16 @@ describe('AvAnalytics', () => {
|
|
|
123
123
|
|
|
124
124
|
test('should check each plugin is enabled', () => {
|
|
125
125
|
mockAvAnalytics.init();
|
|
126
|
-
|
|
126
|
+
for (const plugin of plugins) {
|
|
127
127
|
expect(plugin.isEnabled).toHaveBeenCalled();
|
|
128
|
-
}
|
|
128
|
+
}
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
test('should call init on enabled plugins', () => {
|
|
132
132
|
mockAvAnalytics.init();
|
|
133
|
-
|
|
133
|
+
for (const plugin of plugins) {
|
|
134
134
|
expect(plugin.init).toHaveBeenCalledTimes(1);
|
|
135
|
-
}
|
|
135
|
+
}
|
|
136
136
|
|
|
137
137
|
plugins[0].isEnabled.mockImplementationOnce(() => false);
|
|
138
138
|
mockAvAnalytics.init();
|
package/src/tests/dma.test.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { avLogMessagesApiV2 } from '@availity/api-axios';
|
|
1
2
|
import { AvDmaAnalytics } from '..';
|
|
2
3
|
|
|
4
|
+
jest.mock('@availity/api-axios');
|
|
5
|
+
|
|
3
6
|
describe('AvSplunkAnalytics', () => {
|
|
4
|
-
let mockLog;
|
|
5
7
|
let mockAvSplunkAnalytics;
|
|
6
8
|
|
|
7
9
|
beforeEach(() => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
mockAvSplunkAnalytics = new AvDmaAnalytics(mockLog);
|
|
10
|
+
avLogMessagesApiV2.sendBeacon = jest.fn();
|
|
11
|
+
// avLogMessagesApiV2.info = jest.fn;
|
|
12
|
+
mockAvSplunkAnalytics = new AvDmaAnalytics(avLogMessagesApiV2);
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
test('AvSplunkAnalytics should be defined', () => {
|
|
@@ -18,15 +18,14 @@ describe('AvSplunkAnalytics', () => {
|
|
|
18
18
|
|
|
19
19
|
test('trackEvent should call AvLogMessages.send', () => {
|
|
20
20
|
const level = 'info';
|
|
21
|
-
mockAvSplunkAnalytics.trackEvent({ level });
|
|
22
|
-
expect(
|
|
21
|
+
mockAvSplunkAnalytics.trackEvent({ level, label: 'test' });
|
|
22
|
+
expect(avLogMessagesApiV2.info).toHaveBeenCalledTimes(1);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
test('should
|
|
25
|
+
test('trackEvent should not allow unknown keys', () => {
|
|
26
26
|
const level = 'info';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
27
|
+
expect(() => {
|
|
28
|
+
mockAvSplunkAnalytics.trackEvent({ level, test: 'test' });
|
|
29
|
+
}).toThrow();
|
|
31
30
|
});
|
|
32
31
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
camelCase,
|
|
3
|
+
getComposedPath,
|
|
4
|
+
isLeftClickEvent,
|
|
5
|
+
isModifiedEvent,
|
|
6
|
+
isPluginEnabled,
|
|
7
|
+
isValidEventTypeOnTarget,
|
|
8
|
+
} from '../util';
|
|
9
|
+
|
|
10
|
+
describe('analytics-core utils', () => {
|
|
11
|
+
test('isLeftClickEvent', () => {
|
|
12
|
+
expect(isLeftClickEvent({ button: 0 })).toBeTruthy();
|
|
13
|
+
expect(isLeftClickEvent({ button: 1 })).toBeFalsy();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('isModifiedEvent', () => {
|
|
17
|
+
expect(isModifiedEvent({ metaKey: 1 })).toBeTruthy();
|
|
18
|
+
expect(isModifiedEvent({ altKey: 1 })).toBeTruthy();
|
|
19
|
+
expect(isModifiedEvent({ ctrlKey: 1 })).toBeTruthy();
|
|
20
|
+
expect(isModifiedEvent({ shiftKey: 1 })).toBeTruthy();
|
|
21
|
+
expect(isModifiedEvent({ key: 1 })).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('isValidEventTypeOnTarget', () => {
|
|
25
|
+
expect(isValidEventTypeOnTarget({ target: { nodeName: 'click' }, type: 'click' })).toBeTruthy();
|
|
26
|
+
expect(isValidEventTypeOnTarget({ target: { nodeName: 'select' }, type: 'click' })).toBeFalsy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('isPluginEnabled', () => {
|
|
30
|
+
expect(isPluginEnabled({ isEnabled: () => true })).toBeTruthy();
|
|
31
|
+
expect(isPluginEnabled({ isEnabled: () => false })).toBeFalsy();
|
|
32
|
+
expect(isPluginEnabled({ isEnabled: true })).toBeTruthy();
|
|
33
|
+
expect(isPluginEnabled({ isEnabled: false })).toBeFalsy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('camelCase', () => {
|
|
37
|
+
expect(camelCase('foo')).toBe('foo');
|
|
38
|
+
expect(camelCase('foo-bar')).toBe('fooBar');
|
|
39
|
+
expect(camelCase('foo-bar-baz')).toBe('fooBarBaz');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('getComposedPath', () => {
|
|
43
|
+
expect(getComposedPath({}).length).toBe(1);
|
|
44
|
+
expect(getComposedPath({ parentNode: {} }).length).toBe(2);
|
|
45
|
+
expect(getComposedPath({ host: {} }).length).toBe(2);
|
|
46
|
+
expect(getComposedPath({ defaultView: {} }).length).toBe(2);
|
|
47
|
+
|
|
48
|
+
const result =
|
|
49
|
+
'[{"parentNode":{"host":{"defaultView":{}}}},[{"host":{"defaultView":{}}},[{"defaultView":{}},[{}]]]]';
|
|
50
|
+
const nested = getComposedPath({ parentNode: { host: { defaultView: {} } } });
|
|
51
|
+
expect(JSON.stringify(nested)).toEqual(result);
|
|
52
|
+
});
|
|
53
|
+
});
|