@microsoft/applicationinsights-clickanalytics-js 3.0.0-beta.2303-11 → 3.0.0-nightly3.2304-28

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 (107) hide show
  1. package/browser/{ai.clck.3.0.0-beta.2303-11.cjs.js → es5/ai.clck.3.0.0-nightly3.2304-28.cjs.js} +810 -786
  2. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.cjs.js.map +1 -0
  3. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.cjs.min.js +6 -0
  4. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.cjs.min.js.map +1 -0
  5. package/browser/{ai.clck.3.0.0-beta.2303-11.gbl.js → es5/ai.clck.3.0.0-nightly3.2304-28.gbl.js} +809 -785
  6. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.gbl.js.map +1 -0
  7. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.gbl.min.js +6 -0
  8. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.gbl.min.js.map +1 -0
  9. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.integrity.json +66 -0
  10. package/browser/{ai.clck.3.0.0-beta.2303-11.js → es5/ai.clck.3.0.0-nightly3.2304-28.js} +809 -785
  11. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.js.map +1 -0
  12. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.min.js +6 -0
  13. package/browser/es5/ai.clck.3.0.0-nightly3.2304-28.min.js.map +1 -0
  14. package/browser/{ai.clck.3.cjs.js → es5/ai.clck.3.cjs.js} +809 -785
  15. package/browser/es5/ai.clck.3.cjs.js.map +1 -0
  16. package/browser/es5/ai.clck.3.cjs.min.js +6 -0
  17. package/browser/es5/ai.clck.3.cjs.min.js.map +1 -0
  18. package/browser/{ai.clck.3.gbl.js → es5/ai.clck.3.gbl.js} +808 -784
  19. package/browser/es5/ai.clck.3.gbl.js.map +1 -0
  20. package/browser/es5/ai.clck.3.gbl.min.js +6 -0
  21. package/browser/es5/ai.clck.3.gbl.min.js.map +1 -0
  22. package/browser/{ai.clck.3.js → es5/ai.clck.3.js} +808 -784
  23. package/browser/es5/ai.clck.3.js.map +1 -0
  24. package/browser/es5/ai.clck.3.min.js +6 -0
  25. package/browser/es5/ai.clck.3.min.js.map +1 -0
  26. package/dist/{applicationinsights-clickanalytics-js.js → es5/applicationinsights-clickanalytics-js.js} +808 -784
  27. package/dist/es5/applicationinsights-clickanalytics-js.js.map +1 -0
  28. package/dist/es5/applicationinsights-clickanalytics-js.min.js +6 -0
  29. package/dist/es5/applicationinsights-clickanalytics-js.min.js.map +1 -0
  30. package/{dist-esm → dist-es5}/Behaviours.js +1 -1
  31. package/{dist-esm → dist-es5}/ClickAnalyticsPlugin.js +2 -2
  32. package/{dist-esm → dist-es5}/ClickAnalyticsPlugin.js.map +1 -1
  33. package/{dist-esm → dist-es5}/DataCollector.js +1 -1
  34. package/{dist-esm → dist-es5}/Enums.js +1 -1
  35. package/{dist-esm → dist-es5}/Interfaces/Datamodel.js +1 -1
  36. package/{dist-esm → dist-es5}/__DynamicConstants.js +1 -1
  37. package/{dist-esm → dist-es5}/applicationinsights-clickanalytics-js.js +1 -1
  38. package/{dist-esm → dist-es5}/common/Utils.js +1 -1
  39. package/{dist-esm → dist-es5}/events/PageAction.js +1 -1
  40. package/{dist-esm → dist-es5}/events/WebEvent.js +1 -1
  41. package/{dist-esm → dist-es5}/handlers/AutoCaptureHandler.js +1 -1
  42. package/{dist-esm → dist-es5}/handlers/DomContentHandler.js +3 -2
  43. package/dist-es5/handlers/DomContentHandler.js.map +1 -0
  44. package/package.json +19 -18
  45. package/tsconfig.json +4 -3
  46. package/types/applicationinsights-clickanalytics-js.d.ts +101 -2
  47. package/{dist/applicationinsights-clickanalytics-js.d.ts → types/applicationinsights-clickanalytics-js.namespaced.d.ts} +1 -1
  48. package/browser/ai.clck.3.0.0-beta.2303-11.cjs.js.map +0 -1
  49. package/browser/ai.clck.3.0.0-beta.2303-11.cjs.min.js +0 -6
  50. package/browser/ai.clck.3.0.0-beta.2303-11.cjs.min.js.map +0 -1
  51. package/browser/ai.clck.3.0.0-beta.2303-11.gbl.js.map +0 -1
  52. package/browser/ai.clck.3.0.0-beta.2303-11.gbl.min.js +0 -6
  53. package/browser/ai.clck.3.0.0-beta.2303-11.gbl.min.js.map +0 -1
  54. package/browser/ai.clck.3.0.0-beta.2303-11.integrity.json +0 -66
  55. package/browser/ai.clck.3.0.0-beta.2303-11.js.map +0 -1
  56. package/browser/ai.clck.3.0.0-beta.2303-11.min.js +0 -6
  57. package/browser/ai.clck.3.0.0-beta.2303-11.min.js.map +0 -1
  58. package/browser/ai.clck.3.cjs.js.map +0 -1
  59. package/browser/ai.clck.3.cjs.min.js +0 -6
  60. package/browser/ai.clck.3.cjs.min.js.map +0 -1
  61. package/browser/ai.clck.3.gbl.js.map +0 -1
  62. package/browser/ai.clck.3.gbl.min.js +0 -6
  63. package/browser/ai.clck.3.gbl.min.js.map +0 -1
  64. package/browser/ai.clck.3.js.map +0 -1
  65. package/browser/ai.clck.3.min.js +0 -6
  66. package/browser/ai.clck.3.min.js.map +0 -1
  67. package/dist/applicationinsights-clickanalytics-js.api.json +0 -695
  68. package/dist/applicationinsights-clickanalytics-js.api.md +0 -46
  69. package/dist/applicationinsights-clickanalytics-js.js.map +0 -1
  70. package/dist/applicationinsights-clickanalytics-js.min.js +0 -6
  71. package/dist/applicationinsights-clickanalytics-js.min.js.map +0 -1
  72. package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +0 -102
  73. package/dist-esm/handlers/DomContentHandler.js.map +0 -1
  74. package/src/Behaviours.ts +0 -165
  75. package/src/ClickAnalyticsPlugin.ts +0 -183
  76. package/src/DataCollector.ts +0 -159
  77. package/src/Enums.ts +0 -15
  78. package/src/Interfaces/Datamodel.ts +0 -300
  79. package/src/__DynamicConstants.ts +0 -61
  80. package/src/applicationinsights-clickanalytics-js.ts +0 -6
  81. package/src/common/Utils.ts +0 -281
  82. package/src/events/PageAction.ts +0 -197
  83. package/src/events/WebEvent.ts +0 -202
  84. package/src/handlers/AutoCaptureHandler.ts +0 -121
  85. package/src/handlers/DomContentHandler.ts +0 -395
  86. package/types/Behaviours.d.ts +0 -99
  87. package/types/ClickAnalyticsPlugin.d.ts +0 -22
  88. package/types/DataCollector.d.ts +0 -39
  89. package/types/Enums.d.ts +0 -14
  90. package/types/Interfaces/Datamodel.d.ts +0 -291
  91. package/types/__DynamicConstants.d.ts +0 -49
  92. package/types/common/Utils.d.ts +0 -123
  93. package/types/events/PageAction.d.ts +0 -28
  94. package/types/events/WebEvent.d.ts +0 -54
  95. package/types/handlers/AutoCaptureHandler.d.ts +0 -20
  96. package/types/handlers/DomContentHandler.d.ts +0 -29
  97. package/types/tsdoc-metadata.json +0 -11
  98. /package/{dist-esm → dist-es5}/Behaviours.js.map +0 -0
  99. /package/{dist-esm → dist-es5}/DataCollector.js.map +0 -0
  100. /package/{dist-esm → dist-es5}/Enums.js.map +0 -0
  101. /package/{dist-esm → dist-es5}/Interfaces/Datamodel.js.map +0 -0
  102. /package/{dist-esm → dist-es5}/__DynamicConstants.js.map +0 -0
  103. /package/{dist-esm → dist-es5}/applicationinsights-clickanalytics-js.js.map +0 -0
  104. /package/{dist-esm → dist-es5}/common/Utils.js.map +0 -0
  105. /package/{dist-esm → dist-es5}/events/PageAction.js.map +0 -0
  106. /package/{dist-esm → dist-es5}/events/WebEvent.js.map +0 -0
  107. /package/{dist-esm → dist-es5}/handlers/AutoCaptureHandler.js.map +0 -0
@@ -1,281 +0,0 @@
1
- /**
2
- * @copyright Microsoft 2020
3
- * File containing utility functions.
4
- */
5
-
6
- import { _eInternalMessageId, arrForEach, isNullOrUndefined } from "@microsoft/applicationinsights-core-js";
7
- import { IClickAnalyticsConfiguration } from "../Interfaces/Datamodel";
8
-
9
- export const DEFAULT_DONOT_TRACK_TAG = "ai-dnt";
10
- export const DEFAULT_AI_BLOB_ATTRIBUTE_TAG = "ai-blob";
11
- export const DEFAULT_DATA_PREFIX = "data-";
12
-
13
- export const enum _eExtendedInternalMessageId {
14
- CannotParseAiBlobValue = 101,
15
- InvalidContentBlob = 102,
16
- TrackPageActionEventFailed = 103
17
- }
18
-
19
- export type _ExtendedInternalMessageId = number | _eExtendedInternalMessageId | _eInternalMessageId;
20
-
21
-
22
- /**
23
- * Finds attributes in overrideConfig which are invalid or should be objects
24
- * and deletes them. useful in override config
25
- * @param overrideConfig - override config object
26
- * @param attributeNamesExpectedObjects - attributes that should be objects in override config object
27
- */
28
- export function removeNonObjectsAndInvalidElements(overrideConfig: IClickAnalyticsConfiguration, attributeNamesExpectedObjects: Array<string>): void {
29
- removeInvalidElements(overrideConfig);
30
- arrForEach(attributeNamesExpectedObjects, (i) => {
31
- var objectName = attributeNamesExpectedObjects[i];
32
- if (typeof overrideConfig[objectName] === "object") {
33
- removeInvalidElements(overrideConfig[objectName]);
34
- } else {
35
- delete overrideConfig[objectName];
36
- }
37
- });
38
- }
39
-
40
- /**
41
- * Finds attributes in object which are invalid
42
- * and deletes them. useful in override config
43
- * @param object - Input object
44
- */
45
- export function removeInvalidElements(object: Object): void {
46
- /// Because the config object 'callback' contains only functions,
47
- /// when it is stringified it returns the empty object. This explains
48
- /// the workaround regarding 'callback'
49
- for (var property in object) {
50
- if (!isValueAssigned(object[property]) ||
51
- (JSON.stringify(object[property]) === "{}" && (property !== "callback"))) {
52
- delete object[property];
53
- }
54
- }
55
- }
56
-
57
- /**
58
- * Checks if value is assigned to the given param.
59
- * @param value - The token from which the tenant id is to be extracted.
60
- * @returns True/false denoting if value is assigned to the param.
61
- */
62
- export function isValueAssigned(value: any) {
63
- /// <summary> takes a value and checks for undefined, null and empty string </summary>
64
- /// <param type="any"> value to be tested </param>
65
- /// <returns> true if value is null undefined or emptyString </returns>
66
- return !(isNullOrUndefined(value) || value === "");
67
- }
68
-
69
- /**
70
- * Determines whether an event is a right click or not
71
- * @param evt - Mouse event
72
- * @returns true if the event is a right click
73
- */
74
- export function isRightClick(evt: any): boolean {
75
- try {
76
- if ("which" in evt) { // Chrome, FF, ...
77
- return (evt.which === 3);
78
- } else if ("button" in evt) { // IE, ...
79
- return (evt.button === 2);
80
- }
81
- } catch (e) {
82
- // This can happen with some native browser objects, but should not happen for the type we are checking for
83
- }
84
- }
85
-
86
- /**
87
- * Determines whether an event is a left click or not
88
- * @param evt - Mouse event
89
- * @returns true if the event is a left click
90
- */
91
- export function isLeftClick(evt: any): boolean {
92
- try {
93
- if ("which" in evt) { // Chrome, FF, ...
94
- return (evt.which === 1);
95
- } else if ("button" in evt) { // IE, ...
96
- return (evt.button === 1);
97
- }
98
- } catch (e) {
99
- // This can happen with some native browser objects, but should not happen for the type we are checking for
100
- }
101
- }
102
-
103
- /**
104
- * Determines whether an event is a middle click or not
105
- * @param evt - Mouse event
106
- * @returns true if the event is a middle click
107
- */
108
- export function isMiddleClick(evt: any): boolean {
109
- try {
110
- if ("which" in evt) { // Chrome, FF, ...
111
- return (evt.which === 2);
112
- } else if ("button" in evt) { // IE, ...
113
- return (evt.button === 4);
114
- }
115
- } catch (e) {
116
- // This can happen with some native browser objects, but should not happen for the type we are checking for
117
- }
118
- }
119
-
120
- /**
121
- * Determines whether an event is a keyboard enter or not
122
- * @param evt - Keyboard event
123
- * @returns true if the event is a keyboard enter
124
- */
125
- export function isKeyboardEnter(evt: KeyboardEvent): boolean {
126
- try {
127
- if ("keyCode" in evt) { // Chrome, FF, ...
128
- return (evt.keyCode === 13);
129
- }
130
- } catch (e) {
131
- // This can happen with some native browser objects, but should not happen for the type we are checking for
132
- }
133
- }
134
-
135
- /**
136
- * Determines whether an event is a keyboard space or not
137
- * @param evt - Keyboard event
138
- * @returns true if the event is a space enter
139
- */
140
- export function isKeyboardSpace(evt: KeyboardEvent) {
141
- try {
142
- if ("keyCode" in evt) { // Chrome, FF, ...
143
- return (evt.keyCode === 32);
144
- }
145
- } catch (e) {
146
- // This can happen with some native browser objects, but should not happen for the type we are checking for
147
- }
148
- }
149
-
150
- /**
151
- * Determines whether the elemt have a DNT(Do Not Track) tag
152
- * @param element - DOM element
153
- * @param doNotTrackFieldName - DOM element
154
- * @returns true if the element must not be tarcked
155
- */
156
- export function isElementDnt(element: Element, doNotTrackFieldName: string): boolean {
157
- var dntElement = findClosestByAttribute(element, doNotTrackFieldName);
158
- if (!isValueAssigned(dntElement)) {
159
- return false;
160
- }
161
- return true;
162
- }
163
-
164
- /**
165
- * Walks up DOM tree to find element with attribute
166
- * @param el - DOM element
167
- * @param attribute - Attribute name
168
- * @returns Dom element which contains attribute
169
- */
170
- export function findClosestByAttribute(el: Element, attribute: string): Element {
171
- return walkUpDomChainWithElementValidation(el, isAttributeInElement, attribute);
172
- }
173
-
174
- /**
175
- * checks if attribute is in element.
176
- * method checks for empty string, in case the attribute is set but no value is assigned to it
177
- * @param element - DOM element
178
- * @param attributeToLookFor - Attribute name
179
- * @returns true if attribute is in element, even if empty string
180
- */
181
- export function isAttributeInElement(element: Element, attributeToLookFor: string): Boolean {
182
- var value = element.getAttribute(attributeToLookFor);
183
- return isValueAssigned(value);
184
- }
185
-
186
- /**
187
- * Walks up DOM tree to find element which matches validationMethod
188
- * @param el - DOM element
189
- * @param validationMethod - DOM element validation method
190
- * @param validationMethodParam - DOM element validation method parameters
191
- * @returns Dom element which is an anchor
192
- */
193
- export function walkUpDomChainWithElementValidation(el: Element, validationMethod: Function, validationMethodParam?: any): Element {
194
- var element = el;
195
- if (element) {
196
- while (!validationMethod(element, validationMethodParam)) {
197
- element = (element.parentNode as Element);
198
- if (!element || !(element.getAttribute)) {
199
- return null;
200
- }
201
- }
202
- return element;
203
- }
204
- }
205
-
206
-
207
- /**
208
- * Determine if DOM element is an anchor
209
- * @param element - DOM element
210
- * @returns Is element an anchor
211
- */
212
- export function isElementAnAnchor(element: Element): boolean {
213
- return element.nodeName === "A";
214
- }
215
-
216
- /**
217
- * Walks up DOM tree to find anchor element
218
- * @param element - DOM element
219
- * @returns Dom element which is an anchor
220
- */
221
- export function findClosestAnchor(element: Element): Element {
222
- /// <summary> Walks up DOM tree to find anchor element </summary>
223
- /// <param type='object'> DOM element </param>
224
- /// <returns> Dom element which is an anchor</returns>
225
-
226
- return walkUpDomChainWithElementValidation(element, isElementAnAnchor);
227
- }
228
-
229
- /**
230
- * Returns the specified field and also removes the property from the object if exists.
231
- * @param obj - Input object
232
- * @param fieldName - >Name of the field/property to be extracted
233
- * @returns Value of the specified tag
234
- */
235
- export function extractFieldFromObject(obj: Object, fieldName: string): string {
236
- var fieldValue: any;
237
- if (obj && obj[fieldName]) {
238
- fieldValue = obj[fieldName];
239
- delete obj[fieldName];
240
- }
241
-
242
- return fieldValue;
243
- }
244
-
245
- /**
246
- * Adds surrounding square brackets to the passed in text
247
- * @param str - Input string
248
- * @returns String with surrounding brackets
249
- */
250
- export function bracketIt(str: string): string {
251
- /// <summary>
252
- /// Adds surrounding square brackets to the passed in text
253
- /// </summary>
254
- return "[" + str + "]";
255
- }
256
-
257
- export function validateContentNamePrefix ( config: IClickAnalyticsConfiguration, defaultDataPrefix: string) {
258
- return isValueAssigned(config.dataTags.customDataPrefix) && (config.dataTags.customDataPrefix.indexOf(defaultDataPrefix) === 0);
259
- }
260
-
261
- export function BehaviorMapValidator (map: any) {
262
- return (key: string) => map[key] || "";
263
- }
264
-
265
- export function BehaviorValueValidator (behaviorArray: string[]) {
266
- return (key: string) => {
267
- let result;
268
- arrForEach(behaviorArray, (value) => {
269
- if (value === key) {
270
- result = value;
271
- return -1;
272
- }
273
- });
274
- return result || "";
275
- }
276
-
277
- }
278
-
279
- export function BehaviorEnumValidator (enumObj: any) {
280
- return (key: string) => enumObj[key] || "";
281
- }
@@ -1,197 +0,0 @@
1
- /**
2
- * @copyright Microsoft 2020
3
- */
4
-
5
- import dynamicProto from "@microsoft/dynamicproto-js";
6
- import { strNotSpecified } from "@microsoft/applicationinsights-common";
7
- import {
8
- ICustomProperties, IDiagnosticLogger, ITelemetryItem, _eInternalMessageId, _throwInternal, eLoggingSeverity, getPerformance, objExtend,
9
- objForEachKey
10
- } from "@microsoft/applicationinsights-core-js";
11
- import { ClickAnalyticsPlugin } from "../ClickAnalyticsPlugin";
12
- import { getClickTarget } from "../DataCollector";
13
- import { IClickAnalyticsConfiguration, IContentHandler, IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
14
- import { bracketIt, extractFieldFromObject, isValueAssigned } from "../common/Utils";
15
- import { WebEvent } from "./WebEvent";
16
-
17
- export class PageAction extends WebEvent {
18
-
19
- constructor(
20
- clickAnalyticsPlugin: ClickAnalyticsPlugin,
21
- config: IClickAnalyticsConfiguration,
22
- contentHandler: IContentHandler,
23
- pageTagsCallback: any,
24
- metaTags: { [name: string]: string },
25
- traceLogger: IDiagnosticLogger) {
26
- super(clickAnalyticsPlugin, config, contentHandler, pageTagsCallback, metaTags, traceLogger);
27
-
28
- dynamicProto(PageAction, this, (_self, _base) => {
29
-
30
- _self.trackPageAction = (pageActionEvent: IPageActionTelemetry, properties?: ICustomProperties): void => {
31
- // Get part A properties
32
- var ext = {};
33
- ext["web"] = {};
34
- let event: ITelemetryItem = {
35
- name: "Microsoft.ApplicationInsights.{0}.Event",
36
- baseType: "EventData",
37
- ext,
38
- data: {},
39
- baseData: {}
40
- };
41
-
42
- _populateEventDataIfPresent(event.baseData, "name", pageActionEvent.name);
43
- _populateEventDataIfPresent(event.data, "baseTypeSource", "ClickEvent");
44
- _populateEventDataIfPresent(event.data, "uri", pageActionEvent.uri);
45
- _populateEventDataIfPresent(event.data, "pageType", pageActionEvent.pageType);
46
- _populateEventDataIfPresent(event.data, "properties", pageActionEvent.properties);
47
- _populateEventDataIfPresent(event.data, "actionType", pageActionEvent.actionType);
48
- _populateEventDataIfPresent(event.data, "behavior", pageActionEvent.behavior);
49
- _populateEventDataIfPresent(event.data, "clickCoordinates", pageActionEvent.clickCoordinates);
50
- _populateEventDataIfPresent(event.data, "content", pageActionEvent.content);
51
- _populateEventDataIfPresent(event.data, "targetUri", pageActionEvent.targetUri);
52
- _populateEventDataIfPresent(event.data, "timeToAction", pageActionEvent.timeToAction);
53
- _populateEventDataIfPresent(event.data, "refUri", pageActionEvent.refUri);
54
- _populateEventDataIfPresent(event.data, "pageName", pageActionEvent.pageName);
55
- _populateEventDataIfPresent(event.data, "parentId", pageActionEvent.parentId);
56
-
57
- if (properties) {
58
- objForEachKey(properties, (property, value) => {
59
- if (!event.data[property]) {
60
- _populateEventDataIfPresent(event.data, property, value);
61
- }
62
- });
63
- }
64
- _self._clickAnalyticsPlugin.core.track(event);
65
- };
66
-
67
- /**
68
- * API to create and send a populated PageAction event
69
- * @param element - DOM element
70
- * @param overrideValues - PageAction overrides
71
- * @param customProperties - Custom properties(Part C)
72
- * @param isRightClick - Flag for mouse right clicks
73
- */
74
- _self.capturePageAction = (element: Element, overrideValues?: IPageActionOverrideValues, customProperties?: { [name: string]: string | number | boolean | string[] | number[] | boolean[] | object }, isRightClick?: boolean): void => {
75
- overrideValues = !isValueAssigned(overrideValues) ? {} : overrideValues;
76
- let pageActionEvent: IPageActionTelemetry = { name : ""};
77
- let pageActionProperties: ICustomProperties = isValueAssigned(customProperties) ? customProperties : {};
78
- _self.setCommonProperties(pageActionEvent, overrideValues);
79
- pageActionEvent.behavior = _self._getBehavior(overrideValues);
80
- // element in scope is needed for below properties. We cannot pass element into the plugin call chain.
81
- // process them here.
82
- let elementContent: any = {};
83
-
84
- if (isRightClick) {
85
- // Default behavior for righ click
86
- pageActionEvent.behavior = _self._config.defaultRightClickBhvr;
87
- }
88
- // Fill PartB
89
- if (element) {
90
- pageActionEvent.targetUri = getClickTarget(element);
91
-
92
- elementContent = _self._contentHandler.getElementContent(element); // collect id,cn tags
93
-
94
- // if the element has a data-*-bhvr attrib defined, use it.
95
- if (elementContent.bhvr && !isValueAssigned(overrideValues.behavior)) {
96
- let currentBehavior: string = extractFieldFromObject(elementContent, "bhvr");
97
- pageActionEvent.behavior = _self._getValidBehavior(currentBehavior);
98
- }
99
-
100
- // Validate to ensure the minimum required field 'contentName' or 'id' is present. However,
101
- // requiring these fields would result in majority of adopter's content from being collected.
102
- // Just throw a warning and continue collection.
103
- if (!isValueAssigned(elementContent.id) && !isValueAssigned(elementContent.contentName)) {
104
- _throwInternal(_self._traceLogger,
105
- eLoggingSeverity.WARNING,
106
- _eInternalMessageId.InvalidContentBlob, "Missing attributes id or contentName in click event. Click event information will still be collected!"
107
- );
108
- }
109
- }
110
- pageActionEvent.name = elementContent.id || elementContent.contentName || strNotSpecified;
111
- pageActionEvent.parentId = elementContent.parentid || elementContent.parentName || strNotSpecified;
112
-
113
- if (isValueAssigned(overrideValues.actionType)) {
114
- pageActionEvent.actionType = overrideValues.actionType;
115
- }
116
-
117
- if (isValueAssigned(overrideValues.clickCoordinateX) && isValueAssigned(overrideValues.clickCoordinateY)) {
118
- pageActionEvent.clickCoordinates = overrideValues.clickCoordinateX + "X" + overrideValues.clickCoordinateY;
119
- }
120
-
121
- _sanitizePageActionEventContent(elementContent);
122
- pageActionEvent.content = bracketIt(JSON.stringify(objExtend(
123
- elementContent,
124
- overrideValues && overrideValues.contentTags ? overrideValues.contentTags : {})));
125
-
126
-
127
- pageActionEvent.timeToAction = _getTimeToClick();
128
- pageActionEvent.refUri = isValueAssigned(overrideValues.refUri) ? overrideValues.refUri : _self._config.coreData.referrerUri;
129
- if(_isUndefinedEvent(pageActionEvent)) {
130
- return;
131
- }
132
- _self.trackPageAction(pageActionEvent, pageActionProperties);
133
- };
134
-
135
- // capture performance data into PageTags
136
- function _getTimeToClick() {
137
- const perf = getPerformance();
138
- if (perf && perf.timing) {
139
- var isNavigationStart = perf.timing.navigationStart;
140
- if (isNavigationStart && isNavigationStart !== 0) {
141
- return new Date().getTime() - isNavigationStart;
142
- }
143
- }
144
- return -1;
145
- }
146
-
147
- function _populateEventDataIfPresent(obj:any, property:any, value:any) {
148
- if(isValueAssigned(value)) {
149
- obj[property] = value;
150
- }
151
- }
152
-
153
- function _sanitizePageActionEventContent(pageActionContent: any) {
154
- if(pageActionContent) {
155
- delete pageActionContent.id;
156
- delete pageActionContent.parentid;
157
- delete pageActionContent.parentname;
158
- if(_self._config && _self._config.dataTags && isValueAssigned(_self._config.dataTags.parentDataTag)) {
159
- delete pageActionContent[_self._config.dataTags.parentDataTag];
160
- }
161
- }
162
- }
163
-
164
- function _isUndefinedEvent(pageActionEvent: IPageActionTelemetry) {
165
- if(_self._config.dropInvalidEvents) {
166
- if(pageActionEvent.name === strNotSpecified
167
- && pageActionEvent.parentId === strNotSpecified
168
- && pageActionEvent.content === "[{}]") {
169
- return true;
170
- }
171
- }
172
-
173
- return false;
174
- }
175
- });
176
- }
177
-
178
- /**
179
- * API to send pageAction event
180
- * @param pageActionEvent - PageAction event
181
- * @param properties - PageAction properties(Part C)
182
- */
183
- public trackPageAction(pageActionEvent: IPageActionTelemetry, properties?: ICustomProperties): void {
184
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
185
- }
186
-
187
- /**
188
- * API to create and send a populated PageAction event
189
- * @param element - DOM element
190
- * @param overrideValues - PageAction overrides
191
- * @param customProperties - Custom properties(Part C)
192
- * @param isRightClick - Flag for mouse right clicks
193
- */
194
- public capturePageAction(element: Element, overrideValues?: IPageActionOverrideValues, customProperties?: { [name: string]: string | number | boolean | string[] | number[] | boolean[] | object }, isRightClick?: boolean): void {
195
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
196
- }
197
- }
@@ -1,202 +0,0 @@
1
- /**
2
- * @copyright Microsoft 2020
3
- */
4
-
5
- import dynamicProto from "@microsoft/dynamicproto-js";
6
- import {
7
- IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState, IUnloadableComponent, getLocation, hasWindow, objExtend
8
- } from "@microsoft/applicationinsights-core-js";
9
- import { ClickAnalyticsPlugin } from "../ClickAnalyticsPlugin";
10
- import { getPageName, getUri } from "../DataCollector";
11
- import {
12
- IClickAnalyticsConfiguration, IContentHandler, ICoreData, IOverrideValues, IPageActionTelemetry, IPageTags
13
- } from "../Interfaces/Datamodel";
14
- import { isValueAssigned } from "../common/Utils";
15
-
16
- export class WebEvent implements IUnloadableComponent {
17
-
18
- protected _pageTags: IPageTags;
19
- protected _pageTypeMetaTag: string;
20
- protected _marketMetaTag: string;
21
- protected _behaviorMetaTag: string;
22
- protected _clickAnalyticsPlugin: ClickAnalyticsPlugin;
23
- protected _config: IClickAnalyticsConfiguration;
24
- protected _contentHandler: IContentHandler;
25
- protected _pageTagsCallback: any;
26
- protected _metaTags: { [name: string]: string };
27
- protected _traceLogger: IDiagnosticLogger;
28
-
29
- /**
30
- * @param clickAnalyticsPlugin - Click Analytics plugin instance
31
- * @param config - ClickAnalytics configuration object
32
- * @param contentHandler - Content handler
33
- * @param id - Id object
34
- * @param pageTagsCallback - callback methods to get pageTags value
35
- * @param metaTags - Meta tags
36
- * @param traceLogger - Trace logger to log to console.
37
- */
38
- constructor(
39
- clickAnalyticsPlugin: ClickAnalyticsPlugin,
40
- config: IClickAnalyticsConfiguration,
41
- contentHandler: IContentHandler,
42
- pageTagsCallback: any,
43
- metaTags: { [name: string]: string },
44
- traceLogger: IDiagnosticLogger) {
45
-
46
- dynamicProto(WebEvent, this, (_self) => {
47
- _initDefaults();
48
-
49
- function _initDefaults() {
50
- _self._pageTags = {};
51
- _self._clickAnalyticsPlugin = clickAnalyticsPlugin;
52
- _self._config = config;
53
- _self._contentHandler = contentHandler;
54
- _self._pageTagsCallback = pageTagsCallback;
55
- _self._metaTags = metaTags;
56
- _self._traceLogger = traceLogger;
57
- }
58
-
59
- _self.setBasicProperties = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
60
- if (!isValueAssigned(event.name)) {
61
- event.pageName = getPageName(_self._config, overrideValues);
62
- }
63
- if (!isValueAssigned(event.uri) && hasWindow) {
64
- event.uri = getUri(_self._config, getLocation());
65
- }
66
- };
67
-
68
- /**
69
- * Sets common properties for events that are based on the WebEvent schema.
70
- * @param event - The event
71
- */
72
- _self.setCommonProperties = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
73
- _self.setBasicProperties(event, overrideValues);
74
- _self._setPageTags(event, overrideValues);
75
-
76
- // extract specific meta tags out of the pageTags.metaTags collection. These will go into assigned first class fields in the event.
77
- // the rest will go into pageTags.metaTags collection as is.
78
- _self._pageTypeMetaTag = _getMetaData(_self._metaTags, _self._config.coreData, "pageType");
79
- _self._behaviorMetaTag = _getMetaData(_self._metaTags, _self._config.coreData, "behavior");
80
-
81
- if (isValueAssigned(overrideValues.pageType)) {
82
- event.pageType = overrideValues.pageType;
83
- }
84
- // Only assign if not overriden and meta data is available
85
- if (isValueAssigned(_self._pageTypeMetaTag) && !isValueAssigned(event.pageType)) {
86
- event.pageType = _self._pageTypeMetaTag;
87
- }
88
- };
89
-
90
- /**
91
- * Sets pageTags.
92
- * @param event - The event
93
- */
94
- _self._setPageTags = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
95
- // Prepare the pageTags object that is mostly the same for all events. Event specific pageTags will be added inside event constructors.
96
-
97
- if (_self._pageTagsCallback) {
98
- _self._pageTags = objExtend(true, _self._pageTags, _self._pageTagsCallback());
99
- }
100
- if (isValueAssigned(overrideValues.pageTags)) {
101
- _self._pageTags = objExtend(true, _self._pageTags, overrideValues.pageTags);
102
- }
103
- // If metadata is present add it to pageTags property
104
- if (_self._metaTags) {
105
- _self._pageTags.metaTags = {};
106
- // Remove not supported meta data in pageTags.metaTags
107
- for (var metaTag in _self._metaTags) {
108
- if (metaTag != "behavior" && metaTag != "market" && metaTag != "pageType") {
109
- _self._pageTags.metaTags[metaTag] = _self._metaTags[metaTag];
110
- }
111
- }
112
- }
113
- // All metadata tags that must be saved as properties have been extracted at this point. Assign pageTags as is.
114
- event.properties = event.properties || {};
115
- event.properties["pageTags"] = _self._pageTags;
116
- };
117
-
118
- _self._getBehavior = (overrideValues?: IOverrideValues): string | number => {
119
- let behavior: string | number;
120
- // If override specified
121
- if (overrideValues && isValueAssigned(overrideValues.behavior)) {
122
- behavior = overrideValues.behavior;
123
- } else if (isValueAssigned(_self._behaviorMetaTag)) {
124
- // If behavior meta tag available
125
- behavior = _self._behaviorMetaTag;
126
- }
127
- return _self._getValidBehavior(behavior);
128
- };
129
-
130
- _self._getValidBehavior = (behavior: string | number): string | number => {
131
- return _self._config.behaviorValidator(behavior);
132
- };
133
-
134
- _self._doUnload = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean => {
135
- _initDefaults();
136
- };
137
-
138
- /**
139
- * Get the specified metadata value from the collection
140
- * If overrideValue is specified in the config that takes precedence.
141
- * @param metaTags - Meta data.
142
- * @param coreData - Coredata values from configuration.
143
- * @param metaTagName - Name of the metaTag to get.
144
- * @returns Meta data value
145
- */
146
- function _getMetaData(metaTags: { [name: string]: string }, coreData: ICoreData, metaTagName: string): string {
147
- if (coreData && coreData[metaTagName]) {
148
- return coreData[metaTagName];
149
- }
150
-
151
- if (metaTags) {
152
- return metaTags[metaTagName];
153
- }
154
-
155
- return "";
156
- }
157
- });
158
- }
159
-
160
- // Fill common PartB fields
161
- public setBasicProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
162
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
163
- }
164
-
165
- /**
166
- * Sets common properties for events that are based on the WebEvent schema.
167
- * @param event - The event
168
- */
169
- public setCommonProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
170
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
171
- }
172
-
173
- /**
174
- * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
175
- * finishes it's removal.
176
- * @param unloadCtx - This is the context that should be used during unloading.
177
- * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
178
- * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
179
- * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
180
- */
181
- public _doUnload(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
182
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
183
- }
184
-
185
- /**
186
- * Sets pageTags.
187
- * @param event - The event
188
- */
189
- protected _setPageTags(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
190
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
191
- }
192
-
193
- protected _getBehavior(overrideValues?: IOverrideValues): string | number {
194
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
195
- return null;
196
- }
197
-
198
- protected _getValidBehavior(behavior: string | number): string | number {
199
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
200
- return null;
201
- }
202
- }