@microsoft/applicationinsights-clickanalytics-js 3.0.0-beta.2302-03 → 3.0.0-beta.2302-05
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.3.0.0-beta.2302-03.cjs.js → ai.clck.3.0.0-beta.2302-05.cjs.js} +236 -172
- package/browser/ai.clck.3.0.0-beta.2302-05.cjs.js.map +1 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.cjs.min.js +6 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.cjs.min.js.map +1 -0
- package/browser/{ai.clck.3.0.0-beta.2302-03.gbl.js → ai.clck.3.0.0-beta.2302-05.gbl.js} +236 -172
- package/browser/ai.clck.3.0.0-beta.2302-05.gbl.js.map +1 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.gbl.min.js +6 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.gbl.min.js.map +1 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.integrity.json +66 -0
- package/browser/{ai.clck.3.0.0-beta.2302-03.js → ai.clck.3.0.0-beta.2302-05.js} +236 -172
- package/browser/ai.clck.3.0.0-beta.2302-05.js.map +1 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.min.js +6 -0
- package/browser/ai.clck.3.0.0-beta.2302-05.min.js.map +1 -0
- package/browser/ai.clck.3.cjs.js +235 -171
- package/browser/ai.clck.3.cjs.js.map +1 -1
- package/browser/ai.clck.3.cjs.min.js +2 -2
- package/browser/ai.clck.3.cjs.min.js.map +1 -1
- package/browser/ai.clck.3.gbl.js +235 -171
- package/browser/ai.clck.3.gbl.js.map +1 -1
- package/browser/ai.clck.3.gbl.min.js +2 -2
- package/browser/ai.clck.3.gbl.min.js.map +1 -1
- package/browser/ai.clck.3.js +235 -171
- package/browser/ai.clck.3.js.map +1 -1
- package/browser/ai.clck.3.min.js +2 -2
- package/browser/ai.clck.3.min.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.api.json +1 -1
- package/dist/applicationinsights-clickanalytics-js.d.ts +1 -1
- package/dist/applicationinsights-clickanalytics-js.js +235 -171
- 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 +1 -1
- package/dist-esm/Behaviours.js +1 -1
- package/dist-esm/ClickAnalyticsPlugin.js +36 -46
- package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
- package/dist-esm/DataCollector.js +3 -3
- package/dist-esm/DataCollector.js.map +1 -1
- package/dist-esm/Enums.js +1 -1
- package/dist-esm/Interfaces/Datamodel.js +1 -1
- package/dist-esm/__DynamicConstants.js +9 -7
- package/dist-esm/__DynamicConstants.js.map +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 +6 -6
- package/dist-esm/events/PageAction.js.map +1 -1
- package/dist-esm/events/WebEvent.js +3 -3
- package/dist-esm/events/WebEvent.js.map +1 -1
- package/dist-esm/handlers/AutoCaptureHandler.js +1 -1
- package/dist-esm/handlers/DomContentHandler.js +4 -4
- package/dist-esm/handlers/DomContentHandler.js.map +1 -1
- package/package.json +5 -5
- package/src/ClickAnalyticsPlugin.ts +28 -41
- package/src/__DynamicConstants.ts +8 -6
- package/types/__DynamicConstants.d.ts +8 -6
- package/types/tsdoc-metadata.json +1 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.cjs.js.map +0 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.cjs.min.js +0 -6
- package/browser/ai.clck.3.0.0-beta.2302-03.cjs.min.js.map +0 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.gbl.js.map +0 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.gbl.min.js +0 -6
- package/browser/ai.clck.3.0.0-beta.2302-03.gbl.min.js.map +0 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.integrity.json +0 -66
- package/browser/ai.clck.3.0.0-beta.2302-03.js.map +0 -1
- package/browser/ai.clck.3.0.0-beta.2302-03.min.js +0 -6
- package/browser/ai.clck.3.0.0-beta.2302-03.min.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Click Analytics, 3.0.0-beta.2302-
|
|
2
|
+
* Application Insights JavaScript SDK - Click Analytics, 3.0.0-beta.2302-05
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
9
9
|
import { _throwInternal, getDocument, hasDocument, isNullOrUndefined, objExtend } from "@microsoft/applicationinsights-core-js";
|
|
10
|
-
import { _DYN_ATTRIBUTES, _DYN_CAPTURE_ALL_META_DAT2, _DYN_CONTENT, _DYN_CONTENT_NAME, _DYN_CUSTOM_DATA_PREFIX, _DYN_DATA_TAGS, _DYN_GET_ATTRIBUTE, _DYN_GET_ELEMENT_CONTENT, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_NAME, _DYN_PARENT_DATA_TAG, _DYN_PARENT_ELEMENT, _DYN_PARENT_NODE, _DYN_TAG_NAME, _DYN_USE_DEFAULT_CONTENT_1, _DYN__CONFIG, _DYN__TRACE_LOGGER } from "../__DynamicConstants";
|
|
10
|
+
import { _DYN_ATTRIBUTES, _DYN_CAPTURE_ALL_META_DAT2, _DYN_CONTENT, _DYN_CONTENT_NAME, _DYN_CUSTOM_DATA_PREFIX, _DYN_DATA_TAGS, _DYN_GET_ATTRIBUTE, _DYN_GET_ELEMENT_CONTENT, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_META_DATA_PREFIX, _DYN_NAME, _DYN_PARENT_DATA_TAG, _DYN_PARENT_ELEMENT, _DYN_PARENT_NODE, _DYN_TAG_NAME, _DYN_USE_DEFAULT_CONTENT_1, _DYN__CONFIG, _DYN__TRACE_LOGGER } from "../__DynamicConstants";
|
|
11
11
|
import { isValueAssigned, removeInvalidElements, walkUpDomChainWithElementValidation } from "../common/Utils";
|
|
12
12
|
var MAX_CONTENTNAME_LENGTH = 200;
|
|
13
13
|
var DomContentHandler = /** @class */ (function () {
|
|
@@ -23,7 +23,7 @@ var DomContentHandler = /** @class */ (function () {
|
|
|
23
23
|
var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];
|
|
24
24
|
var metaTags = {};
|
|
25
25
|
if (hasDocument) {
|
|
26
|
-
metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], dataTags
|
|
26
|
+
metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], dataTags[_DYN_META_DATA_PREFIX /* @min:%2emetaDataPrefix */], false) :
|
|
27
27
|
_getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], "", false);
|
|
28
28
|
}
|
|
29
29
|
return metaTags;
|
|
@@ -253,7 +253,7 @@ var DomContentHandler = /** @class */ (function () {
|
|
|
253
253
|
return htmlContent;
|
|
254
254
|
}
|
|
255
255
|
if (dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) {
|
|
256
|
-
var customizedContentName = callback
|
|
256
|
+
var customizedContentName = callback[_DYN_CONTENT_NAME /* @min:%2econtentName */] ? callback[_DYN_CONTENT_NAME /* @min:%2econtentName */](element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) : "";
|
|
257
257
|
var defaultContentName = _getDefaultContentName(element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]);
|
|
258
258
|
htmlContent = (_a = {
|
|
259
259
|
id: element.id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomContentHandler.js.map","sources":["DomContentHandler.js"],"sourcesContent":["/**\r\n* @copyright Microsoft 2020\r\n*/\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { _throwInternal, getDocument, hasDocument, isNullOrUndefined, objExtend } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ATTRIBUTES, _DYN_CAPTURE_ALL_META_DAT2, _DYN_CONTENT, _DYN_CONTENT_NAME, _DYN_CUSTOM_DATA_PREFIX, _DYN_DATA_TAGS, _DYN_GET_ATTRIBUTE, _DYN_GET_ELEMENT_CONTENT, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_NAME, _DYN_PARENT_DATA_TAG, _DYN_PARENT_ELEMENT, _DYN_PARENT_NODE, _DYN_TAG_NAME, _DYN_USE_DEFAULT_CONTENT_1, _DYN__CONFIG, _DYN__TRACE_LOGGER } from \"../__DynamicConstants\";\r\nimport { isValueAssigned, removeInvalidElements, walkUpDomChainWithElementValidation } from \"../common/Utils\";\r\nvar MAX_CONTENTNAME_LENGTH = 200;\r\nvar DomContentHandler = /** @class */ (function () {\r\n /**\r\n * @param config - ClickAnalytics configuration object\r\n * @param traceLogger - Trace logger to log to console.\r\n */\r\n function DomContentHandler(_config, _traceLogger) {\r\n this._config = _config;\r\n this._traceLogger = _traceLogger;\r\n dynamicProto(DomContentHandler, this, function (_self) {\r\n _self.getMetadata = function () {\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var metaTags = {};\r\n if (hasDocument) {\r\n metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], dataTags.metaDataPrefix, false) :\r\n _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], \"\", false);\r\n }\r\n return metaTags;\r\n };\r\n _self[_DYN_GET_ELEMENT_CONTENT /* @min:%2egetElementContent */] = function (element) {\r\n if (!element) {\r\n return {};\r\n }\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var elementContent = {};\r\n var biBlobValue;\r\n var parentDataTagPrefix;\r\n var dataTagPrefix = dataTags[_DYN_CUSTOM_DATA_PREFIX /* @min:%2ecustomDataPrefix */];\r\n var aiBlobAttributeTag = dataTagPrefix + dataTags.aiBlobAttributeTag;\r\n if (isValueAssigned(dataTags[_DYN_PARENT_DATA_TAG /* @min:%2eparentDataTag */])) {\r\n parentDataTagPrefix = dataTagPrefix + dataTags[_DYN_PARENT_DATA_TAG /* @min:%2eparentDataTag */];\r\n }\r\n if (!_isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {\r\n // capture blob from element or hierarchy\r\n biBlobValue = element[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](aiBlobAttributeTag);\r\n if (biBlobValue) {\r\n try {\r\n elementContent = JSON.parse(biBlobValue);\r\n }\r\n catch (e) {\r\n _throwInternal(_self[_DYN__TRACE_LOGGER /* @min:%2e_traceLogger */], 1 /* eLoggingSeverity.CRITICAL */, 101 /* _eInternalMessageId.CannotParseAiBlobValue */, \"Can not parse \" + biBlobValue);\r\n }\r\n }\r\n else {\r\n // traverse up the DOM to find the closest parent with data-* tag defined\r\n //contentElement = walkUpDomChainWithElementValidation(element, _self._isTracked, dataTagPrefix);\r\n elementContent = objExtend(elementContent, _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n }\r\n else {\r\n elementContent = objExtend(elementContent, _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n removeInvalidElements(elementContent);\r\n if (parentDataTagPrefix) {\r\n elementContent = objExtend(elementContent, _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag));\r\n }\r\n return elementContent;\r\n };\r\n /**\r\n * Capture current level Element content\r\n */\r\n function _captureElementContentWithDataTag(contentElement, elementContent, dataTagPrefix) {\r\n for (var i = 0, attrib; i < contentElement.attributes[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n attrib = contentElement[_DYN_ATTRIBUTES /* @min:%2eattributes */][i];\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n var attribName = attrib[_DYN_NAME /* @min:%2ename */].replace(dataTagPrefix, \"\");\r\n elementContent[attribName] = attrib.value;\r\n }\r\n }\r\n /**\r\n * Walk Up the DOM to capture Element content\r\n */\r\n function _walkUpDomChainCaptureData(el, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var element = el;\r\n var parentDataTagFound = false;\r\n var elementLevelFlag = false; // Use this flag to capture 'id' only at the incoming html element level.\r\n while (!isNullOrUndefined(element) && !isNullOrUndefined(element[_DYN_ATTRIBUTES /* @min:%2eattributes */])) {\r\n var attributes = element[_DYN_ATTRIBUTES /* @min:%2eattributes */];\r\n for (var i = 0; i < attributes[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var attrib = attributes[i];\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](parentDataTagPrefix) === 0) {\r\n parentDataTagFound = true;\r\n }\r\n // Todo handle blob data\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](aiBlobAttributeTag) === 0) {\r\n continue;\r\n }\r\n var attribName = attrib[_DYN_NAME /* @min:%2ename */].replace(dataTagPrefix, \"\");\r\n if (elementLevelFlag && attribName === \"id\") {\r\n continue; // skip capturing id if not at the first level.\r\n }\r\n if (!isValueAssigned(elementContent[attribName])) {\r\n elementContent[attribName] = attrib.value;\r\n }\r\n }\r\n // break after current level;\r\n if (parentDataTagFound) {\r\n break;\r\n }\r\n elementLevelFlag = true; // after the initial level set this flag to true.\r\n element = element[_DYN_PARENT_NODE /* @min:%2eparentNode */];\r\n }\r\n }\r\n /**\r\n * Capture Element content along with Data Tag attributes and values\r\n */\r\n function _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var elementContent = {};\r\n if (!element) {\r\n return elementContent;\r\n }\r\n var htmlContent = _getHtmlIdAndContentName(element);\r\n elementContent = {\r\n id: htmlContent.id || \"\",\r\n contentName: htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] || \"\"\r\n };\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n _walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);\r\n }\r\n // Validate to ensure the minimum required field 'id' or 'contentName' is present.\r\n // The content schema defines id, aN and sN as required fields. However,\r\n // requiring these fields would result in majority of adopter's content from being collected.\r\n // Just throw a warning and continue collection.\r\n if (!elementContent.id && !elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */]) {\r\n _throwInternal(_traceLogger, 2 /* eLoggingSeverity.WARNING */, 102 /* _eInternalMessageId.InvalidContentBlob */, \"Invalid content blob. Missing required attributes (id, contentName. \" +\r\n \" Content information will still be collected!\");\r\n }\r\n return elementContent;\r\n }\r\n /**\r\n * Capture Element content along with Data Tag attributes and values\r\n */\r\n function _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var elementContent = {};\r\n if (!element) {\r\n return elementContent;\r\n }\r\n var htmlContent = _getHtmlIdAndContentName(element);\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n _walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);\r\n }\r\n else {\r\n _captureElementContentWithDataTag(element, elementContent, dataTagPrefix);\r\n }\r\n if (dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) {\r\n if (!isValueAssigned(elementContent.id)) {\r\n elementContent.id = htmlContent.id || \"\";\r\n }\r\n elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] = htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] || \"\";\r\n }\r\n // Validate to ensure the minimum required field 'id' or 'contentName' is present.\r\n // The content schema defines id, aN and sN as required fields. However,\r\n // requiring these fields would result in majority of adopter's content from being collected.\r\n // Just throw a warning and continue collection.\r\n if (!elementContent.id && !elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */]) {\r\n _throwInternal(_traceLogger, 2 /* eLoggingSeverity.WARNING */, 102 /* _eInternalMessageId.InvalidContentBlob */, \"Invalid content blob. Missing required attributes (id, contentName. \" +\r\n \" Content information will still be collected!\");\r\n }\r\n return elementContent;\r\n }\r\n /**\r\n * Retrieve a specified metadata tag value from the DOM.\r\n * @param captureAllMetaDataContent - Flag to capture all metadata content\r\n * @param prefix - Prefix to search the metatags with.\r\n * @param removePrefix - Specifies if the prefix must be excluded from key names in the returned collection.\r\n * @returns Metadata collection/property bag\r\n */\r\n function _getMetaDataFromDOM(captureAllMetaDataContent, prefix, removePrefix) {\r\n var metaElements;\r\n var metaData = {};\r\n if (hasDocument) {\r\n metaElements = document.querySelectorAll(\"meta\");\r\n for (var i = 0; i < metaElements[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var meta = metaElements[i];\r\n if (meta[_DYN_NAME /* @min:%2ename */]) {\r\n if (captureAllMetaDataContent || meta.name[_DYN_INDEX_OF /* @min:%2eindexOf */](prefix) === 0) {\r\n var name_1 = removePrefix ? meta[_DYN_NAME /* @min:%2ename */].replace(prefix, \"\") : meta[_DYN_NAME /* @min:%2ename */];\r\n metaData[name_1] = meta[_DYN_CONTENT /* @min:%2econtent */];\r\n }\r\n }\r\n }\r\n }\r\n return metaData;\r\n }\r\n /**\r\n * Gets the default content name.\r\n * @param element - An html element\r\n * @param useDefaultContentNameOrId - Flag indicating if an element is market PII.\r\n * @returns Content name\r\n */\r\n function _getDefaultContentName(element, useDefaultContentName) {\r\n if (useDefaultContentName === false || !element[_DYN_TAG_NAME /* @min:%2etagName */]) {\r\n return \"\";\r\n }\r\n var doc = getDocument() || {};\r\n var contentName;\r\n switch (element[_DYN_TAG_NAME /* @min:%2etagName */]) {\r\n case \"A\":\r\n contentName = doc.all ? element.innerText || element.innerHTML : element.text || element.innerHTML;\r\n break;\r\n case \"IMG\":\r\n case \"AREA\":\r\n contentName = element.alt;\r\n break;\r\n default:\r\n contentName = element.value || element[_DYN_NAME /* @min:%2ename */] || element.alt || element.innerText || element.id;\r\n }\r\n return contentName.substring(0, MAX_CONTENTNAME_LENGTH);\r\n }\r\n /**\r\n * Check if the user wants to track the element, which means if the element has any tags with data-* or customDataPrefix\r\n * @param element - An html element\r\n * @returns true if any data-* exist, otherwise return false\r\n */\r\n function _isTracked(element, dataTag, aiBlobAttributeTag) {\r\n var attrs = element[_DYN_ATTRIBUTES /* @min:%2eattributes */];\r\n var dataTagFound = false;\r\n for (var i = 0; i < attrs[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var attributeName = attrs[i][_DYN_NAME /* @min:%2ename */];\r\n if (attributeName === aiBlobAttributeTag) {\r\n // ignore if the attribute name is equal to aiBlobAttributeTag\r\n return false;\r\n }\r\n else if (attributeName[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTag) === 0) {\r\n dataTagFound = true;\r\n }\r\n }\r\n return dataTagFound;\r\n }\r\n function _getHtmlIdAndContentName(element) {\r\n var _a;\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var callback = (_self[_DYN__CONFIG /* @min:%2e_config */] || {}).callback;\r\n var htmlContent = {};\r\n if (!element) {\r\n return htmlContent;\r\n }\r\n if (dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) {\r\n var customizedContentName = callback.contentName ? callback.contentName(element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) : \"\";\r\n var defaultContentName = _getDefaultContentName(element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]);\r\n htmlContent = (_a = {\r\n id: element.id\r\n },\r\n _a[_DYN_CONTENT_NAME /* @min:contentName */] = customizedContentName || defaultContentName || element[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](\"alt\"),\r\n _a);\r\n }\r\n return htmlContent;\r\n }\r\n /**\r\n * Computes the parentId of a given element.\r\n * @param element - An html element\r\n * @returns An object containing the closest parentId , can be empty if nothing was found\r\n */\r\n function _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag) {\r\n var parentId = elementContent[\"parentid\"];\r\n var parentName = elementContent[\"parentname\"];\r\n var parentInfo = {};\r\n if (parentId || parentName || !element) {\r\n return parentInfo;\r\n }\r\n return _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag);\r\n }\r\n /**\r\n * Check if parent info already set up, if so take and put into content, if not walk up the DOM to find correct info\r\n * @param element - An html element that the user wants to track\r\n * @returns An object containing the parent info, can be empty if nothing was found\r\n */\r\n function _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag) {\r\n var parentInfo = {};\r\n var parentId;\r\n // if the user does not set up parent info, walk to the DOM, find the closest parent element (with tags) and populate the info\r\n var closestParentElement = walkUpDomChainWithElementValidation(element[_DYN_PARENT_ELEMENT /* @min:%2eparentElement */], _isTracked, dataTagPrefix);\r\n if (closestParentElement) {\r\n var dataAttr = closestParentElement[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](aiBlobAttributeTag) || element[aiBlobAttributeTag];\r\n if (dataAttr) {\r\n try {\r\n var telemetryObject = JSON.parse(dataAttr);\r\n }\r\n catch (e) {\r\n _throwInternal(_traceLogger, 1 /* eLoggingSeverity.CRITICAL */, 101 /* _eInternalMessageId.CannotParseAiBlobValue */, \"Can not parse \" + dataAttr);\r\n }\r\n if (telemetryObject) {\r\n parentId = telemetryObject.id;\r\n }\r\n }\r\n else {\r\n parentId = closestParentElement[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](dataTagPrefix + \"id\");\r\n }\r\n }\r\n if (parentId) {\r\n parentInfo[\"parentid\"] = parentId;\r\n }\r\n else {\r\n var htmlContent = _getHtmlIdAndContentName(element[_DYN_PARENT_ELEMENT /* @min:%2eparentElement */]);\r\n parentInfo[\"parentid\"] = htmlContent.id;\r\n parentInfo[\"parentname\"] = htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */];\r\n }\r\n return parentInfo;\r\n }\r\n });\r\n }\r\n /**\r\n * Collect metatags from DOM.\r\n * Collect data from meta tags.\r\n * @returns {object} - Metatags collection/property bag\r\n */\r\n DomContentHandler.prototype.getMetadata = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Collect data-* attributes for the given element.\r\n * All attributes with data-* prefix or user provided customDataPrefix are collected.'data-*' prefix is removed from the key name.\r\n * @param element - The element from which attributes need to be collected.\r\n * @returns String representation of the Json array of element attributes\r\n */\r\n DomContentHandler.prototype.getElementContent = function (element) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return DomContentHandler;\r\n}());\r\nexport { DomContentHandler };\r\n//# sourceMappingURL=DomContentHandler.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;kEAkBM,CAAC;;;;;6BACsB;AAC7B;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"DomContentHandler.js.map","sources":["DomContentHandler.js"],"sourcesContent":["/**\r\n* @copyright Microsoft 2020\r\n*/\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { _throwInternal, getDocument, hasDocument, isNullOrUndefined, objExtend } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ATTRIBUTES, _DYN_CAPTURE_ALL_META_DAT2, _DYN_CONTENT, _DYN_CONTENT_NAME, _DYN_CUSTOM_DATA_PREFIX, _DYN_DATA_TAGS, _DYN_GET_ATTRIBUTE, _DYN_GET_ELEMENT_CONTENT, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_META_DATA_PREFIX, _DYN_NAME, _DYN_PARENT_DATA_TAG, _DYN_PARENT_ELEMENT, _DYN_PARENT_NODE, _DYN_TAG_NAME, _DYN_USE_DEFAULT_CONTENT_1, _DYN__CONFIG, _DYN__TRACE_LOGGER } from \"../__DynamicConstants\";\r\nimport { isValueAssigned, removeInvalidElements, walkUpDomChainWithElementValidation } from \"../common/Utils\";\r\nvar MAX_CONTENTNAME_LENGTH = 200;\r\nvar DomContentHandler = /** @class */ (function () {\r\n /**\r\n * @param config - ClickAnalytics configuration object\r\n * @param traceLogger - Trace logger to log to console.\r\n */\r\n function DomContentHandler(_config, _traceLogger) {\r\n this._config = _config;\r\n this._traceLogger = _traceLogger;\r\n dynamicProto(DomContentHandler, this, function (_self) {\r\n _self.getMetadata = function () {\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var metaTags = {};\r\n if (hasDocument) {\r\n metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], dataTags[_DYN_META_DATA_PREFIX /* @min:%2emetaDataPrefix */], false) :\r\n _getMetaDataFromDOM(dataTags[_DYN_CAPTURE_ALL_META_DAT2 /* @min:%2ecaptureAllMetaDataContent */], \"\", false);\r\n }\r\n return metaTags;\r\n };\r\n _self[_DYN_GET_ELEMENT_CONTENT /* @min:%2egetElementContent */] = function (element) {\r\n if (!element) {\r\n return {};\r\n }\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var elementContent = {};\r\n var biBlobValue;\r\n var parentDataTagPrefix;\r\n var dataTagPrefix = dataTags[_DYN_CUSTOM_DATA_PREFIX /* @min:%2ecustomDataPrefix */];\r\n var aiBlobAttributeTag = dataTagPrefix + dataTags.aiBlobAttributeTag;\r\n if (isValueAssigned(dataTags[_DYN_PARENT_DATA_TAG /* @min:%2eparentDataTag */])) {\r\n parentDataTagPrefix = dataTagPrefix + dataTags[_DYN_PARENT_DATA_TAG /* @min:%2eparentDataTag */];\r\n }\r\n if (!_isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {\r\n // capture blob from element or hierarchy\r\n biBlobValue = element[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](aiBlobAttributeTag);\r\n if (biBlobValue) {\r\n try {\r\n elementContent = JSON.parse(biBlobValue);\r\n }\r\n catch (e) {\r\n _throwInternal(_self[_DYN__TRACE_LOGGER /* @min:%2e_traceLogger */], 1 /* eLoggingSeverity.CRITICAL */, 101 /* _eInternalMessageId.CannotParseAiBlobValue */, \"Can not parse \" + biBlobValue);\r\n }\r\n }\r\n else {\r\n // traverse up the DOM to find the closest parent with data-* tag defined\r\n //contentElement = walkUpDomChainWithElementValidation(element, _self._isTracked, dataTagPrefix);\r\n elementContent = objExtend(elementContent, _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n }\r\n else {\r\n elementContent = objExtend(elementContent, _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n removeInvalidElements(elementContent);\r\n if (parentDataTagPrefix) {\r\n elementContent = objExtend(elementContent, _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag));\r\n }\r\n return elementContent;\r\n };\r\n /**\r\n * Capture current level Element content\r\n */\r\n function _captureElementContentWithDataTag(contentElement, elementContent, dataTagPrefix) {\r\n for (var i = 0, attrib; i < contentElement.attributes[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n attrib = contentElement[_DYN_ATTRIBUTES /* @min:%2eattributes */][i];\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n var attribName = attrib[_DYN_NAME /* @min:%2ename */].replace(dataTagPrefix, \"\");\r\n elementContent[attribName] = attrib.value;\r\n }\r\n }\r\n /**\r\n * Walk Up the DOM to capture Element content\r\n */\r\n function _walkUpDomChainCaptureData(el, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var element = el;\r\n var parentDataTagFound = false;\r\n var elementLevelFlag = false; // Use this flag to capture 'id' only at the incoming html element level.\r\n while (!isNullOrUndefined(element) && !isNullOrUndefined(element[_DYN_ATTRIBUTES /* @min:%2eattributes */])) {\r\n var attributes = element[_DYN_ATTRIBUTES /* @min:%2eattributes */];\r\n for (var i = 0; i < attributes[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var attrib = attributes[i];\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](parentDataTagPrefix) === 0) {\r\n parentDataTagFound = true;\r\n }\r\n // Todo handle blob data\r\n if (attrib.name[_DYN_INDEX_OF /* @min:%2eindexOf */](aiBlobAttributeTag) === 0) {\r\n continue;\r\n }\r\n var attribName = attrib[_DYN_NAME /* @min:%2ename */].replace(dataTagPrefix, \"\");\r\n if (elementLevelFlag && attribName === \"id\") {\r\n continue; // skip capturing id if not at the first level.\r\n }\r\n if (!isValueAssigned(elementContent[attribName])) {\r\n elementContent[attribName] = attrib.value;\r\n }\r\n }\r\n // break after current level;\r\n if (parentDataTagFound) {\r\n break;\r\n }\r\n elementLevelFlag = true; // after the initial level set this flag to true.\r\n element = element[_DYN_PARENT_NODE /* @min:%2eparentNode */];\r\n }\r\n }\r\n /**\r\n * Capture Element content along with Data Tag attributes and values\r\n */\r\n function _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var elementContent = {};\r\n if (!element) {\r\n return elementContent;\r\n }\r\n var htmlContent = _getHtmlIdAndContentName(element);\r\n elementContent = {\r\n id: htmlContent.id || \"\",\r\n contentName: htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] || \"\"\r\n };\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n _walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);\r\n }\r\n // Validate to ensure the minimum required field 'id' or 'contentName' is present.\r\n // The content schema defines id, aN and sN as required fields. However,\r\n // requiring these fields would result in majority of adopter's content from being collected.\r\n // Just throw a warning and continue collection.\r\n if (!elementContent.id && !elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */]) {\r\n _throwInternal(_traceLogger, 2 /* eLoggingSeverity.WARNING */, 102 /* _eInternalMessageId.InvalidContentBlob */, \"Invalid content blob. Missing required attributes (id, contentName. \" +\r\n \" Content information will still be collected!\");\r\n }\r\n return elementContent;\r\n }\r\n /**\r\n * Capture Element content along with Data Tag attributes and values\r\n */\r\n function _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var elementContent = {};\r\n if (!element) {\r\n return elementContent;\r\n }\r\n var htmlContent = _getHtmlIdAndContentName(element);\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n _walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);\r\n }\r\n else {\r\n _captureElementContentWithDataTag(element, elementContent, dataTagPrefix);\r\n }\r\n if (dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) {\r\n if (!isValueAssigned(elementContent.id)) {\r\n elementContent.id = htmlContent.id || \"\";\r\n }\r\n elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] = htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */] || \"\";\r\n }\r\n // Validate to ensure the minimum required field 'id' or 'contentName' is present.\r\n // The content schema defines id, aN and sN as required fields. However,\r\n // requiring these fields would result in majority of adopter's content from being collected.\r\n // Just throw a warning and continue collection.\r\n if (!elementContent.id && !elementContent[_DYN_CONTENT_NAME /* @min:%2econtentName */]) {\r\n _throwInternal(_traceLogger, 2 /* eLoggingSeverity.WARNING */, 102 /* _eInternalMessageId.InvalidContentBlob */, \"Invalid content blob. Missing required attributes (id, contentName. \" +\r\n \" Content information will still be collected!\");\r\n }\r\n return elementContent;\r\n }\r\n /**\r\n * Retrieve a specified metadata tag value from the DOM.\r\n * @param captureAllMetaDataContent - Flag to capture all metadata content\r\n * @param prefix - Prefix to search the metatags with.\r\n * @param removePrefix - Specifies if the prefix must be excluded from key names in the returned collection.\r\n * @returns Metadata collection/property bag\r\n */\r\n function _getMetaDataFromDOM(captureAllMetaDataContent, prefix, removePrefix) {\r\n var metaElements;\r\n var metaData = {};\r\n if (hasDocument) {\r\n metaElements = document.querySelectorAll(\"meta\");\r\n for (var i = 0; i < metaElements[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var meta = metaElements[i];\r\n if (meta[_DYN_NAME /* @min:%2ename */]) {\r\n if (captureAllMetaDataContent || meta.name[_DYN_INDEX_OF /* @min:%2eindexOf */](prefix) === 0) {\r\n var name_1 = removePrefix ? meta[_DYN_NAME /* @min:%2ename */].replace(prefix, \"\") : meta[_DYN_NAME /* @min:%2ename */];\r\n metaData[name_1] = meta[_DYN_CONTENT /* @min:%2econtent */];\r\n }\r\n }\r\n }\r\n }\r\n return metaData;\r\n }\r\n /**\r\n * Gets the default content name.\r\n * @param element - An html element\r\n * @param useDefaultContentNameOrId - Flag indicating if an element is market PII.\r\n * @returns Content name\r\n */\r\n function _getDefaultContentName(element, useDefaultContentName) {\r\n if (useDefaultContentName === false || !element[_DYN_TAG_NAME /* @min:%2etagName */]) {\r\n return \"\";\r\n }\r\n var doc = getDocument() || {};\r\n var contentName;\r\n switch (element[_DYN_TAG_NAME /* @min:%2etagName */]) {\r\n case \"A\":\r\n contentName = doc.all ? element.innerText || element.innerHTML : element.text || element.innerHTML;\r\n break;\r\n case \"IMG\":\r\n case \"AREA\":\r\n contentName = element.alt;\r\n break;\r\n default:\r\n contentName = element.value || element[_DYN_NAME /* @min:%2ename */] || element.alt || element.innerText || element.id;\r\n }\r\n return contentName.substring(0, MAX_CONTENTNAME_LENGTH);\r\n }\r\n /**\r\n * Check if the user wants to track the element, which means if the element has any tags with data-* or customDataPrefix\r\n * @param element - An html element\r\n * @returns true if any data-* exist, otherwise return false\r\n */\r\n function _isTracked(element, dataTag, aiBlobAttributeTag) {\r\n var attrs = element[_DYN_ATTRIBUTES /* @min:%2eattributes */];\r\n var dataTagFound = false;\r\n for (var i = 0; i < attrs[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var attributeName = attrs[i][_DYN_NAME /* @min:%2ename */];\r\n if (attributeName === aiBlobAttributeTag) {\r\n // ignore if the attribute name is equal to aiBlobAttributeTag\r\n return false;\r\n }\r\n else if (attributeName[_DYN_INDEX_OF /* @min:%2eindexOf */](dataTag) === 0) {\r\n dataTagFound = true;\r\n }\r\n }\r\n return dataTagFound;\r\n }\r\n function _getHtmlIdAndContentName(element) {\r\n var _a;\r\n var dataTags = (_self[_DYN__CONFIG /* @min:%2e_config */] || {})[_DYN_DATA_TAGS /* @min:%2edataTags */];\r\n var callback = (_self[_DYN__CONFIG /* @min:%2e_config */] || {}).callback;\r\n var htmlContent = {};\r\n if (!element) {\r\n return htmlContent;\r\n }\r\n if (dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) {\r\n var customizedContentName = callback[_DYN_CONTENT_NAME /* @min:%2econtentName */] ? callback[_DYN_CONTENT_NAME /* @min:%2econtentName */](element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]) : \"\";\r\n var defaultContentName = _getDefaultContentName(element, dataTags[_DYN_USE_DEFAULT_CONTENT_1 /* @min:%2euseDefaultContentNameOrId */]);\r\n htmlContent = (_a = {\r\n id: element.id\r\n },\r\n _a[_DYN_CONTENT_NAME /* @min:contentName */] = customizedContentName || defaultContentName || element[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](\"alt\"),\r\n _a);\r\n }\r\n return htmlContent;\r\n }\r\n /**\r\n * Computes the parentId of a given element.\r\n * @param element - An html element\r\n * @returns An object containing the closest parentId , can be empty if nothing was found\r\n */\r\n function _getParentDetails(element, elementContent, dataTagPrefix, aiBlobAttributeTag) {\r\n var parentId = elementContent[\"parentid\"];\r\n var parentName = elementContent[\"parentname\"];\r\n var parentInfo = {};\r\n if (parentId || parentName || !element) {\r\n return parentInfo;\r\n }\r\n return _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag);\r\n }\r\n /**\r\n * Check if parent info already set up, if so take and put into content, if not walk up the DOM to find correct info\r\n * @param element - An html element that the user wants to track\r\n * @returns An object containing the parent info, can be empty if nothing was found\r\n */\r\n function _populateParentInfo(element, dataTagPrefix, aiBlobAttributeTag) {\r\n var parentInfo = {};\r\n var parentId;\r\n // if the user does not set up parent info, walk to the DOM, find the closest parent element (with tags) and populate the info\r\n var closestParentElement = walkUpDomChainWithElementValidation(element[_DYN_PARENT_ELEMENT /* @min:%2eparentElement */], _isTracked, dataTagPrefix);\r\n if (closestParentElement) {\r\n var dataAttr = closestParentElement[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](aiBlobAttributeTag) || element[aiBlobAttributeTag];\r\n if (dataAttr) {\r\n try {\r\n var telemetryObject = JSON.parse(dataAttr);\r\n }\r\n catch (e) {\r\n _throwInternal(_traceLogger, 1 /* eLoggingSeverity.CRITICAL */, 101 /* _eInternalMessageId.CannotParseAiBlobValue */, \"Can not parse \" + dataAttr);\r\n }\r\n if (telemetryObject) {\r\n parentId = telemetryObject.id;\r\n }\r\n }\r\n else {\r\n parentId = closestParentElement[_DYN_GET_ATTRIBUTE /* @min:%2egetAttribute */](dataTagPrefix + \"id\");\r\n }\r\n }\r\n if (parentId) {\r\n parentInfo[\"parentid\"] = parentId;\r\n }\r\n else {\r\n var htmlContent = _getHtmlIdAndContentName(element[_DYN_PARENT_ELEMENT /* @min:%2eparentElement */]);\r\n parentInfo[\"parentid\"] = htmlContent.id;\r\n parentInfo[\"parentname\"] = htmlContent[_DYN_CONTENT_NAME /* @min:%2econtentName */];\r\n }\r\n return parentInfo;\r\n }\r\n });\r\n }\r\n /**\r\n * Collect metatags from DOM.\r\n * Collect data from meta tags.\r\n * @returns {object} - Metatags collection/property bag\r\n */\r\n DomContentHandler.prototype.getMetadata = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Collect data-* attributes for the given element.\r\n * All attributes with data-* prefix or user provided customDataPrefix are collected.'data-*' prefix is removed from the key name.\r\n * @param element - The element from which attributes need to be collected.\r\n * @returns String representation of the Json array of element attributes\r\n */\r\n DomContentHandler.prototype.getElementContent = function (element) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return DomContentHandler;\r\n}());\r\nexport { DomContentHandler };\r\n//# sourceMappingURL=DomContentHandler.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;kEAkBM,CAAC;;;;;6BACsB;AAC7B;AACA;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/applicationinsights-clickanalytics-js",
|
|
3
|
-
"version": "3.0.0-beta.2302-
|
|
3
|
+
"version": "3.0.0-beta.2302-05",
|
|
4
4
|
"description": "Microsoft Application Insights Click Analytics extension",
|
|
5
5
|
"homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
|
|
6
6
|
"author": "Microsoft Application Insights Team",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@microsoft/dynamicproto-js": "^1.1.7",
|
|
49
49
|
"@microsoft/applicationinsights-shims": "2.0.2",
|
|
50
|
-
"@microsoft/applicationinsights-core-js": "3.0.0-beta.2302-
|
|
51
|
-
"@microsoft/applicationinsights-common": "3.0.0-beta.2302-
|
|
52
|
-
"@microsoft/applicationinsights-properties-js": "3.0.0-beta.2302-
|
|
53
|
-
"@nevware21/ts-utils": "
|
|
50
|
+
"@microsoft/applicationinsights-core-js": "3.0.0-beta.2302-05",
|
|
51
|
+
"@microsoft/applicationinsights-common": "3.0.0-beta.2302-05",
|
|
52
|
+
"@microsoft/applicationinsights-properties-js": "3.0.0-beta.2302-05",
|
|
53
|
+
"@nevware21/ts-utils": ">= 0.7 < 2.x"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
@@ -7,13 +7,13 @@ import { IConfig, IPropertiesPlugin, PropertiesPluginIdentifier } from "@microso
|
|
|
7
7
|
import {
|
|
8
8
|
BaseTelemetryPlugin, IAppInsightsCore, IConfigDefaults, IConfiguration, ICustomProperties, IPlugin, IProcessTelemetryContext,
|
|
9
9
|
IProcessTelemetryUnloadContext, ITelemetryItem, ITelemetryPluginChain, ITelemetryUnloadState, _eInternalMessageId, _throwInternal,
|
|
10
|
-
arrForEach,
|
|
11
|
-
unloadComponents
|
|
10
|
+
arrForEach, cfgDfFunc, cfgDfMerge, cfgDfString, cfgDfValidate, createProcessTelemetryContext, dumpObj, eLoggingSeverity,
|
|
11
|
+
getExceptionName, isNullOrUndefined, onConfigChange, throwError, unloadComponents
|
|
12
12
|
} from "@microsoft/applicationinsights-core-js";
|
|
13
13
|
import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
|
|
14
|
-
import { hasDocument,
|
|
14
|
+
import { hasDocument, objDeepFreeze, objDefineProp } from "@nevware21/ts-utils";
|
|
15
15
|
import {
|
|
16
|
-
IAutoCaptureHandler, IClickAnalyticsConfiguration, IContentHandler, ICoreData, ICustomDataTags, IPageActionTelemetry
|
|
16
|
+
IAutoCaptureHandler, IClickAnalyticsConfiguration, IContentHandler, ICoreData, ICustomDataTags, IPageActionTelemetry, IValueCallback
|
|
17
17
|
} from "./Interfaces/Datamodel";
|
|
18
18
|
import {
|
|
19
19
|
BehaviorEnumValidator, BehaviorMapValidator, BehaviorValueValidator, DEFAULT_AI_BLOB_ATTRIBUTE_TAG, DEFAULT_DATA_PREFIX,
|
|
@@ -25,51 +25,38 @@ import { DomContentHandler } from "./handlers/DomContentHandler";
|
|
|
25
25
|
|
|
26
26
|
export { BehaviorMapValidator, BehaviorValueValidator, BehaviorEnumValidator }
|
|
27
27
|
|
|
28
|
-
const dataTagsDefault = {
|
|
29
|
-
useDefaultContentNameOrId: false,
|
|
30
|
-
aiBlobAttributeTag: DEFAULT_AI_BLOB_ATTRIBUTE_TAG,
|
|
31
|
-
customDataPrefix: DEFAULT_DATA_PREFIX,
|
|
32
|
-
captureAllMetaDataContent: false,
|
|
33
|
-
dntDataTag: DEFAULT_DONOT_TRACK_TAG,
|
|
34
|
-
metaDataPrefix: "",
|
|
35
|
-
parentDataTag: ""
|
|
36
|
-
} as ICustomDataTags;
|
|
37
|
-
|
|
38
|
-
const coreDataDefault = {
|
|
39
|
-
eferrerUri: hasDocument ? document.referrer : "",
|
|
40
|
-
requestUri: "",
|
|
41
|
-
pageName: "",
|
|
42
|
-
pageType: ""
|
|
43
|
-
} as ICoreData;
|
|
44
|
-
|
|
45
28
|
const defaultValues: IConfigDefaults<IClickAnalyticsConfiguration> = objDeepFreeze({
|
|
46
29
|
autoCapture: true,
|
|
47
|
-
callback: {
|
|
48
|
-
pageActionPageTags:
|
|
49
|
-
pageName:
|
|
50
|
-
contentName:
|
|
51
|
-
},
|
|
30
|
+
callback: cfgDfMerge<IValueCallback, IClickAnalyticsConfiguration>({
|
|
31
|
+
pageActionPageTags: cfgDfFunc(),
|
|
32
|
+
pageName: cfgDfFunc(),
|
|
33
|
+
contentName: cfgDfFunc()
|
|
34
|
+
}),
|
|
52
35
|
pageTags: {},
|
|
53
|
-
coreData:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
coreData: cfgDfMerge<ICoreData, IClickAnalyticsConfiguration>({
|
|
37
|
+
referrerUri: hasDocument ? document.referrer : "",
|
|
38
|
+
requestUri: cfgDfString(),
|
|
39
|
+
pageName: cfgDfString(),
|
|
40
|
+
pageType: cfgDfString()
|
|
41
|
+
}),
|
|
42
|
+
dataTags: cfgDfMerge<ICustomDataTags, IClickAnalyticsConfiguration>({
|
|
43
|
+
useDefaultContentNameOrId: false,
|
|
44
|
+
aiBlobAttributeTag: DEFAULT_AI_BLOB_ATTRIBUTE_TAG,
|
|
45
|
+
customDataPrefix: cfgDfValidate(_dataPrefixChk, DEFAULT_DATA_PREFIX),
|
|
46
|
+
captureAllMetaDataContent: false,
|
|
47
|
+
dntDataTag: DEFAULT_DONOT_TRACK_TAG,
|
|
48
|
+
metaDataPrefix: cfgDfString(),
|
|
49
|
+
parentDataTag: cfgDfString()
|
|
50
|
+
}),
|
|
51
|
+
behaviorValidator: cfgDfFunc((key:string) => key || ""),
|
|
52
|
+
defaultRightClickBhvr: cfgDfString(),
|
|
57
53
|
dropInvalidEvents : false,
|
|
58
54
|
urlCollectHash: false,
|
|
59
55
|
urlCollectQuery: false
|
|
60
56
|
});
|
|
61
57
|
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
objForEachKey(def, (key, obj) => {
|
|
65
|
-
val[key] = val[key] || obj;
|
|
66
|
-
if (key === "customDataPrefix") {
|
|
67
|
-
let prefix = val[key];
|
|
68
|
-
val[key] = prefix && prefix.indexOf(DEFAULT_DATA_PREFIX) === 0? prefix : DEFAULT_DATA_PREFIX;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return val;
|
|
58
|
+
function _dataPrefixChk(val: any) {
|
|
59
|
+
return val && val.indexOf(DEFAULT_DATA_PREFIX) === 0;
|
|
73
60
|
}
|
|
74
61
|
|
|
75
62
|
export class ClickAnalyticsPlugin extends BaseTelemetryPlugin {
|
|
@@ -14,24 +14,27 @@ export const _DYN_INDEX_OF = "indexOf"; // Count: 9
|
|
|
14
14
|
export const _DYN_TRACK_PAGE_ACTION = "trackPageAction"; // Count: 4
|
|
15
15
|
export const _DYN_PAGE_ACTION_PAGE_TAG0 = "pageActionPageTags"; // Count: 2
|
|
16
16
|
export const _DYN__DO_UNLOAD = "_doUnload"; // Count: 3
|
|
17
|
+
export const _DYN_PAGE_NAME = "pageName"; // Count: 10
|
|
18
|
+
export const _DYN_CONTENT_NAME = "contentName"; // Count: 13
|
|
19
|
+
export const _DYN_REQUEST_URI = "requestUri"; // Count: 4
|
|
20
|
+
export const _DYN_PAGE_TYPE = "pageType"; // Count: 7
|
|
17
21
|
export const _DYN_USE_DEFAULT_CONTENT_1 = "useDefaultContentNameOrId"; // Count: 5
|
|
18
22
|
export const _DYN_CAPTURE_ALL_META_DAT2 = "captureAllMetaDataContent"; // Count: 3
|
|
19
|
-
export const
|
|
20
|
-
export const
|
|
23
|
+
export const _DYN_META_DATA_PREFIX = "metaDataPrefix"; // Count: 3
|
|
24
|
+
export const _DYN_PARENT_DATA_TAG = "parentDataTag"; // Count: 4
|
|
21
25
|
export const _DYN_BEHAVIOR_VALIDATOR = "behaviorValidator"; // Count: 2
|
|
26
|
+
export const _DYN_DEFAULT_RIGHT_CLICK_3 = "defaultRightClickBhvr"; // Count: 2
|
|
22
27
|
export const _DYN_LENGTH = "length"; // Count: 5
|
|
23
28
|
export const _DYN_TAG_NAME = "tagName"; // Count: 4
|
|
24
29
|
export const _DYN_TO_UPPER_CASE = "toUpperCase"; // Count: 4
|
|
25
30
|
export const _DYN_PATHNAME = "pathname"; // Count: 3
|
|
26
31
|
export const _DYN_ADD_EVENT_LISTENER = "addEventListener"; // Count: 2
|
|
27
32
|
export const _DYN_CORE_DATA = "coreData"; // Count: 4
|
|
28
|
-
export const _DYN_REQUEST_URI = "requestUri"; // Count: 3
|
|
29
33
|
export const _DYN_GET_ATTRIBUTE = "getAttribute"; // Count: 6
|
|
30
34
|
export const _DYN_PARENT_NODE = "parentNode"; // Count: 3
|
|
31
35
|
export const _DYN_CUSTOM_DATA_PREFIX = "customDataPrefix"; // Count: 3
|
|
32
36
|
export const _DYN_NAME = "name"; // Count: 8
|
|
33
37
|
export const _DYN_DATA = "data"; // Count: 15
|
|
34
|
-
export const _DYN_PAGE_TYPE = "pageType"; // Count: 6
|
|
35
38
|
export const _DYN_PROPERTIES = "properties"; // Count: 4
|
|
36
39
|
export const _DYN_ACTION_TYPE = "actionType"; // Count: 9
|
|
37
40
|
export const _DYN_BEHAVIOR = "behavior"; // Count: 7
|
|
@@ -40,7 +43,7 @@ export const _DYN_CONTENT = "content"; // Count: 4
|
|
|
40
43
|
export const _DYN_REF_URI = "refUri"; // Count: 4
|
|
41
44
|
export const _DYN_PARENT_ID = "parentId"; // Count: 3
|
|
42
45
|
export const _DYN_CAPTURE_PAGE_ACTION = "capturePageAction"; // Count: 2
|
|
43
|
-
export const
|
|
46
|
+
export const _DYN_SET_COMMON_PROPERTIE4 = "setCommonProperties"; // Count: 2
|
|
44
47
|
export const _DYN_GET_ELEMENT_CONTENT = "getElementContent"; // Count: 2
|
|
45
48
|
export const _DYN__GET_VALID_BEHAVIOR = "_getValidBehavior"; // Count: 3
|
|
46
49
|
export const _DYN__TRACE_LOGGER = "_traceLogger"; // Count: 3
|
|
@@ -48,7 +51,6 @@ export const _DYN_CLICK_COORDINATE_X = "clickCoordinateX"; // Count: 3
|
|
|
48
51
|
export const _DYN_CLICK_COORDINATE_Y = "clickCoordinateY"; // Count: 3
|
|
49
52
|
export const _DYN__CONFIG = "_config"; // Count: 9
|
|
50
53
|
export const _DYN_DATA_TAGS = "dataTags"; // Count: 6
|
|
51
|
-
export const _DYN_PARENT_DATA_TAG = "parentDataTag"; // Count: 3
|
|
52
54
|
export const _DYN__PAGE_TAGS = "_pageTags"; // Count: 6
|
|
53
55
|
export const _DYN__PAGE_TAGS_CALLBACK = "_pageTagsCallback"; // Count: 3
|
|
54
56
|
export const _DYN__META_TAGS = "_metaTags"; // Count: 6
|
|
@@ -2,24 +2,27 @@ export declare const _DYN_INDEX_OF = "indexOf";
|
|
|
2
2
|
export declare const _DYN_TRACK_PAGE_ACTION = "trackPageAction";
|
|
3
3
|
export declare const _DYN_PAGE_ACTION_PAGE_TAG0 = "pageActionPageTags";
|
|
4
4
|
export declare const _DYN__DO_UNLOAD = "_doUnload";
|
|
5
|
-
export declare const _DYN_USE_DEFAULT_CONTENT_1 = "useDefaultContentNameOrId";
|
|
6
|
-
export declare const _DYN_CAPTURE_ALL_META_DAT2 = "captureAllMetaDataContent";
|
|
7
5
|
export declare const _DYN_PAGE_NAME = "pageName";
|
|
8
6
|
export declare const _DYN_CONTENT_NAME = "contentName";
|
|
7
|
+
export declare const _DYN_REQUEST_URI = "requestUri";
|
|
8
|
+
export declare const _DYN_PAGE_TYPE = "pageType";
|
|
9
|
+
export declare const _DYN_USE_DEFAULT_CONTENT_1 = "useDefaultContentNameOrId";
|
|
10
|
+
export declare const _DYN_CAPTURE_ALL_META_DAT2 = "captureAllMetaDataContent";
|
|
11
|
+
export declare const _DYN_META_DATA_PREFIX = "metaDataPrefix";
|
|
12
|
+
export declare const _DYN_PARENT_DATA_TAG = "parentDataTag";
|
|
9
13
|
export declare const _DYN_BEHAVIOR_VALIDATOR = "behaviorValidator";
|
|
14
|
+
export declare const _DYN_DEFAULT_RIGHT_CLICK_3 = "defaultRightClickBhvr";
|
|
10
15
|
export declare const _DYN_LENGTH = "length";
|
|
11
16
|
export declare const _DYN_TAG_NAME = "tagName";
|
|
12
17
|
export declare const _DYN_TO_UPPER_CASE = "toUpperCase";
|
|
13
18
|
export declare const _DYN_PATHNAME = "pathname";
|
|
14
19
|
export declare const _DYN_ADD_EVENT_LISTENER = "addEventListener";
|
|
15
20
|
export declare const _DYN_CORE_DATA = "coreData";
|
|
16
|
-
export declare const _DYN_REQUEST_URI = "requestUri";
|
|
17
21
|
export declare const _DYN_GET_ATTRIBUTE = "getAttribute";
|
|
18
22
|
export declare const _DYN_PARENT_NODE = "parentNode";
|
|
19
23
|
export declare const _DYN_CUSTOM_DATA_PREFIX = "customDataPrefix";
|
|
20
24
|
export declare const _DYN_NAME = "name";
|
|
21
25
|
export declare const _DYN_DATA = "data";
|
|
22
|
-
export declare const _DYN_PAGE_TYPE = "pageType";
|
|
23
26
|
export declare const _DYN_PROPERTIES = "properties";
|
|
24
27
|
export declare const _DYN_ACTION_TYPE = "actionType";
|
|
25
28
|
export declare const _DYN_BEHAVIOR = "behavior";
|
|
@@ -28,7 +31,7 @@ export declare const _DYN_CONTENT = "content";
|
|
|
28
31
|
export declare const _DYN_REF_URI = "refUri";
|
|
29
32
|
export declare const _DYN_PARENT_ID = "parentId";
|
|
30
33
|
export declare const _DYN_CAPTURE_PAGE_ACTION = "capturePageAction";
|
|
31
|
-
export declare const
|
|
34
|
+
export declare const _DYN_SET_COMMON_PROPERTIE4 = "setCommonProperties";
|
|
32
35
|
export declare const _DYN_GET_ELEMENT_CONTENT = "getElementContent";
|
|
33
36
|
export declare const _DYN__GET_VALID_BEHAVIOR = "_getValidBehavior";
|
|
34
37
|
export declare const _DYN__TRACE_LOGGER = "_traceLogger";
|
|
@@ -36,7 +39,6 @@ export declare const _DYN_CLICK_COORDINATE_X = "clickCoordinateX";
|
|
|
36
39
|
export declare const _DYN_CLICK_COORDINATE_Y = "clickCoordinateY";
|
|
37
40
|
export declare const _DYN__CONFIG = "_config";
|
|
38
41
|
export declare const _DYN_DATA_TAGS = "dataTags";
|
|
39
|
-
export declare const _DYN_PARENT_DATA_TAG = "parentDataTag";
|
|
40
42
|
export declare const _DYN__PAGE_TAGS = "_pageTags";
|
|
41
43
|
export declare const _DYN__PAGE_TAGS_CALLBACK = "_pageTagsCallback";
|
|
42
44
|
export declare const _DYN__META_TAGS = "_metaTags";
|