@microsoft/applicationinsights-clickanalytics-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-06
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/browser/ai.clck.2.8.0-nightly.2204-06.cjs.js +2890 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.js.map +1 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.min.js +6 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.min.js.map +1 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.js +2894 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.js.map +1 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.min.js +6 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.min.js.map +1 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.integrity.json +66 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.js +2896 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.js.map +1 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.min.js +6 -0
- package/browser/ai.clck.2.8.0-nightly.2204-06.min.js.map +1 -0
- package/browser/ai.clck.2.cjs.js +1689 -805
- package/browser/ai.clck.2.cjs.js.map +1 -1
- package/browser/ai.clck.2.cjs.min.js +2 -2
- package/browser/ai.clck.2.cjs.min.js.map +1 -1
- package/browser/ai.clck.2.gbl.js +1689 -805
- package/browser/ai.clck.2.gbl.js.map +1 -1
- package/browser/ai.clck.2.gbl.min.js +2 -2
- package/browser/ai.clck.2.gbl.min.js.map +1 -1
- package/browser/ai.clck.2.js +1689 -805
- package/browser/ai.clck.2.js.map +1 -1
- package/browser/ai.clck.2.min.js +2 -2
- package/browser/ai.clck.2.min.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.api.json +38 -13
- package/dist/applicationinsights-clickanalytics-js.api.md +1 -0
- package/dist/applicationinsights-clickanalytics-js.d.ts +2 -5
- package/dist/applicationinsights-clickanalytics-js.js +1689 -805
- package/dist/applicationinsights-clickanalytics-js.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.min.js +2 -2
- package/dist/applicationinsights-clickanalytics-js.min.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +2 -5
- package/dist-esm/Behaviours.js +1 -1
- package/dist-esm/ClickAnalyticsPlugin.js +75 -51
- package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
- package/dist-esm/DataCollector.js +4 -2
- package/dist-esm/DataCollector.js.map +1 -1
- package/dist-esm/Enums.js +1 -1
- package/dist-esm/Interfaces/Datamodel.js +1 -1
- package/dist-esm/applicationinsights-clickanalytics-js.js +1 -1
- package/dist-esm/common/Utils.js +1 -1
- package/dist-esm/events/PageAction.js +130 -128
- package/dist-esm/events/PageAction.js.map +1 -1
- package/dist-esm/events/WebEvent.js +109 -94
- package/dist-esm/events/WebEvent.js.map +1 -1
- package/dist-esm/handlers/AutoCaptureHandler.js +85 -83
- package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
- package/dist-esm/handlers/DomContentHandler.js +281 -278
- package/dist-esm/handlers/DomContentHandler.js.map +1 -1
- package/package.json +5 -5
- package/src/ClickAnalyticsPlugin.ts +94 -49
- package/src/DataCollector.ts +24 -22
- package/src/Interfaces/Datamodel.ts +20 -21
- package/src/common/Utils.ts +8 -8
- package/src/events/PageAction.ts +166 -132
- package/src/events/WebEvent.ts +147 -78
- package/src/handlers/AutoCaptureHandler.ts +92 -79
- package/src/handlers/DomContentHandler.ts +337 -304
- package/types/ClickAnalyticsPlugin.d.ts +1 -4
- package/types/Interfaces/Datamodel.d.ts +3 -2
- package/types/common/Utils.d.ts +79 -79
- package/types/events/PageAction.d.ts +6 -6
- package/types/events/WebEvent.d.ts +17 -17
- package/types/handlers/AutoCaptureHandler.d.ts +2 -10
- package/types/handlers/DomContentHandler.d.ts +3 -50
- package/types/tsdoc-metadata.json +1 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js +0 -2006
- package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js.map +0 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js +0 -6
- package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js.map +0 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js +0 -2010
- package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js.map +0 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js +0 -6
- package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js.map +0 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.integrity.json +0 -66
- package/browser/ai.clck.2.8.0-nightly.2202-06.js +0 -2012
- package/browser/ai.clck.2.8.0-nightly.2202-06.js.map +0 -1
- package/browser/ai.clck.2.8.0-nightly.2202-06.min.js +0 -6
- package/browser/ai.clck.2.8.0-nightly.2202-06.min.js.map +0 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Click Analytics, 2.8.0-nightly.
|
|
2
|
+
* Application Insights JavaScript SDK - Click Analytics, 2.8.0-nightly.2204-06
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @copyright Microsoft 2020
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
8
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
9
|
+
import { removeInvalidElements, walkUpDomChainWithElementValidation, extend, isValueAssigned } from "../common/Utils";
|
|
10
|
+
import { getDocument, isNullOrUndefined, hasDocument, _throwInternal } from "@microsoft/applicationinsights-core-js";
|
|
10
11
|
var MAX_CONTENTNAME_LENGTH = 200;
|
|
11
12
|
var DomContentHandler = /** @class */ (function () {
|
|
12
13
|
/**
|
|
@@ -16,302 +17,304 @@ var DomContentHandler = /** @class */ (function () {
|
|
|
16
17
|
function DomContentHandler(_config, _traceLogger) {
|
|
17
18
|
this._config = _config;
|
|
18
19
|
this._traceLogger = _traceLogger;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Collect data-* attributes for the given element.
|
|
35
|
-
* All attributes with data-* prefix or user provided customDataPrefix are collected.'data-*' prefix is removed from the key name.
|
|
36
|
-
* @param element - The element from which attributes need to be collected.
|
|
37
|
-
* @returns String representation of the Json array of element attributes
|
|
38
|
-
*/
|
|
39
|
-
DomContentHandler.prototype.getElementContent = function (element) {
|
|
40
|
-
if (!element) {
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
var elementContent = {};
|
|
44
|
-
var biBlobValue;
|
|
45
|
-
var parentDataTagPrefix;
|
|
46
|
-
var dataTagPrefix = this._config.dataTags.customDataPrefix;
|
|
47
|
-
var aiBlobAttributeTag = dataTagPrefix + this._config.dataTags.aiBlobAttributeTag;
|
|
48
|
-
if (isValueAssigned(this._config.dataTags.parentDataTag)) {
|
|
49
|
-
parentDataTagPrefix = dataTagPrefix + this._config.dataTags.parentDataTag;
|
|
50
|
-
}
|
|
51
|
-
if (!this._isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {
|
|
52
|
-
// capture blob from element or hierarchy
|
|
53
|
-
biBlobValue = element.getAttribute(aiBlobAttributeTag);
|
|
54
|
-
if (biBlobValue) {
|
|
55
|
-
try {
|
|
56
|
-
elementContent = JSON.parse(biBlobValue);
|
|
20
|
+
dynamicProto(DomContentHandler, this, function (_self) {
|
|
21
|
+
_self.getMetadata = function () {
|
|
22
|
+
var dataTags = (_self._config || {}).dataTags;
|
|
23
|
+
var metaTags = {};
|
|
24
|
+
if (hasDocument) {
|
|
25
|
+
metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags.captureAllMetaDataContent, dataTags.metaDataPrefix, false) :
|
|
26
|
+
_getMetaDataFromDOM(dataTags.captureAllMetaDataContent, "", false);
|
|
27
|
+
}
|
|
28
|
+
return metaTags;
|
|
29
|
+
};
|
|
30
|
+
_self.getElementContent = function (element) {
|
|
31
|
+
if (!element) {
|
|
32
|
+
return {};
|
|
57
33
|
}
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
var dataTags = (_self._config || {}).dataTags;
|
|
35
|
+
var elementContent = {};
|
|
36
|
+
var biBlobValue;
|
|
37
|
+
var parentDataTagPrefix;
|
|
38
|
+
var dataTagPrefix = dataTags.customDataPrefix;
|
|
39
|
+
var aiBlobAttributeTag = dataTagPrefix + dataTags.aiBlobAttributeTag;
|
|
40
|
+
if (isValueAssigned(dataTags.parentDataTag)) {
|
|
41
|
+
parentDataTagPrefix = dataTagPrefix + dataTags.parentDataTag;
|
|
42
|
+
}
|
|
43
|
+
if (!_isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {
|
|
44
|
+
// capture blob from element or hierarchy
|
|
45
|
+
biBlobValue = element.getAttribute(aiBlobAttributeTag);
|
|
46
|
+
if (biBlobValue) {
|
|
47
|
+
try {
|
|
48
|
+
elementContent = JSON.parse(biBlobValue);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
_throwInternal(_self._traceLogger, 1 /* CRITICAL */, 101 /* CannotParseAiBlobValue */, "Can not parse " + biBlobValue);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// traverse up the DOM to find the closest parent with data-* tag defined
|
|
56
|
+
//contentElement = walkUpDomChainWithElementValidation(element, _self._isTracked, dataTagPrefix);
|
|
57
|
+
elementContent = extend(elementContent, _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
elementContent = extend(elementContent, _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));
|
|
62
|
+
}
|
|
63
|
+
removeInvalidElements(elementContent);
|
|
64
|
+
if (parentDataTagPrefix) {
|
|
65
|
+
elementContent = extend(elementContent, _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag));
|
|
66
|
+
}
|
|
67
|
+
return elementContent;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Capture current level Element content
|
|
71
|
+
*/
|
|
72
|
+
function _captureElementContentWithDataTag(contentElement, elementContent, dataTagPrefix) {
|
|
73
|
+
for (var i = 0, attrib; i < contentElement.attributes.length; i++) {
|
|
74
|
+
attrib = contentElement.attributes[i];
|
|
75
|
+
if (attrib.name.indexOf(dataTagPrefix) !== 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
var attribName = attrib.name.replace(dataTagPrefix, "");
|
|
79
|
+
elementContent[attribName] = attrib.value;
|
|
60
80
|
}
|
|
61
81
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Walk Up the DOM to capture Element content
|
|
84
|
+
*/
|
|
85
|
+
function _walkUpDomChainCaptureData(el, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {
|
|
86
|
+
var element = el;
|
|
87
|
+
var parentDataTagFound = false;
|
|
88
|
+
var elementLevelFlag = false; // Use this flag to capture 'id' only at the incoming html element level.
|
|
89
|
+
while (!isNullOrUndefined(element) && !isNullOrUndefined(element.attributes)) {
|
|
90
|
+
var attributes = element.attributes;
|
|
91
|
+
for (var i = 0; i < attributes.length; i++) {
|
|
92
|
+
var attrib = attributes[i];
|
|
93
|
+
if (attrib.name.indexOf(dataTagPrefix) !== 0) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (attrib.name.indexOf(parentDataTagPrefix) === 0) {
|
|
97
|
+
parentDataTagFound = true;
|
|
98
|
+
}
|
|
99
|
+
// Todo handle blob data
|
|
100
|
+
if (attrib.name.indexOf(aiBlobAttributeTag) === 0) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
var attribName = attrib.name.replace(dataTagPrefix, "");
|
|
104
|
+
if (elementLevelFlag && attribName === "id") {
|
|
105
|
+
continue; // skip capturing id if not at the first level.
|
|
106
|
+
}
|
|
107
|
+
if (!isValueAssigned(elementContent[attribName])) {
|
|
108
|
+
elementContent[attribName] = attrib.value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// break after current level;
|
|
112
|
+
if (parentDataTagFound) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
elementLevelFlag = true; // after the initial level set this flag to true.
|
|
116
|
+
element = element.parentNode;
|
|
117
|
+
}
|
|
66
118
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Capture Element content along with Data Tag attributes and values
|
|
121
|
+
*/
|
|
122
|
+
function _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {
|
|
123
|
+
var elementContent = {};
|
|
124
|
+
if (!element) {
|
|
125
|
+
return elementContent;
|
|
126
|
+
}
|
|
127
|
+
var htmlContent = _getHtmlIdAndContentName(element);
|
|
128
|
+
elementContent = {
|
|
129
|
+
id: htmlContent.id || "",
|
|
130
|
+
contentName: htmlContent.contentName || ""
|
|
131
|
+
};
|
|
132
|
+
if (isValueAssigned(parentDataTagPrefix)) {
|
|
133
|
+
_walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);
|
|
134
|
+
}
|
|
135
|
+
// Validate to ensure the minimum required field 'id' or 'contentName' is present.
|
|
136
|
+
// The content schema defines id, aN and sN as required fields. However,
|
|
137
|
+
// requiring these fields would result in majority of adopter's content from being collected.
|
|
138
|
+
// Just throw a warning and continue collection.
|
|
139
|
+
if (!elementContent.id && !elementContent.contentName) {
|
|
140
|
+
_throwInternal(_traceLogger, 2 /* WARNING */, 102 /* InvalidContentBlob */, "Invalid content blob. Missing required attributes (id, contentName. " +
|
|
141
|
+
" Content information will still be collected!");
|
|
142
|
+
}
|
|
143
|
+
return elementContent;
|
|
85
144
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var element = el;
|
|
95
|
-
var parentDataTagFound = false;
|
|
96
|
-
var elementLevelFlag = false; // Use this flag to capture 'id' only at the incoming html element level.
|
|
97
|
-
while (!isNullOrUndefined(element) && !isNullOrUndefined(element.attributes)) {
|
|
98
|
-
var attributes = element.attributes;
|
|
99
|
-
for (var i = 0; i < attributes.length; i++) {
|
|
100
|
-
var attrib = attributes[i];
|
|
101
|
-
if (attrib.name.indexOf(dataTagPrefix) !== 0) {
|
|
102
|
-
continue;
|
|
145
|
+
/**
|
|
146
|
+
* Capture Element content along with Data Tag attributes and values
|
|
147
|
+
*/
|
|
148
|
+
function _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {
|
|
149
|
+
var dataTags = (_self._config || {}).dataTags;
|
|
150
|
+
var elementContent = {};
|
|
151
|
+
if (!element) {
|
|
152
|
+
return elementContent;
|
|
103
153
|
}
|
|
104
|
-
|
|
105
|
-
|
|
154
|
+
var htmlContent = _getHtmlIdAndContentName(element);
|
|
155
|
+
if (isValueAssigned(parentDataTagPrefix)) {
|
|
156
|
+
_walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);
|
|
106
157
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
continue;
|
|
158
|
+
else {
|
|
159
|
+
_captureElementContentWithDataTag(element, elementContent, dataTagPrefix);
|
|
110
160
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
elementContent
|
|
161
|
+
if (dataTags.useDefaultContentNameOrId) {
|
|
162
|
+
if (!isValueAssigned(elementContent.id)) {
|
|
163
|
+
elementContent.id = htmlContent.id || "";
|
|
164
|
+
}
|
|
165
|
+
elementContent.contentName = htmlContent.contentName || "";
|
|
166
|
+
}
|
|
167
|
+
// Validate to ensure the minimum required field 'id' or 'contentName' is present.
|
|
168
|
+
// The content schema defines id, aN and sN as required fields. However,
|
|
169
|
+
// requiring these fields would result in majority of adopter's content from being collected.
|
|
170
|
+
// Just throw a warning and continue collection.
|
|
171
|
+
if (!elementContent.id && !elementContent.contentName) {
|
|
172
|
+
_throwInternal(_traceLogger, 2 /* WARNING */, 102 /* InvalidContentBlob */, "Invalid content blob. Missing required attributes (id, contentName. " +
|
|
173
|
+
" Content information will still be collected!");
|
|
116
174
|
}
|
|
175
|
+
return elementContent;
|
|
117
176
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Retrieve a specified metadata tag value from the DOM.
|
|
179
|
+
* @param captureAllMetaDataContent - Flag to capture all metadata content
|
|
180
|
+
* @param prefix - Prefix to search the metatags with.
|
|
181
|
+
* @param removePrefix - Specifies if the prefix must be excluded from key names in the returned collection.
|
|
182
|
+
* @returns Metadata collection/property bag
|
|
183
|
+
*/
|
|
184
|
+
function _getMetaDataFromDOM(captureAllMetaDataContent, prefix, removePrefix) {
|
|
185
|
+
var metaElements;
|
|
186
|
+
var metaData = {};
|
|
187
|
+
if (hasDocument) {
|
|
188
|
+
metaElements = document.querySelectorAll("meta");
|
|
189
|
+
for (var i = 0; i < metaElements.length; i++) {
|
|
190
|
+
var meta = metaElements[i];
|
|
191
|
+
if (meta.name) {
|
|
192
|
+
if (captureAllMetaDataContent || meta.name.indexOf(prefix) === 0) {
|
|
193
|
+
var name_1 = removePrefix ? meta.name.replace(prefix, "") : meta.name;
|
|
194
|
+
metaData[name_1] = meta.content;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return metaData;
|
|
121
200
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this._traceLogger.throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.InvalidContentBlob, "Invalid content blob. Missing required attributes (id, contentName. " +
|
|
147
|
-
" Content information will still be collected!");
|
|
148
|
-
}
|
|
149
|
-
return elementContent;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Capture Element content along with Data Tag attributes and values
|
|
153
|
-
*/
|
|
154
|
-
DomContentHandler.prototype._populateElementContentwithDataTag = function (element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {
|
|
155
|
-
var elementContent = {};
|
|
156
|
-
if (!element)
|
|
157
|
-
return elementContent;
|
|
158
|
-
var htmlContent = this._getHtmlIdAndContentName(element);
|
|
159
|
-
if (isValueAssigned(parentDataTagPrefix)) {
|
|
160
|
-
this._walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this._captureElementContentWithDataTag(element, elementContent, dataTagPrefix);
|
|
164
|
-
}
|
|
165
|
-
if (this._config.dataTags.useDefaultContentNameOrId) {
|
|
166
|
-
if (!isValueAssigned(elementContent.id)) {
|
|
167
|
-
elementContent.id = htmlContent.id || "";
|
|
201
|
+
/**
|
|
202
|
+
* Gets the default content name.
|
|
203
|
+
* @param element - An html element
|
|
204
|
+
* @param useDefaultContentNameOrId -Flag indicating if an element is market PII.
|
|
205
|
+
* @returns Content name
|
|
206
|
+
*/
|
|
207
|
+
function _getDefaultContentName(element, useDefaultContentName) {
|
|
208
|
+
if (useDefaultContentName === false || !element.tagName) {
|
|
209
|
+
return "";
|
|
210
|
+
}
|
|
211
|
+
var doc = getDocument() || {};
|
|
212
|
+
var contentName;
|
|
213
|
+
switch (element.tagName) {
|
|
214
|
+
case "A":
|
|
215
|
+
contentName = doc.all ? element.innerText || element.innerHTML : element.text || element.innerHTML;
|
|
216
|
+
break;
|
|
217
|
+
case "IMG":
|
|
218
|
+
case "AREA":
|
|
219
|
+
contentName = element.alt;
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
contentName = element.value || element.name || element.alt || element.innerText || element.id;
|
|
223
|
+
}
|
|
224
|
+
return contentName.substring(0, MAX_CONTENTNAME_LENGTH);
|
|
168
225
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
* @param removePrefix - Specifies if the prefix must be excluded from key names in the returned collection.
|
|
186
|
-
* @returns Metadata collection/property bag
|
|
187
|
-
*/
|
|
188
|
-
DomContentHandler.prototype._getMetaDataFromDOM = function (captureAllMetaDataContent, prefix, removePrefix) {
|
|
189
|
-
var metaElements;
|
|
190
|
-
var metaData = {};
|
|
191
|
-
if (hasDocument) {
|
|
192
|
-
metaElements = document.querySelectorAll("meta");
|
|
193
|
-
for (var i = 0; i < metaElements.length; i++) {
|
|
194
|
-
var meta = metaElements[i];
|
|
195
|
-
if (meta.name) {
|
|
196
|
-
if (captureAllMetaDataContent || meta.name.indexOf(prefix) === 0) {
|
|
197
|
-
var name_1 = removePrefix ? meta.name.replace(prefix, "") : meta.name;
|
|
198
|
-
metaData[name_1] = meta.content;
|
|
226
|
+
/**
|
|
227
|
+
* Check if the user wants to track the element, which means if the element has any tags with data-* or customDataPrefix
|
|
228
|
+
* @param element - An html element
|
|
229
|
+
* @returns true if any data-* exist, otherwise return false
|
|
230
|
+
*/
|
|
231
|
+
function _isTracked(element, dataTag, aiBlobAttributeTag) {
|
|
232
|
+
var attrs = element.attributes;
|
|
233
|
+
var dataTagFound = false;
|
|
234
|
+
for (var i = 0; i < attrs.length; i++) {
|
|
235
|
+
var attributeName = attrs[i].name;
|
|
236
|
+
if (attributeName === aiBlobAttributeTag) {
|
|
237
|
+
// ignore if the attribute name is equal to aiBlobAttributeTag
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
else if (attributeName.indexOf(dataTag) === 0) {
|
|
241
|
+
dataTagFound = true;
|
|
199
242
|
}
|
|
200
243
|
}
|
|
244
|
+
return dataTagFound;
|
|
201
245
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
case "A":
|
|
219
|
-
contentName = doc.all ? element.innerText || element.innerHTML : element.text || element.innerHTML;
|
|
220
|
-
break;
|
|
221
|
-
case "IMG":
|
|
222
|
-
case "AREA":
|
|
223
|
-
contentName = element.alt;
|
|
224
|
-
break;
|
|
225
|
-
default:
|
|
226
|
-
contentName = element.value || element.name || element.alt || element.innerText || element.id;
|
|
227
|
-
}
|
|
228
|
-
return contentName.substring(0, MAX_CONTENTNAME_LENGTH);
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Check if the user wants to track the element, which means if the element has any tags with data-* or customDataPrefix
|
|
232
|
-
* @param element - An html element
|
|
233
|
-
* @returns true if any data-* exist, otherwise return false
|
|
234
|
-
*/
|
|
235
|
-
DomContentHandler.prototype._isTracked = function (element, dataTag, aiBlobAttributeTag) {
|
|
236
|
-
var attrs = element.attributes;
|
|
237
|
-
var dataTagFound = false;
|
|
238
|
-
for (var i = 0; i < attrs.length; i++) {
|
|
239
|
-
var attributeName = attrs[i].name;
|
|
240
|
-
if (attributeName === aiBlobAttributeTag) {
|
|
241
|
-
// ignore if the attribute name is equal to aiBlobAttributeTag
|
|
242
|
-
return false;
|
|
246
|
+
function _getHtmlIdAndContentName(element) {
|
|
247
|
+
var dataTags = (_self._config || {}).dataTags;
|
|
248
|
+
var callback = (_self._config || {}).callback;
|
|
249
|
+
var htmlContent = {};
|
|
250
|
+
if (!element) {
|
|
251
|
+
return htmlContent;
|
|
252
|
+
}
|
|
253
|
+
if (dataTags.useDefaultContentNameOrId) {
|
|
254
|
+
var customizedContentName = callback.contentName ? callback.contentName(element, dataTags.useDefaultContentNameOrId) : "";
|
|
255
|
+
var defaultContentName = _getDefaultContentName(element, dataTags.useDefaultContentNameOrId);
|
|
256
|
+
htmlContent = {
|
|
257
|
+
id: element.id,
|
|
258
|
+
contentName: customizedContentName || defaultContentName || element.getAttribute("alt")
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return htmlContent;
|
|
243
262
|
}
|
|
244
|
-
|
|
245
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Computes the parentId of a given element.
|
|
265
|
+
* @param element - An html element
|
|
266
|
+
* @returns An object containing the closest parentId , can be empty if nothing was found
|
|
267
|
+
*/
|
|
268
|
+
function _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag) {
|
|
269
|
+
var parentId = elementContent["parentid"];
|
|
270
|
+
var parentName = elementContent["parentname"];
|
|
271
|
+
var parentInfo = {};
|
|
272
|
+
if (parentId || parentName || !element) {
|
|
273
|
+
return parentInfo;
|
|
274
|
+
}
|
|
275
|
+
return _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag);
|
|
246
276
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (parentId || parentName || !element) {
|
|
274
|
-
return parentInfo;
|
|
275
|
-
}
|
|
276
|
-
return this._populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag);
|
|
277
|
-
};
|
|
278
|
-
/**
|
|
279
|
-
* Check if parent info already set up, if so take and put into content, if not walk up the DOM to find correct info
|
|
280
|
-
* @param element - An html element that the user wants to track
|
|
281
|
-
* @returns An object containing the parent info, can be empty if nothing was found
|
|
282
|
-
*/
|
|
283
|
-
DomContentHandler.prototype._populateParentInfo = function (element, dataTagPrefix, aiBlobAttributeTag) {
|
|
284
|
-
var parentInfo = {};
|
|
285
|
-
var parentId;
|
|
286
|
-
// if the user does not set up parent info, walk to the DOM, find the closest parent element (with tags) and populate the info
|
|
287
|
-
var closestParentElement = walkUpDomChainWithElementValidation(element.parentElement, this._isTracked, dataTagPrefix);
|
|
288
|
-
if (closestParentElement) {
|
|
289
|
-
var dataAttr = closestParentElement.getAttribute(aiBlobAttributeTag) || element[aiBlobAttributeTag];
|
|
290
|
-
if (dataAttr) {
|
|
291
|
-
try {
|
|
292
|
-
var telemetryObject = JSON.parse(dataAttr);
|
|
277
|
+
/**
|
|
278
|
+
* Check if parent info already set up, if so take and put into content, if not walk up the DOM to find correct info
|
|
279
|
+
* @param element - An html element that the user wants to track
|
|
280
|
+
* @returns An object containing the parent info, can be empty if nothing was found
|
|
281
|
+
*/
|
|
282
|
+
function _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag) {
|
|
283
|
+
var parentInfo = {};
|
|
284
|
+
var parentId;
|
|
285
|
+
// if the user does not set up parent info, walk to the DOM, find the closest parent element (with tags) and populate the info
|
|
286
|
+
var closestParentElement = walkUpDomChainWithElementValidation(element.parentElement, _isTracked, dataTagPrefix);
|
|
287
|
+
if (closestParentElement) {
|
|
288
|
+
var dataAttr = closestParentElement.getAttribute(aiBlobAttributeTag) || element[aiBlobAttributeTag];
|
|
289
|
+
if (dataAttr) {
|
|
290
|
+
try {
|
|
291
|
+
var telemetryObject = JSON.parse(dataAttr);
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
_throwInternal(_traceLogger, 1 /* CRITICAL */, 101 /* CannotParseAiBlobValue */, "Can not parse " + dataAttr);
|
|
295
|
+
}
|
|
296
|
+
if (telemetryObject) {
|
|
297
|
+
parentId = telemetryObject.id;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
parentId = closestParentElement.getAttribute(dataTagPrefix + "id");
|
|
302
|
+
}
|
|
293
303
|
}
|
|
294
|
-
|
|
295
|
-
|
|
304
|
+
if (parentId) {
|
|
305
|
+
parentInfo["parentid"] = parentId;
|
|
296
306
|
}
|
|
297
|
-
|
|
298
|
-
|
|
307
|
+
else {
|
|
308
|
+
var htmlContent = _getHtmlIdAndContentName(element.parentElement);
|
|
309
|
+
parentInfo["parentid"] = htmlContent.id;
|
|
310
|
+
parentInfo["parentname"] = htmlContent.contentName;
|
|
299
311
|
}
|
|
312
|
+
return parentInfo;
|
|
300
313
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (parentId) {
|
|
306
|
-
parentInfo["parentid"] = parentId;
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
var htmlContent = this._getHtmlIdAndContentName(element.parentElement);
|
|
310
|
-
parentInfo["parentid"] = htmlContent.id;
|
|
311
|
-
parentInfo["parentname"] = htmlContent.contentName;
|
|
312
|
-
}
|
|
313
|
-
return parentInfo;
|
|
314
|
-
};
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
// Removed Stub for DomContentHandler.prototype.getMetadata.
|
|
317
|
+
// Removed Stub for DomContentHandler.prototype.getElementContent.
|
|
315
318
|
return DomContentHandler;
|
|
316
319
|
}());
|
|
317
320
|
export { DomContentHandler };
|