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