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