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