@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.
Files changed (73) hide show
  1. package/browser/{ai.clck.2.8.0-beta.2203-10.cjs.js → ai.clck.2.8.0-beta.2203-13.cjs.js} +688 -514
  2. package/browser/ai.clck.2.8.0-beta.2203-13.cjs.js.map +1 -0
  3. package/browser/ai.clck.2.8.0-beta.2203-13.cjs.min.js +6 -0
  4. package/browser/ai.clck.2.8.0-beta.2203-13.cjs.min.js.map +1 -0
  5. package/browser/{ai.clck.2.8.0-beta.2203-10.gbl.js → ai.clck.2.8.0-beta.2203-13.gbl.js} +688 -514
  6. package/browser/ai.clck.2.8.0-beta.2203-13.gbl.js.map +1 -0
  7. package/browser/ai.clck.2.8.0-beta.2203-13.gbl.min.js +6 -0
  8. package/browser/ai.clck.2.8.0-beta.2203-13.gbl.min.js.map +1 -0
  9. package/browser/ai.clck.2.8.0-beta.2203-13.integrity.json +66 -0
  10. package/browser/{ai.clck.2.8.0-beta.2203-10.js → ai.clck.2.8.0-beta.2203-13.js} +688 -514
  11. package/browser/ai.clck.2.8.0-beta.2203-13.js.map +1 -0
  12. package/browser/ai.clck.2.8.0-beta.2203-13.min.js +6 -0
  13. package/browser/ai.clck.2.8.0-beta.2203-13.min.js.map +1 -0
  14. package/browser/ai.clck.2.cjs.js +687 -513
  15. package/browser/ai.clck.2.cjs.js.map +1 -1
  16. package/browser/ai.clck.2.cjs.min.js +2 -2
  17. package/browser/ai.clck.2.cjs.min.js.map +1 -1
  18. package/browser/ai.clck.2.gbl.js +687 -513
  19. package/browser/ai.clck.2.gbl.js.map +1 -1
  20. package/browser/ai.clck.2.gbl.min.js +2 -2
  21. package/browser/ai.clck.2.gbl.min.js.map +1 -1
  22. package/browser/ai.clck.2.js +687 -513
  23. package/browser/ai.clck.2.js.map +1 -1
  24. package/browser/ai.clck.2.min.js +2 -2
  25. package/browser/ai.clck.2.min.js.map +1 -1
  26. package/dist/applicationinsights-clickanalytics-js.api.json +15 -1
  27. package/dist/applicationinsights-clickanalytics-js.api.md +1 -0
  28. package/dist/applicationinsights-clickanalytics-js.d.ts +2 -5
  29. package/dist/applicationinsights-clickanalytics-js.js +687 -513
  30. package/dist/applicationinsights-clickanalytics-js.js.map +1 -1
  31. package/dist/applicationinsights-clickanalytics-js.min.js +2 -2
  32. package/dist/applicationinsights-clickanalytics-js.min.js.map +1 -1
  33. package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +2 -5
  34. package/dist-esm/Behaviours.js +1 -1
  35. package/dist-esm/ClickAnalyticsPlugin.js +74 -50
  36. package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
  37. package/dist-esm/DataCollector.js +1 -1
  38. package/dist-esm/Enums.js +1 -1
  39. package/dist-esm/Interfaces/Datamodel.js +1 -1
  40. package/dist-esm/applicationinsights-clickanalytics-js.js +1 -1
  41. package/dist-esm/common/Utils.js +1 -1
  42. package/dist-esm/events/PageAction.js +128 -128
  43. package/dist-esm/events/PageAction.js.map +1 -1
  44. package/dist-esm/events/WebEvent.js +109 -94
  45. package/dist-esm/events/WebEvent.js.map +1 -1
  46. package/dist-esm/handlers/AutoCaptureHandler.js +85 -91
  47. package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
  48. package/dist-esm/handlers/DomContentHandler.js +279 -280
  49. package/dist-esm/handlers/DomContentHandler.js.map +1 -1
  50. package/package.json +5 -5
  51. package/src/ClickAnalyticsPlugin.ts +91 -46
  52. package/src/Interfaces/Datamodel.ts +17 -18
  53. package/src/events/PageAction.ts +165 -134
  54. package/src/events/WebEvent.ts +147 -77
  55. package/src/handlers/AutoCaptureHandler.ts +88 -86
  56. package/src/handlers/DomContentHandler.ts +336 -310
  57. package/types/ClickAnalyticsPlugin.d.ts +1 -4
  58. package/types/Interfaces/Datamodel.d.ts +7 -6
  59. package/types/events/PageAction.d.ts +6 -6
  60. package/types/events/WebEvent.d.ts +17 -17
  61. package/types/handlers/AutoCaptureHandler.d.ts +2 -10
  62. package/types/handlers/DomContentHandler.d.ts +3 -50
  63. package/types/tsdoc-metadata.json +1 -1
  64. package/browser/ai.clck.2.8.0-beta.2203-10.cjs.js.map +0 -1
  65. package/browser/ai.clck.2.8.0-beta.2203-10.cjs.min.js +0 -6
  66. package/browser/ai.clck.2.8.0-beta.2203-10.cjs.min.js.map +0 -1
  67. package/browser/ai.clck.2.8.0-beta.2203-10.gbl.js.map +0 -1
  68. package/browser/ai.clck.2.8.0-beta.2203-10.gbl.min.js +0 -6
  69. package/browser/ai.clck.2.8.0-beta.2203-10.gbl.min.js.map +0 -1
  70. package/browser/ai.clck.2.8.0-beta.2203-10.integrity.json +0 -66
  71. package/browser/ai.clck.2.8.0-beta.2203-10.js.map +0 -1
  72. package/browser/ai.clck.2.8.0-beta.2203-10.min.js +0 -6
  73. 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
- * Collect metatags from DOM.
25
- * Collect data from meta tags.
26
- * @returns {object} - Metatags collection/property bag
27
- */
28
- public getMetadata(): { [name: string]: string } {
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
- let metaTags = {};
31
- if (hasDocument) {
32
- metaTags = isValueAssigned(this._config.dataTags.metaDataPrefix) ? this._getMetaDataFromDOM(this._config.dataTags.captureAllMetaDataContent ,this._config.dataTags.metaDataPrefix, false) :
33
- this._getMetaDataFromDOM(this._config.dataTags.captureAllMetaDataContent ,"", false);
34
- }
35
- return metaTags;
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
- * Collect data-* attributes for the given element.
40
- * All attributes with data-* prefix or user provided customDataPrefix are collected.'data-*' prefix is removed from the key name.
41
- * @param element - The element from which attributes need to be collected.
42
- * @returns String representation of the Json array of element attributes
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
- if (!element) {
47
- return {};
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
- if (!this._isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {
60
- // capture blob from element or hierarchy
61
- biBlobValue = element.getAttribute(aiBlobAttributeTag);
62
- if (biBlobValue) {
63
- try {
64
- elementContent = JSON.parse(biBlobValue);
65
- } catch (e) {
66
- this._traceLogger.throwInternal(
67
- LoggingSeverity.CRITICAL,
68
- _ExtendedInternalMessageId.CannotParseAiBlobValue, "Can not parse " + biBlobValue
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
- * Capture current level Element content
89
- */
90
- private _captureElementContentWithDataTag(contentElement: Element, elementContent: any, dataTagPrefix: string) {
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
- for (var i = 0, attrib; i < contentElement.attributes.length; i++) {
93
- attrib = contentElement.attributes[i];
107
+ while(!isNullOrUndefined(element) && !isNullOrUndefined(element.attributes)) {
108
+ let attributes=element.attributes;
94
109
 
95
- if ( attrib.name.indexOf(dataTagPrefix) !== 0 ) {
96
- continue;
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
- var attribName = attrib.name.replace(dataTagPrefix, "");
100
- elementContent[attribName] = attrib.value;
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
- * Walk Up the DOM to capture Element content
106
- */
107
- private _walkUpDomChainCaptureData(el: Element, elementContent: any, dataTagPrefix: string, parentDataTagPrefix: string, aiBlobAttributeTag: string ): void {
108
- let element = el;
109
- let parentDataTagFound: boolean = false;
110
- let elementLevelFlag: boolean = false; // Use this flag to capture 'id' only at the incoming html element level.
111
- while(!isNullOrUndefined(element) && !isNullOrUndefined(element.attributes)) {
112
- let attributes=element.attributes;
113
- for (let i = 0; i < attributes.length; i++) {
114
- const attrib = attributes[i];
115
-
116
- if ( attrib.name.indexOf(dataTagPrefix) !== 0 ) {
117
- continue;
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
- if( attrib.name.indexOf(parentDataTagPrefix) === 0) {
121
- parentDataTagFound = true;
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
- // Todo handle blob data
125
- if( attrib.name.indexOf(aiBlobAttributeTag) === 0) {
126
- continue;
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
- const attribName = attrib.name.replace(dataTagPrefix, "");
129
- if(elementLevelFlag && attribName ==="id") {
130
- continue;
131
- } // skip capturing id if not at the first level.
132
- if(!isValueAssigned(elementContent[attribName])) {
133
- elementContent[attribName] = attrib.value;
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
- * Capture Element content along with Data Tag attributes and values
183
- */
184
- private _populateElementContentwithDataTag(element: Element, dataTagPrefix: string, parentDataTagPrefix: string, aiBlobAttributeTag: string) {
185
-
186
- let elementContent: any = {};
187
- if(!element) {
188
- return elementContent;
189
- }
190
-
191
-
192
- let htmlContent = this._getHtmlIdAndContentName(element);
193
-
194
- if(isValueAssigned(parentDataTagPrefix)) {
195
- this._walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);
196
- } else {
197
- this._captureElementContentWithDataTag(element, elementContent, dataTagPrefix);
198
- }
199
-
200
-
201
- if (this._config.dataTags.useDefaultContentNameOrId) {
202
- if(!isValueAssigned(elementContent.id)) {
203
- elementContent.id = htmlContent.id || "";
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
- * 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
- private _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;
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
- return metaData;
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
- * 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
- 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
- * 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
- 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
- private _getHtmlIdAndContentName(element:Element) {
299
- let htmlContent: any = {};
300
- if(!element) {
301
- return htmlContent;
302
- }
316
+ return htmlContent;
317
+ }
303
318
 
304
- if (this._config.dataTags.useDefaultContentNameOrId) {
305
- const customizedContentName = this._config.callback.contentName ? this._config.callback.contentName(element, this._config.dataTags.useDefaultContentNameOrId) : "";
306
- const defaultContentName = this._getDefaultContentName(element, this._config.dataTags.useDefaultContentNameOrId);
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
- htmlContent = {
309
- id: element.id,
310
- contentName: customizedContentName || defaultContentName || element.getAttribute("alt")
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
- return htmlContent;
372
+ return parentInfo;
373
+ }
374
+ });
315
375
  }
316
376
 
317
377
  /**
318
- * Computes the parentId of a given element.
319
- * @param element - An html element
320
- * @returns An object containing the closest parentId , can be empty if nothing was found
321
- */
322
- private _getParentDetails(element: Element, elementContent: any, dataTagPrefix: string, aiBlobAttributeTag: string): IContent {
323
- const parentId = elementContent["parentid"];
324
- const parentName = elementContent["parentname"];
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
- * Check if parent info already set up, if so take and put into content, if not walk up the DOM to find correct info
335
- * @param element - An html element that the user wants to track
336
- * @returns An object containing the parent info, can be empty if nothing was found
337
- */
338
- private _populateParentInfo(element: Element, dataTagPrefix: string, aiBlobAttributeTag: string): IContent {
339
- let parentInfo: IContent = {};
340
- let parentId;
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
  }