@microsoft/applicationinsights-clickanalytics-js 2.7.5-nightly.2204-03 → 2.7.6

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 (79) hide show
  1. package/browser/ai.clck.2.7.6.cjs.js +2013 -0
  2. package/browser/ai.clck.2.7.6.cjs.js.map +1 -0
  3. package/browser/ai.clck.2.7.6.cjs.min.js +6 -0
  4. package/browser/ai.clck.2.7.6.cjs.min.js.map +1 -0
  5. package/browser/ai.clck.2.7.6.gbl.js +2017 -0
  6. package/browser/ai.clck.2.7.6.gbl.js.map +1 -0
  7. package/browser/ai.clck.2.7.6.gbl.min.js +6 -0
  8. package/browser/ai.clck.2.7.6.gbl.min.js.map +1 -0
  9. package/browser/ai.clck.2.7.6.integrity.json +66 -0
  10. package/browser/ai.clck.2.7.6.js +2019 -0
  11. package/browser/ai.clck.2.7.6.js.map +1 -0
  12. package/browser/ai.clck.2.7.6.min.js +6 -0
  13. package/browser/ai.clck.2.7.6.min.js.map +1 -0
  14. package/browser/ai.clck.2.cjs.js +818 -1688
  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 +818 -1688
  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 +818 -1688
  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 +27 -29
  27. package/dist/applicationinsights-clickanalytics-js.api.md +0 -1
  28. package/dist/applicationinsights-clickanalytics-js.d.ts +5 -2
  29. package/dist/applicationinsights-clickanalytics-js.js +818 -1688
  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 +5 -2
  34. package/dist-esm/Behaviours.js +1 -1
  35. package/dist-esm/ClickAnalyticsPlugin.js +50 -74
  36. package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
  37. package/dist-esm/DataCollector.js +2 -4
  38. package/dist-esm/DataCollector.js.map +1 -1
  39. package/dist-esm/Enums.js +1 -1
  40. package/dist-esm/Interfaces/Datamodel.js +1 -1
  41. package/dist-esm/applicationinsights-clickanalytics-js.js +1 -1
  42. package/dist-esm/common/Utils.js +1 -1
  43. package/dist-esm/events/PageAction.js +126 -128
  44. package/dist-esm/events/PageAction.js.map +1 -1
  45. package/dist-esm/events/WebEvent.js +94 -109
  46. package/dist-esm/events/WebEvent.js.map +1 -1
  47. package/dist-esm/handlers/AutoCaptureHandler.js +83 -85
  48. package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
  49. package/dist-esm/handlers/DomContentHandler.js +276 -279
  50. package/dist-esm/handlers/DomContentHandler.js.map +1 -1
  51. package/package.json +56 -59
  52. package/src/ClickAnalyticsPlugin.ts +47 -92
  53. package/src/DataCollector.ts +22 -24
  54. package/src/Interfaces/Datamodel.ts +21 -20
  55. package/src/common/Utils.ts +8 -8
  56. package/src/events/PageAction.ts +131 -165
  57. package/src/events/WebEvent.ts +78 -147
  58. package/src/handlers/AutoCaptureHandler.ts +79 -89
  59. package/src/handlers/DomContentHandler.ts +303 -336
  60. package/types/ClickAnalyticsPlugin.d.ts +4 -1
  61. package/types/Interfaces/Datamodel.d.ts +2 -3
  62. package/types/events/PageAction.d.ts +6 -6
  63. package/types/events/WebEvent.d.ts +17 -17
  64. package/types/handlers/AutoCaptureHandler.d.ts +10 -2
  65. package/types/handlers/DomContentHandler.d.ts +50 -3
  66. package/types/tsdoc-metadata.json +1 -1
  67. package/browser/ai.clck.2.7.5-nightly.2204-03.cjs.js +0 -2883
  68. package/browser/ai.clck.2.7.5-nightly.2204-03.cjs.js.map +0 -1
  69. package/browser/ai.clck.2.7.5-nightly.2204-03.cjs.min.js +0 -6
  70. package/browser/ai.clck.2.7.5-nightly.2204-03.cjs.min.js.map +0 -1
  71. package/browser/ai.clck.2.7.5-nightly.2204-03.gbl.js +0 -2887
  72. package/browser/ai.clck.2.7.5-nightly.2204-03.gbl.js.map +0 -1
  73. package/browser/ai.clck.2.7.5-nightly.2204-03.gbl.min.js +0 -6
  74. package/browser/ai.clck.2.7.5-nightly.2204-03.gbl.min.js.map +0 -1
  75. package/browser/ai.clck.2.7.5-nightly.2204-03.integrity.json +0 -66
  76. package/browser/ai.clck.2.7.5-nightly.2204-03.js +0 -2889
  77. package/browser/ai.clck.2.7.5-nightly.2204-03.js.map +0 -1
  78. package/browser/ai.clck.2.7.5-nightly.2204-03.min.js +0 -6
  79. package/browser/ai.clck.2.7.5-nightly.2204-03.min.js.map +0 -1
@@ -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 { removeInvalidElements, walkUpDomChainWithElementValidation, extend, _ExtendedInternalMessageId, isValueAssigned } from \"../common/Utils\";\r\nimport { LoggingSeverity, getDocument, isNullOrUndefined, hasDocument } from \"@microsoft/applicationinsights-core-js\";\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._config || {}).dataTags;\r\n var metaTags = {};\r\n if (hasDocument) {\r\n metaTags = isValueAssigned(dataTags.metaDataPrefix) ? _getMetaDataFromDOM(dataTags.captureAllMetaDataContent, dataTags.metaDataPrefix, false) :\r\n _getMetaDataFromDOM(dataTags.captureAllMetaDataContent, \"\", false);\r\n }\r\n return metaTags;\r\n };\r\n _self.getElementContent = function (element) {\r\n if (!element) {\r\n return {};\r\n }\r\n var dataTags = (_self._config || {}).dataTags;\r\n var elementContent = {};\r\n var biBlobValue;\r\n var parentDataTagPrefix;\r\n var dataTagPrefix = dataTags.customDataPrefix;\r\n var aiBlobAttributeTag = dataTagPrefix + dataTags.aiBlobAttributeTag;\r\n if (isValueAssigned(dataTags.parentDataTag)) {\r\n parentDataTagPrefix = dataTagPrefix + dataTags.parentDataTag;\r\n }\r\n if (!_isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {\r\n // capture blob from element or hierarchy\r\n biBlobValue = element.getAttribute(aiBlobAttributeTag);\r\n if (biBlobValue) {\r\n try {\r\n elementContent = JSON.parse(biBlobValue);\r\n }\r\n catch (e) {\r\n _self._traceLogger.throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.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 = extend(elementContent, _populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n }\r\n else {\r\n elementContent = extend(elementContent, _populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n removeInvalidElements(elementContent);\r\n if (parentDataTagPrefix) {\r\n elementContent = extend(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.length; i++) {\r\n attrib = contentElement.attributes[i];\r\n if (attrib.name.indexOf(dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n var attribName = attrib.name.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.attributes)) {\r\n var attributes = element.attributes;\r\n for (var i = 0; i < attributes.length; i++) {\r\n var attrib = attributes[i];\r\n if (attrib.name.indexOf(dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n if (attrib.name.indexOf(parentDataTagPrefix) === 0) {\r\n parentDataTagFound = true;\r\n }\r\n // Todo handle blob data\r\n if (attrib.name.indexOf(aiBlobAttributeTag) === 0) {\r\n continue;\r\n }\r\n var attribName = attrib.name.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.parentNode;\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.contentName || \"\"\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.contentName) {\r\n _traceLogger.throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.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._config || {}).dataTags;\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.useDefaultContentNameOrId) {\r\n if (!isValueAssigned(elementContent.id)) {\r\n elementContent.id = htmlContent.id || \"\";\r\n }\r\n elementContent.contentName = htmlContent.contentName || \"\";\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.contentName) {\r\n _traceLogger.throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.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.length; i++) {\r\n var meta = metaElements[i];\r\n if (meta.name) {\r\n if (captureAllMetaDataContent || meta.name.indexOf(prefix) === 0) {\r\n var name_1 = removePrefix ? meta.name.replace(prefix, \"\") : meta.name;\r\n metaData[name_1] = meta.content;\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.tagName) {\r\n return \"\";\r\n }\r\n var doc = getDocument() || {};\r\n var contentName;\r\n switch (element.tagName) {\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.name || 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.attributes;\r\n var dataTagFound = false;\r\n for (var i = 0; i < attrs.length; i++) {\r\n var attributeName = attrs[i].name;\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.indexOf(dataTag) === 0) {\r\n dataTagFound = true;\r\n }\r\n }\r\n return dataTagFound;\r\n }\r\n function _getHtmlIdAndContentName(element) {\r\n var dataTags = (_self._config || {}).dataTags;\r\n var callback = (_self._config || {}).callback;\r\n var htmlContent = {};\r\n if (!element) {\r\n return htmlContent;\r\n }\r\n if (dataTags.useDefaultContentNameOrId) {\r\n var customizedContentName = callback.contentName ? callback.contentName(element, dataTags.useDefaultContentNameOrId) : \"\";\r\n var defaultContentName = _getDefaultContentName(element, dataTags.useDefaultContentNameOrId);\r\n htmlContent = {\r\n id: element.id,\r\n contentName: customizedContentName || defaultContentName || element.getAttribute(\"alt\")\r\n };\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.parentElement, _isTracked, dataTagPrefix);\r\n if (closestParentElement) {\r\n var dataAttr = closestParentElement.getAttribute(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 _traceLogger.throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.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.getAttribute(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.parentElement);\r\n parentInfo[\"parentid\"] = htmlContent.id;\r\n parentInfo[\"parentname\"] = htmlContent.contentName;\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;kEAkBM;AACN;AACA;AACA;AACA"}
1
+ {"version":3,"file":"DomContentHandler.js.map","sources":["DomContentHandler.js"],"sourcesContent":["/**\r\n * @copyright Microsoft 2020\r\n */\r\nimport { removeInvalidElements, walkUpDomChainWithElementValidation, extend, _ExtendedInternalMessageId, isValueAssigned } from \"../common/Utils\";\r\nimport { LoggingSeverity, getDocument, isNullOrUndefined, hasDocument } from \"@microsoft/applicationinsights-core-js\";\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 }\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 var metaTags = {};\r\n if (hasDocument) {\r\n metaTags = isValueAssigned(this._config.dataTags.metaDataPrefix) ? this._getMetaDataFromDOM(this._config.dataTags.captureAllMetaDataContent, this._config.dataTags.metaDataPrefix, false) :\r\n this._getMetaDataFromDOM(this._config.dataTags.captureAllMetaDataContent, \"\", false);\r\n }\r\n return metaTags;\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 if (!element) {\r\n return {};\r\n }\r\n var elementContent = {};\r\n var biBlobValue;\r\n var parentDataTagPrefix;\r\n var dataTagPrefix = this._config.dataTags.customDataPrefix;\r\n var aiBlobAttributeTag = dataTagPrefix + this._config.dataTags.aiBlobAttributeTag;\r\n if (isValueAssigned(this._config.dataTags.parentDataTag)) {\r\n parentDataTagPrefix = dataTagPrefix + this._config.dataTags.parentDataTag;\r\n }\r\n if (!this._isTracked(element, dataTagPrefix, aiBlobAttributeTag)) {\r\n // capture blob from element or hierarchy\r\n biBlobValue = element.getAttribute(aiBlobAttributeTag);\r\n if (biBlobValue) {\r\n try {\r\n elementContent = JSON.parse(biBlobValue);\r\n }\r\n catch (e) {\r\n this._traceLogger.throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.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, this._isTracked, dataTagPrefix);\r\n elementContent = extend(elementContent, this._populateElementContent(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n }\r\n else {\r\n elementContent = extend(elementContent, this._populateElementContentwithDataTag(element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag));\r\n }\r\n removeInvalidElements(elementContent);\r\n if (parentDataTagPrefix) {\r\n elementContent = extend(elementContent, this._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 DomContentHandler.prototype._captureElementContentWithDataTag = function (contentElement, elementContent, dataTagPrefix) {\r\n for (var i = 0, attrib; i < contentElement.attributes.length; i++) {\r\n attrib = contentElement.attributes[i];\r\n if (attrib.name.indexOf(dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n var attribName = attrib.name.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 DomContentHandler.prototype._walkUpDomChainCaptureData = function (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.attributes)) {\r\n var attributes = element.attributes;\r\n for (var i = 0; i < attributes.length; i++) {\r\n var attrib = attributes[i];\r\n if (attrib.name.indexOf(dataTagPrefix) !== 0) {\r\n continue;\r\n }\r\n if (attrib.name.indexOf(parentDataTagPrefix) === 0) {\r\n parentDataTagFound = true;\r\n }\r\n // Todo handle blob data\r\n if (attrib.name.indexOf(aiBlobAttributeTag) === 0) {\r\n continue;\r\n }\r\n var attribName = attrib.name.replace(dataTagPrefix, \"\");\r\n if (elementLevelFlag && attribName === \"id\")\r\n continue; // skip capturing id if not at the first level.\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.parentNode;\r\n }\r\n };\r\n /**\r\n * Capture Element content along with Data Tag attributes and values\r\n */\r\n DomContentHandler.prototype._populateElementContent = function (element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var elementContent = {};\r\n if (!element)\r\n return elementContent;\r\n var htmlContent = this._getHtmlIdAndContentName(element);\r\n elementContent = {\r\n id: htmlContent.id || \"\",\r\n contentName: htmlContent.contentName || \"\"\r\n };\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n this._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.contentName) {\r\n this._traceLogger.throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.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 DomContentHandler.prototype._populateElementContentwithDataTag = function (element, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag) {\r\n var elementContent = {};\r\n if (!element)\r\n return elementContent;\r\n var htmlContent = this._getHtmlIdAndContentName(element);\r\n if (isValueAssigned(parentDataTagPrefix)) {\r\n this._walkUpDomChainCaptureData(element, elementContent, dataTagPrefix, parentDataTagPrefix, aiBlobAttributeTag);\r\n }\r\n else {\r\n this._captureElementContentWithDataTag(element, elementContent, dataTagPrefix);\r\n }\r\n if (this._config.dataTags.useDefaultContentNameOrId) {\r\n if (!isValueAssigned(elementContent.id)) {\r\n elementContent.id = htmlContent.id || \"\";\r\n }\r\n elementContent.contentName = htmlContent.contentName || \"\";\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.contentName) {\r\n this._traceLogger.throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.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 DomContentHandler.prototype._getMetaDataFromDOM = function (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.length; i++) {\r\n var meta = metaElements[i];\r\n if (meta.name) {\r\n if (captureAllMetaDataContent || meta.name.indexOf(prefix) === 0) {\r\n var name_1 = removePrefix ? meta.name.replace(prefix, \"\") : meta.name;\r\n metaData[name_1] = meta.content;\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 DomContentHandler.prototype._getDefaultContentName = function (element, useDefaultContentName) {\r\n if (useDefaultContentName === false || !element.tagName) {\r\n return \"\";\r\n }\r\n var doc = getDocument() || {};\r\n var contentName;\r\n switch (element.tagName) {\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.name || 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 DomContentHandler.prototype._isTracked = function (element, dataTag, aiBlobAttributeTag) {\r\n var attrs = element.attributes;\r\n var dataTagFound = false;\r\n for (var i = 0; i < attrs.length; i++) {\r\n var attributeName = attrs[i].name;\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.indexOf(dataTag) === 0) {\r\n dataTagFound = true;\r\n }\r\n }\r\n return dataTagFound;\r\n };\r\n DomContentHandler.prototype._getHtmlIdAndContentName = function (element) {\r\n var htmlContent = {};\r\n if (!element)\r\n return htmlContent;\r\n if (this._config.dataTags.useDefaultContentNameOrId) {\r\n var customizedContentName = this._config.callback.contentName ? this._config.callback.contentName(element, this._config.dataTags.useDefaultContentNameOrId) : \"\";\r\n var defaultContentName = this._getDefaultContentName(element, this._config.dataTags.useDefaultContentNameOrId);\r\n htmlContent = {\r\n id: element.id,\r\n contentName: customizedContentName || defaultContentName || element.getAttribute(\"alt\")\r\n };\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 DomContentHandler.prototype._getParentDetails = function (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 this._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 DomContentHandler.prototype._populateParentInfo = function (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.parentElement, this._isTracked, dataTagPrefix);\r\n if (closestParentElement) {\r\n var dataAttr = closestParentElement.getAttribute(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 this._traceLogger.throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.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.getAttribute(dataTagPrefix + \"id\");\r\n }\r\n }\r\n if (parentId) {\r\n parentInfo[\"parentid\"] = parentId;\r\n }\r\n else {\r\n var htmlContent = this._getHtmlIdAndContentName(element.parentElement);\r\n parentInfo[\"parentid\"] = htmlContent.id;\r\n parentInfo[\"parentname\"] = htmlContent.contentName;\r\n }\r\n return parentInfo;\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"}
package/package.json CHANGED
@@ -1,59 +1,56 @@
1
- {
2
- "name": "@microsoft/applicationinsights-clickanalytics-js",
3
- "version": "2.7.5-nightly.2204-03",
4
- "description": "Microsoft Application Insights Click Analytics extension",
5
- "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
- "author": "Microsoft Application Insights Team",
7
- "main": "dist/applicationinsights-clickanalytics-js.js",
8
- "module": "dist-esm/applicationinsights-clickanalytics-js.js",
9
- "types": "types/applicationinsights-clickanalytics-js.d.ts",
10
- "sideEffects": false,
11
- "scripts": {
12
- "build": "npm run build:esm && npm run build:browser && npm run sri && npm run dtsgen",
13
- "build:esm": "grunt clickanalytics",
14
- "build:browser": "rollup -c",
15
- "rebuild": "npm run build",
16
- "test": "grunt clickanalyticstests",
17
- "lint": "tslint -p tsconfig.json",
18
- "dtsgen": "api-extractor run --local && node ../../scripts/dtsgen.js 'Microsoft.ApplicationInsights'",
19
- "sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js"
20
- },
21
- "devDependencies": {
22
- "@microsoft/ai-test-framework": "0.0.1",
23
- "@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",
24
- "@microsoft/applicationinsights-rollup-es3": "1.1.3",
25
- "@microsoft/api-extractor": "^7.18.1",
26
- "typescript": "^4.3.4",
27
- "tslib": "^2.0.0",
28
- "globby": "^11.0.0",
29
- "magic-string": "^0.25.7",
30
- "@rollup/plugin-commonjs": "^18.0.0",
31
- "@rollup/plugin-node-resolve": "^11.2.1",
32
- "@rollup/plugin-replace": "^2.3.3",
33
- "rollup-plugin-cleanup": "^3.2.1",
34
- "rollup": "^2.32.0",
35
- "grunt": "^1.4.1",
36
- "grunt-cli": "^1.4.3",
37
- "grunt-contrib-qunit": "^5.0.1",
38
- "@nevware21/grunt-ts-plugin": "^0.4.3",
39
- "@nevware21/grunt-eslint-ts": "^0.2.2"
40
- },
41
- "peerDependencies": {
42
- "tslib": "*"
43
- },
44
- "dependencies": {
45
- "@microsoft/dynamicproto-js": "^1.1.4",
46
- "@microsoft/applicationinsights-shims": "2.0.1",
47
- "@microsoft/applicationinsights-core-js": "2.7.5-nightly.2204-03",
48
- "@microsoft/applicationinsights-common": "2.7.5-nightly.2204-03",
49
- "@microsoft/applicationinsights-properties-js": "2.7.5-nightly.2204-03"
50
- },
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/extensions/applicationinsights-clickanalytics-js"
54
- },
55
- "license": "MIT",
56
- "publishConfig": {
57
- "tag": "nightly"
58
- }
59
- }
1
+ {
2
+ "name": "@microsoft/applicationinsights-clickanalytics-js",
3
+ "version": "2.7.6",
4
+ "description": "Microsoft Application Insights Click Analytics extension",
5
+ "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
+ "author": "Microsoft Application Insights Team",
7
+ "main": "dist/applicationinsights-clickanalytics-js.js",
8
+ "module": "dist-esm/applicationinsights-clickanalytics-js.js",
9
+ "types": "types/applicationinsights-clickanalytics-js.d.ts",
10
+ "sideEffects": false,
11
+ "scripts": {
12
+ "build": "npm run build:esm && npm run build:browser && npm run sri && npm run dtsgen",
13
+ "build:esm": "grunt clickanalytics",
14
+ "build:browser": "rollup -c",
15
+ "rebuild": "npm run build",
16
+ "test": "grunt clickanalyticstests",
17
+ "lint": "tslint -p tsconfig.json",
18
+ "dtsgen": "api-extractor run --local && node ../../scripts/dtsgen.js 'Microsoft.ApplicationInsights'",
19
+ "sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js"
20
+ },
21
+ "devDependencies": {
22
+ "@microsoft/ai-test-framework": "0.0.1",
23
+ "@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",
24
+ "@microsoft/applicationinsights-rollup-es3": "1.1.3",
25
+ "@microsoft/api-extractor": "^7.18.1",
26
+ "typescript": "^4.3.4",
27
+ "tslib": "^2.0.0",
28
+ "globby": "^11.0.0",
29
+ "magic-string": "^0.25.7",
30
+ "@rollup/plugin-commonjs": "^18.0.0",
31
+ "@rollup/plugin-node-resolve": "^11.2.1",
32
+ "@rollup/plugin-replace": "^2.3.3",
33
+ "rollup-plugin-cleanup": "3.2.1",
34
+ "rollup": "^2.32.0",
35
+ "grunt": "^1.4.1",
36
+ "grunt-cli": "^1.4.3",
37
+ "grunt-contrib-qunit": "^5.0.1",
38
+ "@nevware21/grunt-ts-plugin": "^0.4.3",
39
+ "@nevware21/grunt-eslint-ts": "^0.2.2"
40
+ },
41
+ "peerDependencies": {
42
+ "tslib": "*"
43
+ },
44
+ "dependencies": {
45
+ "@microsoft/dynamicproto-js": "^1.1.6",
46
+ "@microsoft/applicationinsights-shims": "2.0.1",
47
+ "@microsoft/applicationinsights-core-js": "2.7.6",
48
+ "@microsoft/applicationinsights-common": "2.7.6",
49
+ "@microsoft/applicationinsights-properties-js": "2.7.6"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/extensions/applicationinsights-clickanalytics-js"
54
+ },
55
+ "license": "MIT"
56
+ }
@@ -2,13 +2,12 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
- import dynamicProto from "@microsoft/dynamicproto-js";
6
5
  import {
7
6
  IPlugin, IConfiguration, IAppInsightsCore,
8
7
  BaseTelemetryPlugin, isNullOrUndefined, ITelemetryItem,
9
8
  IProcessTelemetryContext, ITelemetryPluginChain,
10
9
  _InternalMessageId, ICustomProperties,
11
- LoggingSeverity, arrForEach, dumpObj, getExceptionName, throwError, _throwInternal, IProcessTelemetryUnloadContext, ITelemetryUnloadState, unloadComponents
10
+ LoggingSeverity, arrForEach, dumpObj, getExceptionName
12
11
  } from "@microsoft/applicationinsights-core-js";
13
12
  import { IConfig, IPropertiesPlugin, PropertiesPluginIdentifier } from "@microsoft/applicationinsights-common";
14
13
  import {
@@ -18,7 +17,7 @@ import {
18
17
  import {
19
18
  mergeConfig, BehaviorMapValidator,
20
19
  BehaviorValueValidator, BehaviorEnumValidator, _ExtendedInternalMessageId
21
- } from "./common/Utils";
20
+ } from "./common/Utils";
22
21
  import { PageAction } from "./events/PageAction";
23
22
  import { AutoCaptureHandler } from "./handlers/AutoCaptureHandler";
24
23
  import { DomContentHandler } from "./handlers/DomContentHandler";
@@ -28,100 +27,46 @@ export { BehaviorMapValidator, BehaviorValueValidator, BehaviorEnumValidator }
28
27
  export class ClickAnalyticsPlugin extends BaseTelemetryPlugin {
29
28
  public identifier: string = "ClickAnalyticsPlugin";
30
29
  public priority: number = 181;
31
- public static Version = "2.7.5-nightly.2204-03";
30
+ public static Version = "2.7.6";
31
+ private _config: IClickAnalyticsConfiguration;
32
+ private pageAction: PageAction;
33
+ private _autoCaptureHandler: IAutoCaptureHandler;
34
+ private _contentHandler: IContentHandler;
32
35
 
33
- constructor() {
34
- super();
35
-
36
- let _config: IClickAnalyticsConfiguration;
37
- let _pageAction: PageAction;
38
- let _autoCaptureHandler: IAutoCaptureHandler;
39
- let _contentHandler: IContentHandler;
40
-
41
- dynamicProto(ClickAnalyticsPlugin, this, (_self, _base) => {
42
- let _identifier = _self.identifier;
43
- _initDefaults();
44
-
45
- _self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => {
46
-
47
- if (isNullOrUndefined(core)) {
48
- throwError("Error initializing");
49
- }
50
-
51
- config.extensionConfig = config.extensionConfig || [];
52
- config.extensionConfig[_identifier] = config.extensionConfig[_identifier] || {};
53
- _config = mergeConfig(config.extensionConfig[_identifier]);
54
- super.initialize(config, core, extensions, pluginChain);
55
- let logger = _self.diagLog();
56
-
57
- // Default to DOM content handler
58
- _contentHandler = _contentHandler ? _contentHandler : new DomContentHandler(_config, logger);
59
- let metaTags = _contentHandler.getMetadata();
60
- _pageAction = new PageAction(this, _config, _contentHandler, _config.callback.pageActionPageTags, metaTags, logger);
61
-
62
- // Default to DOM autoCapture handler
63
- _autoCaptureHandler = _autoCaptureHandler ? _autoCaptureHandler : new AutoCaptureHandler(_self, _config, _pageAction, logger);
64
- if (_config.autoCapture) {
65
- _autoCaptureHandler.click();
66
- }
67
-
68
- // Find the properties plugin.
69
- let _propertiesExtension:IPropertiesPlugin;
70
- arrForEach(extensions, extension => {
71
- if (extension.identifier === PropertiesPluginIdentifier) {
72
- _propertiesExtension = extension as PropertiesPlugin;
73
- }
74
- });
75
- // Append Click Analytics Plugin Version to SDK version.
76
- if (_propertiesExtension && _propertiesExtension.context &&
77
- _propertiesExtension.context.internal && _propertiesExtension.context.internal.sdkVersion) {
78
- _propertiesExtension.context.internal.sdkVersion += "_ClickPlugin"+ ClickAnalyticsPlugin.Version;
79
- }
80
- }
81
-
82
- _self.processTelemetry = (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void => {
83
- _self.processNext(env, itemCtx);
84
- };
36
+ initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) {
85
37
 
86
- _self.trackPageAction = (pageAction?: IPageActionTelemetry, customProperties?: ICustomProperties) => {
87
- try {
88
- _pageAction.trackPageAction(pageAction, customProperties);
89
- } catch (e) {
90
- _throwInternal(
91
- _self.diagLog(),
92
- LoggingSeverity.CRITICAL,
93
- _ExtendedInternalMessageId.TrackPageActionEventFailed,
94
- "trackPageAction failed, page action event will not be collected: " + getExceptionName(e),
95
- { exception: dumpObj(e) });
96
- }
97
- };
98
-
99
- _self._doTeardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean => {
100
- return unloadComponents([
101
- _autoCaptureHandler,
102
- _contentHandler,
103
- _pageAction
104
- ], unloadCtx, unloadState, () => {
105
- _initDefaults();
106
- asyncCallback && asyncCallback();
107
- })
108
- };
38
+ if (isNullOrUndefined(core)) {
39
+ throw Error("Error initializing");
40
+ }
41
+ config.extensionConfig = config.extensionConfig || [];
42
+ config.extensionConfig[this.identifier] = config.extensionConfig[this.identifier] || {};
43
+ this._config = mergeConfig(config.extensionConfig[this.identifier]);
44
+ super.initialize(config, core, extensions, pluginChain);
45
+ // Default to DOM content handler
46
+ this._contentHandler = this._contentHandler ? this._contentHandler : new DomContentHandler(this._config, this.diagLog());
47
+ let metaTags = this._contentHandler.getMetadata();
48
+ this.pageAction = new PageAction(this, this._config, this._contentHandler, this._config.callback.pageActionPageTags, metaTags, this.diagLog());
49
+ // Default to DOM autoCapture handler
50
+ this._autoCaptureHandler = this._autoCaptureHandler ? this._autoCaptureHandler : new AutoCaptureHandler(this, this._config, this.pageAction, this.diagLog());
51
+ if (this._config.autoCapture) {
52
+ this._autoCaptureHandler.click();
53
+ }
54
+ // Find the properties plugin.
55
+ let _propertiesExtension:IPropertiesPlugin;
56
+ arrForEach(extensions, extension => {
57
+ if (extension.identifier === PropertiesPluginIdentifier) {
58
+ _propertiesExtension = extension as PropertiesPlugin;
59
+ }
109
60
  });
110
-
111
- function _initDefaults() {
112
- _config = null;
113
- _pageAction = null;
114
- _autoCaptureHandler = null;
115
- _contentHandler = null;
61
+ // Append Click Analytics Plugin Version to SDK version.
62
+ if (_propertiesExtension && _propertiesExtension.context &&
63
+ _propertiesExtension.context.internal && _propertiesExtension.context.internal.sdkVersion) {
64
+ _propertiesExtension.context.internal.sdkVersion += "_ClickPlugin"+ ClickAnalyticsPlugin.Version;
116
65
  }
117
66
  }
118
67
 
119
- public initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) {
120
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
121
- }
122
-
123
- public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
124
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
68
+ processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
69
+ this.processNext(env, itemCtx);
125
70
  }
126
71
 
127
72
  /**
@@ -130,6 +75,16 @@ export class ClickAnalyticsPlugin extends BaseTelemetryPlugin {
130
75
  * @param customProperties Additional data used to filter events and metrics. Defaults to empty.
131
76
  */
132
77
  public trackPageAction(pageAction?: IPageActionTelemetry, customProperties?: ICustomProperties) {
133
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
78
+ try {
79
+
80
+ this.pageAction.trackPageAction(pageAction,customProperties);
81
+
82
+ } catch (e) {
83
+ this.diagLog().throwInternal(
84
+ LoggingSeverity.CRITICAL,
85
+ _ExtendedInternalMessageId.TrackPageActionEventFailed,
86
+ "trackPageAction failed, page action event will not be collected: " + getExceptionName(e),
87
+ { exception: dumpObj(e) });
88
+ }
134
89
  }
135
90
  }
@@ -41,26 +41,26 @@ export function getImageHref(element: HTMLImageElement): string {
41
41
  export function getClickTarget(element: any) {
42
42
  var clickTarget = "";
43
43
  switch (element.tagName) {
44
- case "A":
45
- case "AREA":
46
- clickTarget = element.href || "";
47
- break;
48
- case "IMG":
49
- clickTarget = getImageHref(element as HTMLImageElement);
50
- break;
51
- case "INPUT":
52
- var type = element.type;
53
- if (type && (clickCaptureInputTypes[type.toUpperCase()])) {
54
- let loc = getLocation() || ({} as Location);
55
- if (element.form) {
56
- clickTarget = element.form.action || (loc.pathname || "");
57
- } else {
58
- clickTarget = loc.pathname || "";
44
+ case "A":
45
+ case "AREA":
46
+ clickTarget = element.href || "";
47
+ break;
48
+ case "IMG":
49
+ clickTarget = getImageHref(element as HTMLImageElement);
50
+ break;
51
+ case "INPUT":
52
+ var type = element.type;
53
+ if (type && (clickCaptureInputTypes[type.toUpperCase()])) {
54
+ let loc = getLocation() || ({} as Location);
55
+ if (element.form) {
56
+ clickTarget = element.form.action || (loc.pathname || "");
57
+ } else {
58
+ clickTarget = loc.pathname || "";
59
+ }
59
60
  }
60
- }
61
- break;
62
- default:
63
- break;
61
+ break;
62
+ default:
63
+ break;
64
64
  }
65
65
  return clickTarget;
66
66
  }
@@ -95,9 +95,7 @@ function onDomReadyDo(f: any) {
95
95
  /// <param type='function'>function to call on domRead</param>
96
96
 
97
97
  let doc = getDocument() || ({} as Document);
98
- /in/.test(doc.readyState) ? setTimeout(() => {
99
- onDomReadyDo(f);
100
- }, 100) : f.call();
98
+ /in/.test(doc.readyState) ? setTimeout(() => { onDomReadyDo(f); }, 100) : f.call();
101
99
  }
102
100
 
103
101
  /**
@@ -117,8 +115,8 @@ export function getPageName(config: IClickAnalyticsConfiguration, overrideValues
117
115
  } else if (config.coreData && config.coreData.pageName) {
118
116
  return config.coreData.pageName;
119
117
  } else {
120
- const doc = getDocument();
121
- return doc && doc.title || "";
118
+ const doc = getDocument();
119
+ return doc && doc.title || "";
122
120
  }
123
121
  }
124
122
 
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { IEventTelemetry } from "@microsoft/applicationinsights-common";
6
- import { IUnloadableComponent } from "@microsoft/applicationinsights-core-js";
6
+
7
7
 
8
8
  /**
9
9
  * ClickAnalytics Configuration
@@ -126,27 +126,27 @@ export interface IValueCallback {
126
126
  * PageTags format
127
127
  */
128
128
  export interface IPageTags {
129
- /**
130
- * Meta data tags
131
- */
129
+ /**
130
+ * Meta data tags
131
+ */
132
132
  metaTags?: { [name: string]: string };
133
- /**
134
- * Any other page tag
135
- */
133
+ /**
134
+ * Any other page tag
135
+ */
136
136
  [name: string]: string | number | boolean | string[] | number[] | boolean[] | object | undefined;
137
137
  }
138
138
 
139
139
  /**
140
140
  * Auto capture handler interface
141
141
  */
142
- export interface IAutoCaptureHandler extends IUnloadableComponent {
142
+ export interface IAutoCaptureHandler {
143
143
  /**
144
144
  * Auto capture click
145
145
  */
146
146
  click: () => void;
147
- }
147
+ }
148
148
 
149
- export interface IPageActionOverrideValues extends IOverrideValues {
149
+ export interface IPageActionOverrideValues extends IOverrideValues {
150
150
  /**
151
151
  * Uri of the referrer page
152
152
  */
@@ -175,11 +175,11 @@ export interface IPageActionOverrideValues extends IOverrideValues {
175
175
  * KVPs to be added to the content tags collected on a Page Action event; extends the items in the Content blob in Page Action events
176
176
  */
177
177
  contentTags?: any;
178
- }
178
+ }
179
179
 
180
- /**
181
- * Override values interface
182
- */
180
+ /**
181
+ * Override values interface
182
+ */
183
183
  export interface IOverrideValues {
184
184
  /**
185
185
  * One of the awa.behavior values.
@@ -201,7 +201,7 @@ export interface IOverrideValues {
201
201
  * Indicates if the event was fired automatically
202
202
  */
203
203
  isAuto?: boolean;
204
- }
204
+ }
205
205
 
206
206
  /**
207
207
  * Content interface
@@ -223,10 +223,10 @@ export interface IContent {
223
223
  [name: string]: string | number | boolean | string[] | number[] | boolean[] | object | undefined;
224
224
  }
225
225
 
226
- /**
227
- * Content handler interface
228
- */
229
- export interface IContentHandler extends IUnloadableComponent {
226
+ /**
227
+ * Content handler interface
228
+ */
229
+ export interface IContentHandler {
230
230
  /**
231
231
  * Get meta data
232
232
  */
@@ -235,7 +235,8 @@ export interface IContentHandler extends IUnloadableComponent {
235
235
  * Get element content
236
236
  */
237
237
  getElementContent: (element: Element) => IContent;
238
- }
238
+
239
+ }
239
240
 
240
241
  /**
241
242
  * Page Action event
@@ -342,18 +342,18 @@ export function mergeConfig(overrideConfig: IClickAnalyticsConfiguration): IClic
342
342
  };
343
343
 
344
344
  let attributesThatAreObjectsInConfig: any[] = [];
345
- for (const attribute in defaultConfig) {
346
- if (typeof defaultConfig[attribute] === "object") {
347
- attributesThatAreObjectsInConfig.push(attribute);
345
+ for (const attribute in defaultConfig) {
346
+ if (typeof defaultConfig[attribute] === "object") {
347
+ attributesThatAreObjectsInConfig.push(attribute);
348
+ }
348
349
  }
349
- }
350
350
 
351
351
  if (overrideConfig) {
352
- // delete attributes that should be object and
353
- // delete properties that are null, undefined, ''
354
- removeNonObjectsAndInvalidElements(overrideConfig, attributesThatAreObjectsInConfig);
352
+ // delete attributes that should be object and
353
+ // delete properties that are null, undefined, ''
354
+ removeNonObjectsAndInvalidElements(overrideConfig, attributesThatAreObjectsInConfig);
355
355
  if(isValueAssigned(overrideConfig.dataTags)) {
356
- overrideConfig.dataTags.customDataPrefix = validateContentNamePrefix(overrideConfig, DEFAULT_DATA_PREFIX) ? overrideConfig.dataTags.customDataPrefix : DEFAULT_DATA_PREFIX;
356
+ overrideConfig.dataTags.customDataPrefix = validateContentNamePrefix(overrideConfig, DEFAULT_DATA_PREFIX) ? overrideConfig.dataTags.customDataPrefix : DEFAULT_DATA_PREFIX;
357
357
  }
358
358
  return extend(true, defaultConfig, overrideConfig);
359
359
  }