@microsoft/applicationinsights-clickanalytics-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-04

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.8.0-nightly.2204-04.cjs.js +2883 -0
  2. package/browser/ai.clck.2.8.0-nightly.2204-04.cjs.js.map +1 -0
  3. package/browser/ai.clck.2.8.0-nightly.2204-04.cjs.min.js +6 -0
  4. package/browser/ai.clck.2.8.0-nightly.2204-04.cjs.min.js.map +1 -0
  5. package/browser/ai.clck.2.8.0-nightly.2204-04.gbl.js +2887 -0
  6. package/browser/ai.clck.2.8.0-nightly.2204-04.gbl.js.map +1 -0
  7. package/browser/ai.clck.2.8.0-nightly.2204-04.gbl.min.js +6 -0
  8. package/browser/ai.clck.2.8.0-nightly.2204-04.gbl.min.js.map +1 -0
  9. package/browser/ai.clck.2.8.0-nightly.2204-04.integrity.json +66 -0
  10. package/browser/ai.clck.2.8.0-nightly.2204-04.js +2889 -0
  11. package/browser/ai.clck.2.8.0-nightly.2204-04.js.map +1 -0
  12. package/browser/ai.clck.2.8.0-nightly.2204-04.min.js +6 -0
  13. package/browser/ai.clck.2.8.0-nightly.2204-04.min.js.map +1 -0
  14. package/browser/ai.clck.2.cjs.js +1685 -808
  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 +1685 -808
  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 +1685 -808
  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 +38 -13
  27. package/dist/applicationinsights-clickanalytics-js.api.md +1 -0
  28. package/dist/applicationinsights-clickanalytics-js.d.ts +2 -5
  29. package/dist/applicationinsights-clickanalytics-js.js +1685 -808
  30. package/dist/applicationinsights-clickanalytics-js.js.map +1 -1
  31. package/dist/applicationinsights-clickanalytics-js.min.js +2 -2
  32. package/dist/applicationinsights-clickanalytics-js.min.js.map +1 -1
  33. package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +2 -5
  34. package/dist-esm/Behaviours.js +1 -1
  35. package/dist-esm/ClickAnalyticsPlugin.js +74 -50
  36. package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
  37. package/dist-esm/DataCollector.js +4 -2
  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 +128 -126
  44. package/dist-esm/events/PageAction.js.map +1 -1
  45. package/dist-esm/events/WebEvent.js +109 -94
  46. package/dist-esm/events/WebEvent.js.map +1 -1
  47. package/dist-esm/handlers/AutoCaptureHandler.js +85 -83
  48. package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
  49. package/dist-esm/handlers/DomContentHandler.js +279 -276
  50. package/dist-esm/handlers/DomContentHandler.js.map +1 -1
  51. package/package.json +5 -5
  52. package/src/ClickAnalyticsPlugin.ts +92 -47
  53. package/src/DataCollector.ts +24 -22
  54. package/src/Interfaces/Datamodel.ts +20 -21
  55. package/src/common/Utils.ts +8 -8
  56. package/src/events/PageAction.ts +165 -131
  57. package/src/events/WebEvent.ts +147 -78
  58. package/src/handlers/AutoCaptureHandler.ts +89 -79
  59. package/src/handlers/DomContentHandler.ts +336 -303
  60. package/types/ClickAnalyticsPlugin.d.ts +1 -4
  61. package/types/Interfaces/Datamodel.d.ts +3 -2
  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 +2 -10
  65. package/types/handlers/DomContentHandler.d.ts +3 -50
  66. package/types/tsdoc-metadata.json +1 -1
  67. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js +0 -2006
  68. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js.map +0 -1
  69. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js +0 -6
  70. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js.map +0 -1
  71. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js +0 -2010
  72. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js.map +0 -1
  73. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js +0 -6
  74. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js.map +0 -1
  75. package/browser/ai.clck.2.8.0-nightly.2202-06.integrity.json +0 -66
  76. package/browser/ai.clck.2.8.0-nightly.2202-06.js +0 -2012
  77. package/browser/ai.clck.2.8.0-nightly.2202-06.js.map +0 -1
  78. package/browser/ai.clck.2.8.0-nightly.2202-06.min.js +0 -6
  79. package/browser/ai.clck.2.8.0-nightly.2202-06.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 { 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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-clickanalytics-js",
3
- "version": "2.8.0-nightly.2202-06",
3
+ "version": "2.8.0-nightly.2204-04",
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",
@@ -30,7 +30,7 @@
30
30
  "@rollup/plugin-commonjs": "^18.0.0",
31
31
  "@rollup/plugin-node-resolve": "^11.2.1",
32
32
  "@rollup/plugin-replace": "^2.3.3",
33
- "rollup-plugin-cleanup": "3.2.1",
33
+ "rollup-plugin-cleanup": "^3.2.1",
34
34
  "rollup": "^2.32.0",
35
35
  "grunt": "^1.4.1",
36
36
  "grunt-cli": "^1.4.3",
@@ -44,9 +44,9 @@
44
44
  "dependencies": {
45
45
  "@microsoft/dynamicproto-js": "^1.1.4",
46
46
  "@microsoft/applicationinsights-shims": "2.0.1",
47
- "@microsoft/applicationinsights-core-js": "2.8.0-nightly.2202-06",
48
- "@microsoft/applicationinsights-common": "2.8.0-nightly.2202-06",
49
- "@microsoft/applicationinsights-properties-js": "2.8.0-nightly.2202-06"
47
+ "@microsoft/applicationinsights-core-js": "2.8.0-nightly.2204-04",
48
+ "@microsoft/applicationinsights-common": "2.8.0-nightly.2204-04",
49
+ "@microsoft/applicationinsights-properties-js": "2.8.0-nightly.2204-04"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",
@@ -2,12 +2,13 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
+ import dynamicProto from "@microsoft/dynamicproto-js";
5
6
  import {
6
7
  IPlugin, IConfiguration, IAppInsightsCore,
7
8
  BaseTelemetryPlugin, isNullOrUndefined, ITelemetryItem,
8
9
  IProcessTelemetryContext, ITelemetryPluginChain,
9
10
  _InternalMessageId, ICustomProperties,
10
- LoggingSeverity, arrForEach, dumpObj, getExceptionName
11
+ LoggingSeverity, arrForEach, dumpObj, getExceptionName, throwError, _throwInternal, IProcessTelemetryUnloadContext, ITelemetryUnloadState, unloadComponents
11
12
  } from "@microsoft/applicationinsights-core-js";
12
13
  import { IConfig, IPropertiesPlugin, PropertiesPluginIdentifier } from "@microsoft/applicationinsights-common";
13
14
  import {
@@ -17,7 +18,7 @@ import {
17
18
  import {
18
19
  mergeConfig, BehaviorMapValidator,
19
20
  BehaviorValueValidator, BehaviorEnumValidator, _ExtendedInternalMessageId
20
- } from "./common/Utils";
21
+ } from "./common/Utils";
21
22
  import { PageAction } from "./events/PageAction";
22
23
  import { AutoCaptureHandler } from "./handlers/AutoCaptureHandler";
23
24
  import { DomContentHandler } from "./handlers/DomContentHandler";
@@ -27,46 +28,100 @@ export { BehaviorMapValidator, BehaviorValueValidator, BehaviorEnumValidator }
27
28
  export class ClickAnalyticsPlugin extends BaseTelemetryPlugin {
28
29
  public identifier: string = "ClickAnalyticsPlugin";
29
30
  public priority: number = 181;
30
- public static Version = "2.8.0-nightly.2202-06";
31
- private _config: IClickAnalyticsConfiguration;
32
- private pageAction: PageAction;
33
- private _autoCaptureHandler: IAutoCaptureHandler;
34
- private _contentHandler: IContentHandler;
31
+ public static Version = "2.8.0-nightly.2204-04";
35
32
 
36
- initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) {
37
-
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;
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
+ }
59
80
  }
81
+
82
+ _self.processTelemetry = (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void => {
83
+ _self.processNext(env, itemCtx);
84
+ };
85
+
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
+ };
60
109
  });
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;
110
+
111
+ function _initDefaults() {
112
+ _config = null;
113
+ _pageAction = null;
114
+ _autoCaptureHandler = null;
115
+ _contentHandler = null;
65
116
  }
66
117
  }
67
118
 
68
- processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
69
- this.processNext(env, itemCtx);
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
70
125
  }
71
126
 
72
127
  /**
@@ -75,16 +130,6 @@ export class ClickAnalyticsPlugin extends BaseTelemetryPlugin {
75
130
  * @param customProperties Additional data used to filter events and metrics. Defaults to empty.
76
131
  */
77
132
  public trackPageAction(pageAction?: IPageActionTelemetry, customProperties?: ICustomProperties) {
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
- }
133
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
89
134
  }
90
135
  }
@@ -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 || "";
59
- }
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 || "";
60
59
  }
61
- break;
62
- default:
63
- break;
60
+ }
61
+ break;
62
+ default:
63
+ break;
64
64
  }
65
65
  return clickTarget;
66
66
  }
@@ -95,7 +95,9 @@ 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(() => { onDomReadyDo(f); }, 100) : f.call();
98
+ /in/.test(doc.readyState) ? setTimeout(() => {
99
+ onDomReadyDo(f);
100
+ }, 100) : f.call();
99
101
  }
100
102
 
101
103
  /**
@@ -115,8 +117,8 @@ export function getPageName(config: IClickAnalyticsConfiguration, overrideValues
115
117
  } else if (config.coreData && config.coreData.pageName) {
116
118
  return config.coreData.pageName;
117
119
  } else {
118
- const doc = getDocument();
119
- return doc && doc.title || "";
120
+ const doc = getDocument();
121
+ return doc && doc.title || "";
120
122
  }
121
123
  }
122
124
 
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { IEventTelemetry } from "@microsoft/applicationinsights-common";
6
-
6
+ import { IUnloadableComponent } from "@microsoft/applicationinsights-core-js";
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 {
142
+ export interface IAutoCaptureHandler extends IUnloadableComponent {
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 IAutoCaptureHandler {
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 {
226
+ /**
227
+ * Content handler interface
228
+ */
229
+ export interface IContentHandler extends IUnloadableComponent {
230
230
  /**
231
231
  * Get meta data
232
232
  */
@@ -235,8 +235,7 @@ export interface IContentHandler {
235
235
  * Get element content
236
236
  */
237
237
  getElementContent: (element: Element) => IContent;
238
-
239
- }
238
+ }
240
239
 
241
240
  /**
242
241
  * 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);
348
- }
345
+ for (const attribute in defaultConfig) {
346
+ if (typeof defaultConfig[attribute] === "object") {
347
+ attributesThatAreObjectsInConfig.push(attribute);
349
348
  }
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
  }