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

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 (80) hide show
  1. package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.js +2890 -0
  2. package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.js.map +1 -0
  3. package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.min.js +6 -0
  4. package/browser/ai.clck.2.8.0-nightly.2204-06.cjs.min.js.map +1 -0
  5. package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.js +2894 -0
  6. package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.js.map +1 -0
  7. package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.min.js +6 -0
  8. package/browser/ai.clck.2.8.0-nightly.2204-06.gbl.min.js.map +1 -0
  9. package/browser/ai.clck.2.8.0-nightly.2204-06.integrity.json +66 -0
  10. package/browser/ai.clck.2.8.0-nightly.2204-06.js +2896 -0
  11. package/browser/ai.clck.2.8.0-nightly.2204-06.js.map +1 -0
  12. package/browser/ai.clck.2.8.0-nightly.2204-06.min.js +6 -0
  13. package/browser/ai.clck.2.8.0-nightly.2204-06.min.js.map +1 -0
  14. package/browser/ai.clck.2.cjs.js +1689 -805
  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 +1689 -805
  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 +1689 -805
  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 +1689 -805
  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 +75 -51
  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 +130 -128
  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 +281 -278
  50. package/dist-esm/handlers/DomContentHandler.js.map +1 -1
  51. package/package.json +5 -5
  52. package/src/ClickAnalyticsPlugin.ts +94 -49
  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 +166 -132
  57. package/src/events/WebEvent.ts +147 -78
  58. package/src/handlers/AutoCaptureHandler.ts +92 -79
  59. package/src/handlers/DomContentHandler.ts +337 -304
  60. package/types/ClickAnalyticsPlugin.d.ts +1 -4
  61. package/types/Interfaces/Datamodel.d.ts +3 -2
  62. package/types/common/Utils.d.ts +79 -79
  63. package/types/events/PageAction.d.ts +6 -6
  64. package/types/events/WebEvent.d.ts +17 -17
  65. package/types/handlers/AutoCaptureHandler.d.ts +2 -10
  66. package/types/handlers/DomContentHandler.d.ts +3 -50
  67. package/types/tsdoc-metadata.json +1 -1
  68. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js +0 -2006
  69. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.js.map +0 -1
  70. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js +0 -6
  71. package/browser/ai.clck.2.8.0-nightly.2202-06.cjs.min.js.map +0 -1
  72. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js +0 -2010
  73. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.js.map +0 -1
  74. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js +0 -6
  75. package/browser/ai.clck.2.8.0-nightly.2202-06.gbl.min.js.map +0 -1
  76. package/browser/ai.clck.2.8.0-nightly.2202-06.integrity.json +0 -66
  77. package/browser/ai.clck.2.8.0-nightly.2202-06.js +0 -2012
  78. package/browser/ai.clck.2.8.0-nightly.2202-06.js.map +0 -1
  79. package/browser/ai.clck.2.8.0-nightly.2202-06.min.js +0 -6
  80. package/browser/ai.clck.2.8.0-nightly.2202-06.min.js.map +0 -1
@@ -2,55 +2,183 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
+ import dynamicProto from "@microsoft/dynamicproto-js";
5
6
  import { WebEvent } from "./WebEvent";
6
7
  import * as DataCollector from "../DataCollector";
7
- import { ITelemetryItem, getPerformance, ICustomProperties, LoggingSeverity, objForEachKey } from "@microsoft/applicationinsights-core-js"
8
- import { IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
9
- import { extractFieldFromObject, bracketIt, isValueAssigned, extend, _ExtendedInternalMessageId } from "../common/Utils";
8
+ import { ITelemetryItem, getPerformance, ICustomProperties, eLoggingSeverity, _eInternalMessageId, objForEachKey, IDiagnosticLogger, _throwInternal } from "@microsoft/applicationinsights-core-js"
9
+ import { IClickAnalyticsConfiguration, IContentHandler, IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
10
+ import { extractFieldFromObject, bracketIt, isValueAssigned, extend } from "../common/Utils";
10
11
  import { strNotSpecified } from "@microsoft/applicationinsights-common";
12
+ import { ClickAnalyticsPlugin } from "../ClickAnalyticsPlugin";
11
13
 
12
14
  export class PageAction extends WebEvent {
13
15
 
16
+ constructor(
17
+ clickAnalyticsPlugin: ClickAnalyticsPlugin,
18
+ config: IClickAnalyticsConfiguration,
19
+ contentHandler: IContentHandler,
20
+ pageTagsCallback: any,
21
+ metaTags: { [name: string]: string },
22
+ traceLogger: IDiagnosticLogger) {
23
+ super(clickAnalyticsPlugin, config, contentHandler, pageTagsCallback, metaTags, traceLogger);
24
+
25
+ dynamicProto(PageAction, this, (_self, _base) => {
26
+
27
+ _self.trackPageAction = (pageActionEvent: IPageActionTelemetry, properties?: ICustomProperties): void => {
28
+ // Get part A properties
29
+ var ext = {};
30
+ ext["web"] = {};
31
+ let event: ITelemetryItem = {
32
+ name: "Microsoft.ApplicationInsights.{0}.Event",
33
+ baseType: "EventData",
34
+ ext,
35
+ data: {},
36
+ baseData: {}
37
+ };
38
+
39
+ _populateEventDataIfPresent(event.baseData, "name", pageActionEvent.name);
40
+ _populateEventDataIfPresent(event.data, "baseTypeSource", "ClickEvent");
41
+ _populateEventDataIfPresent(event.data, "uri", pageActionEvent.uri);
42
+ _populateEventDataIfPresent(event.data, "pageType", pageActionEvent.pageType);
43
+ _populateEventDataIfPresent(event.data, "properties", pageActionEvent.properties);
44
+ _populateEventDataIfPresent(event.data, "actionType", pageActionEvent.actionType);
45
+ _populateEventDataIfPresent(event.data, "behavior", pageActionEvent.behavior);
46
+ _populateEventDataIfPresent(event.data, "clickCoordinates", pageActionEvent.clickCoordinates);
47
+ _populateEventDataIfPresent(event.data, "content", pageActionEvent.content);
48
+ _populateEventDataIfPresent(event.data, "targetUri", pageActionEvent.targetUri);
49
+ _populateEventDataIfPresent(event.data, "timeToAction", pageActionEvent.timeToAction);
50
+ _populateEventDataIfPresent(event.data, "refUri", pageActionEvent.refUri);
51
+ _populateEventDataIfPresent(event.data, "pageName", pageActionEvent.pageName);
52
+ _populateEventDataIfPresent(event.data, "parentId", pageActionEvent.parentId);
53
+
54
+ if (properties) {
55
+ objForEachKey(properties, (property, value) => {
56
+ if (!event.data[property]) {
57
+ _populateEventDataIfPresent(event.data, property, value);
58
+ }
59
+ });
60
+ }
61
+ _self._clickAnalyticsPlugin.core.track(event);
62
+ };
63
+
64
+ /**
65
+ * API to create and send a populated PageAction event
66
+ * @param element - DOM element
67
+ * @param overrideValues - PageAction overrides
68
+ * @param customProperties - Custom properties(Part C)
69
+ * @param isRightClick - Flag for mouse right clicks
70
+ */
71
+ _self.capturePageAction = (element: Element, overrideValues?: IPageActionOverrideValues, customProperties?: { [name: string]: string | number | boolean | string[] | number[] | boolean[] | object }, isRightClick?: boolean): void => {
72
+ overrideValues = !isValueAssigned(overrideValues) ? {} : overrideValues;
73
+ let pageActionEvent: IPageActionTelemetry = { name : ""};
74
+ let pageActionProperties: ICustomProperties = isValueAssigned(customProperties) ? customProperties : {};
75
+ _self.setCommonProperties(pageActionEvent, overrideValues);
76
+ pageActionEvent.behavior = _self._getBehavior(overrideValues);
77
+ // element in scope is needed for below properties. We cannot pass element into the plugin call chain.
78
+ // process them here.
79
+ let elementContent: any = {};
80
+
81
+ if (isRightClick) {
82
+ // Default behavior for righ click
83
+ pageActionEvent.behavior = _self._config.defaultRightClickBhvr;
84
+ }
85
+ // Fill PartB
86
+ if (element) {
87
+ pageActionEvent.targetUri = DataCollector.getClickTarget(element);
88
+
89
+ elementContent = _self._contentHandler.getElementContent(element); // collect id,cn tags
90
+
91
+ // if the element has a data-*-bhvr attrib defined, use it.
92
+ if (elementContent.bhvr && !isValueAssigned(overrideValues.behavior)) {
93
+ let currentBehavior: string = extractFieldFromObject(elementContent, "bhvr");
94
+ pageActionEvent.behavior = _self._getValidBehavior(currentBehavior);
95
+ }
96
+
97
+ // Validate to ensure the minimum required field 'contentName' or 'id' is present. However,
98
+ // requiring these fields would result in majority of adopter's content from being collected.
99
+ // Just throw a warning and continue collection.
100
+ if (!isValueAssigned(elementContent.id) && !isValueAssigned(elementContent.contentName)) {
101
+ _throwInternal(_self._traceLogger,
102
+ eLoggingSeverity.WARNING,
103
+ _eInternalMessageId.InvalidContentBlob, "Missing attributes id or contentName in click event. Click event information will still be collected!"
104
+ );
105
+ }
106
+ }
107
+ pageActionEvent.name = elementContent.id || elementContent.contentName || strNotSpecified;
108
+ pageActionEvent.parentId = elementContent.parentid || elementContent.parentName || strNotSpecified;
109
+
110
+ if (isValueAssigned(overrideValues.actionType)) {
111
+ pageActionEvent.actionType = overrideValues.actionType;
112
+ }
113
+
114
+ if (isValueAssigned(overrideValues.clickCoordinateX) && isValueAssigned(overrideValues.clickCoordinateY)) {
115
+ pageActionEvent.clickCoordinates = overrideValues.clickCoordinateX + "X" + overrideValues.clickCoordinateY;
116
+ }
117
+
118
+ _sanitizePageActionEventContent(elementContent);
119
+ pageActionEvent.content = bracketIt(JSON.stringify(extend(
120
+ elementContent,
121
+ overrideValues && overrideValues.contentTags ? overrideValues.contentTags : {})));
122
+
123
+
124
+ pageActionEvent.timeToAction = _getTimeToClick();
125
+ pageActionEvent.refUri = isValueAssigned(overrideValues.refUri) ? overrideValues.refUri : _self._config.coreData.referrerUri;
126
+ if(_isUndefinedEvent(pageActionEvent)) {
127
+ return;
128
+ }
129
+ _self.trackPageAction(pageActionEvent, pageActionProperties);
130
+ };
131
+
132
+ // capture performance data into PageTags
133
+ function _getTimeToClick() {
134
+ const perf = getPerformance();
135
+ if (perf && perf.timing) {
136
+ var isNavigationStart = perf.timing.navigationStart;
137
+ if (isNavigationStart && isNavigationStart !== 0) {
138
+ return new Date().getTime() - isNavigationStart;
139
+ }
140
+ }
141
+ return -1;
142
+ }
143
+
144
+ function _populateEventDataIfPresent(obj:any, property:any, value:any) {
145
+ if(isValueAssigned(value)) {
146
+ obj[property] = value;
147
+ }
148
+ }
149
+
150
+ function _sanitizePageActionEventContent(pageActionContent: any) {
151
+ if(pageActionContent) {
152
+ delete pageActionContent.id;
153
+ delete pageActionContent.parentid;
154
+ delete pageActionContent.parentname;
155
+ if(_self._config && _self._config.dataTags && isValueAssigned(_self._config.dataTags.parentDataTag)) {
156
+ delete pageActionContent[_self._config.dataTags.parentDataTag];
157
+ }
158
+ }
159
+ }
160
+
161
+ function _isUndefinedEvent(pageActionEvent: IPageActionTelemetry) {
162
+ if(_self._config.dropInvalidEvents) {
163
+ if(pageActionEvent.name === strNotSpecified
164
+ && pageActionEvent.parentId === strNotSpecified
165
+ && pageActionEvent.content === "[{}]") {
166
+ return true;
167
+ }
168
+ }
169
+
170
+ return false;
171
+ }
172
+ });
173
+ }
174
+
14
175
  /**
15
176
  * API to send pageAction event
16
177
  * @param pageActionEvent - PageAction event
17
178
  * @param properties - PageAction properties(Part C)
18
179
  */
19
180
  public trackPageAction(pageActionEvent: IPageActionTelemetry, properties?: ICustomProperties): void {
20
- // Get part A properties
21
- var ext = {};
22
- ext["web"] = {};
23
- let event: ITelemetryItem = {
24
- name: "Microsoft.ApplicationInsights.{0}.Event",
25
- baseType: "EventData",
26
- ext,
27
- data: {},
28
- baseData: {}
29
- };
30
-
31
- this._populateEventDataIfPresent(event.baseData, "name", pageActionEvent.name);
32
- this._populateEventDataIfPresent(event.data, "baseTypeSource", "ClickEvent");
33
- this._populateEventDataIfPresent(event.data, "uri", pageActionEvent.uri);
34
- this._populateEventDataIfPresent(event.data, "pageType", pageActionEvent.pageType);
35
- this._populateEventDataIfPresent(event.data, "properties", pageActionEvent.properties);
36
- this._populateEventDataIfPresent(event.data, "actionType", pageActionEvent.actionType);
37
- this._populateEventDataIfPresent(event.data, "behavior", pageActionEvent.behavior);
38
- this._populateEventDataIfPresent(event.data, "clickCoordinates", pageActionEvent.clickCoordinates);
39
- this._populateEventDataIfPresent(event.data, "content", pageActionEvent.content);
40
- this._populateEventDataIfPresent(event.data, "targetUri", pageActionEvent.targetUri);
41
- this._populateEventDataIfPresent(event.data, "timeToAction", pageActionEvent.timeToAction);
42
- this._populateEventDataIfPresent(event.data, "refUri", pageActionEvent.refUri);
43
- this._populateEventDataIfPresent(event.data, "pageName", pageActionEvent.pageName);
44
- this._populateEventDataIfPresent(event.data, "parentId", pageActionEvent.parentId);
45
-
46
- if (properties) {
47
- objForEachKey(properties, (property, value) => {
48
- if (!event.data[property]) {
49
- this._populateEventDataIfPresent(event.data, property, value);
50
- }
51
- });
52
- }
53
- this._clickAnalyticsPlugin.core.track(event);
181
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
54
182
  }
55
183
 
56
184
  /**
@@ -61,100 +189,6 @@ export class PageAction extends WebEvent {
61
189
  * @param isRightClick - Flag for mouse right clicks
62
190
  */
63
191
  public capturePageAction(element: Element, overrideValues?: IPageActionOverrideValues, customProperties?: { [name: string]: string | number | boolean | string[] | number[] | boolean[] | object }, isRightClick?: boolean): void {
64
- overrideValues = !isValueAssigned(overrideValues) ? {} : overrideValues;
65
- let pageActionEvent: IPageActionTelemetry = { name : ""};
66
- let pageActionProperties: ICustomProperties = isValueAssigned(customProperties) ? customProperties : {};
67
- this.setCommonProperties(pageActionEvent, overrideValues);
68
- pageActionEvent.behavior = this._getBehavior(overrideValues);
69
- // element in scope is needed for below properties. We cannot pass element into the plugin call chain.
70
- // process them here.
71
- let elementContent: any = {};
72
-
73
- if (isRightClick) {
74
- // Default behavior for righ click
75
- pageActionEvent.behavior = this._config.defaultRightClickBhvr;
76
- }
77
- // Fill PartB
78
- if (element) {
79
- pageActionEvent.targetUri = DataCollector.getClickTarget(element);
80
-
81
- elementContent = this._contentHandler.getElementContent(element); // collect id,cn tags
82
-
83
- // if the element has a data-*-bhvr attrib defined, use it.
84
- if (elementContent.bhvr && !isValueAssigned(overrideValues.behavior)) {
85
- let currentBehavior: string = extractFieldFromObject(elementContent, "bhvr");
86
- pageActionEvent.behavior = this._getValidBehavior(currentBehavior);
87
- }
88
-
89
- // Validate to ensure the minimum required field 'contentName' or 'id' is present. However,
90
- // requiring these fields would result in majority of adopter's content from being collected.
91
- // Just throw a warning and continue collection.
92
- if (!isValueAssigned(elementContent.id) && !isValueAssigned(elementContent.contentName)) {
93
- this._traceLogger.throwInternal(
94
- LoggingSeverity.WARNING,
95
- _ExtendedInternalMessageId.InvalidContentBlob, "Missing attributes id or contentName in click event. Click event information will still be collected!"
96
- );
97
- }
98
- }
99
- pageActionEvent.name = elementContent.id || elementContent.contentName || strNotSpecified;
100
- pageActionEvent.parentId = elementContent.parentid || elementContent.parentName || strNotSpecified;
101
-
102
- if (isValueAssigned(overrideValues.actionType)) {
103
- pageActionEvent.actionType = overrideValues.actionType;
104
- }
105
- if (isValueAssigned(overrideValues.clickCoordinateX) && isValueAssigned(overrideValues.clickCoordinateY)) {
106
- pageActionEvent.clickCoordinates = overrideValues.clickCoordinateX + "X" + overrideValues.clickCoordinateY;
107
- }
108
-
109
- this._sanitizePageActionEventContent(elementContent);
110
- pageActionEvent.content = bracketIt(JSON.stringify(extend(
111
- elementContent,
112
- overrideValues && overrideValues.contentTags ? overrideValues.contentTags : {})));
113
-
114
-
115
- pageActionEvent.timeToAction = this._getTimeToClick();
116
- pageActionEvent.refUri = isValueAssigned(overrideValues.refUri) ? overrideValues.refUri : this._config.coreData.referrerUri;
117
- if(this._isUndefinedEvent(pageActionEvent)) return;
118
- this.trackPageAction(pageActionEvent, pageActionProperties);
119
- }
120
-
121
- // capture performance data into PageTags
122
- private _getTimeToClick() {
123
- const perf = getPerformance();
124
- if (perf && perf.timing) {
125
- var isNavigationStart = perf.timing.navigationStart;
126
- if (isNavigationStart && isNavigationStart !== 0) {
127
- return new Date().getTime() - isNavigationStart;
128
- }
129
- }
130
- return -1;
131
- }
132
-
133
- private _populateEventDataIfPresent(obj:any, property:any, value:any) {
134
- if(isValueAssigned(value)) {
135
- obj[property] = value;
136
- }
192
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
137
193
  }
138
-
139
- private _sanitizePageActionEventContent(pageActionContent: any) {
140
- if(pageActionContent) {
141
- delete pageActionContent.id;
142
- delete pageActionContent.parentid;
143
- delete pageActionContent.parentname;
144
- if(this._config && this._config.dataTags && isValueAssigned(this._config.dataTags.parentDataTag)) {
145
- delete pageActionContent[this._config.dataTags.parentDataTag];
146
- }
147
- }
148
- }
149
-
150
- private _isUndefinedEvent(pageActionEvent: IPageActionTelemetry) {
151
- if(this._config.dropInvalidEvents) {
152
- if(pageActionEvent.name === strNotSpecified
153
- && pageActionEvent.parentId === strNotSpecified
154
- && pageActionEvent.content === "[{}]")
155
- return true;
156
- }
157
- return false;
158
- }
159
-
160
194
  }
@@ -2,21 +2,27 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
-
5
+ import dynamicProto from "@microsoft/dynamicproto-js";
6
6
  import {
7
7
  isValueAssigned, extend
8
8
  } from "../common/Utils";
9
9
  import * as DataCollector from "../DataCollector";
10
- import { IDiagnosticLogger, getLocation, hasWindow } from "@microsoft/applicationinsights-core-js";
10
+ import { IDiagnosticLogger, getLocation, hasWindow, IUnloadableComponent, IProcessTelemetryUnloadContext, ITelemetryUnloadState } from "@microsoft/applicationinsights-core-js";
11
11
  import { IClickAnalyticsConfiguration, IPageTags, IOverrideValues, IContentHandler, ICoreData, IPageActionTelemetry } from "../Interfaces/Datamodel";
12
12
  import { ClickAnalyticsPlugin } from "../ClickAnalyticsPlugin";
13
13
 
14
- export class WebEvent {
14
+ export class WebEvent implements IUnloadableComponent {
15
15
 
16
- protected _pageTags: IPageTags = {};
16
+ protected _pageTags: IPageTags;
17
17
  protected _pageTypeMetaTag: string;
18
18
  protected _marketMetaTag: string;
19
19
  protected _behaviorMetaTag: string;
20
+ protected _clickAnalyticsPlugin: ClickAnalyticsPlugin;
21
+ protected _config: IClickAnalyticsConfiguration;
22
+ protected _contentHandler: IContentHandler;
23
+ protected _pageTagsCallback: any;
24
+ protected _metaTags: { [name: string]: string };
25
+ protected _traceLogger: IDiagnosticLogger;
20
26
 
21
27
  /**
22
28
  * @param clickAnalyticsPlugin - Click Analytics plugin instance
@@ -27,20 +33,131 @@ export class WebEvent {
27
33
  * @param metaTags - Meta tags
28
34
  * @param traceLogger - Trace logger to log to console.
29
35
  */
30
- constructor(protected _clickAnalyticsPlugin: ClickAnalyticsPlugin, protected _config: IClickAnalyticsConfiguration, protected _contentHandler: IContentHandler,
31
- protected _pageTagsCallback: any, protected _metaTags: { [name: string]: string },
32
- protected _traceLogger: IDiagnosticLogger) {
36
+ constructor(
37
+ clickAnalyticsPlugin: ClickAnalyticsPlugin,
38
+ config: IClickAnalyticsConfiguration,
39
+ contentHandler: IContentHandler,
40
+ pageTagsCallback: any,
41
+ metaTags: { [name: string]: string },
42
+ traceLogger: IDiagnosticLogger) {
43
+
44
+ dynamicProto(WebEvent, this, (_self) => {
45
+ _initDefaults();
46
+
47
+ function _initDefaults() {
48
+ _self._pageTags = {};
49
+ _self._clickAnalyticsPlugin = clickAnalyticsPlugin;
50
+ _self._config = config;
51
+ _self._contentHandler = contentHandler;
52
+ _self._pageTagsCallback = pageTagsCallback;
53
+ _self._metaTags = metaTags;
54
+ _self._traceLogger = traceLogger;
55
+ }
56
+
57
+ _self.setBasicProperties = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
58
+ if (!isValueAssigned(event.name)) {
59
+ event.pageName = DataCollector.getPageName(_self._config, overrideValues);
60
+ }
61
+ if (!isValueAssigned(event.uri) && hasWindow) {
62
+ event.uri = DataCollector.getUri(_self._config, getLocation());
63
+ }
64
+ };
65
+
66
+ /**
67
+ * Sets common properties for events that are based on the WebEvent schema.
68
+ * @param event - The event
69
+ */
70
+ _self.setCommonProperties = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
71
+ _self.setBasicProperties(event, overrideValues);
72
+ _self._setPageTags(event, overrideValues);
73
+
74
+ // extract specific meta tags out of the pageTags.metaTags collection. These will go into assigned first class fields in the event.
75
+ // the rest will go into pageTags.metaTags collection as is.
76
+ _self._pageTypeMetaTag = _getMetaData(_self._metaTags, _self._config.coreData, "pageType");
77
+ _self._behaviorMetaTag = _getMetaData(_self._metaTags, _self._config.coreData, "behavior");
78
+
79
+ if (isValueAssigned(overrideValues.pageType)) {
80
+ event.pageType = overrideValues.pageType;
81
+ }
82
+ // Only assign if not overriden and meta data is available
83
+ if (isValueAssigned(_self._pageTypeMetaTag) && !isValueAssigned(event.pageType)) {
84
+ event.pageType = _self._pageTypeMetaTag;
85
+ }
86
+ };
87
+
88
+ /**
89
+ * Sets pageTags.
90
+ * @param event - The event
91
+ */
92
+ _self._setPageTags = (event: IPageActionTelemetry, overrideValues: IOverrideValues) => {
93
+ // Prepare the pageTags object that is mostly the same for all events. Event specific pageTags will be added inside event constructors.
94
+
95
+ if (_self._pageTagsCallback) {
96
+ _self._pageTags = extend(true, _self._pageTags, _self._pageTagsCallback());
97
+ }
98
+ if (isValueAssigned(overrideValues.pageTags)) {
99
+ _self._pageTags = extend(true, _self._pageTags, overrideValues.pageTags);
100
+ }
101
+ // If metadata is present add it to pageTags property
102
+ if (_self._metaTags) {
103
+ _self._pageTags.metaTags = {};
104
+ // Remove not supported meta data in pageTags.metaTags
105
+ for (var metaTag in _self._metaTags) {
106
+ if (metaTag != "behavior" && metaTag != "market" && metaTag != "pageType") {
107
+ _self._pageTags.metaTags[metaTag] = _self._metaTags[metaTag];
108
+ }
109
+ }
110
+ }
111
+ // All metadata tags that must be saved as properties have been extracted at this point. Assign pageTags as is.
112
+ event.properties = event.properties || {};
113
+ event.properties["pageTags"] = _self._pageTags;
114
+ };
115
+
116
+ _self._getBehavior = (overrideValues?: IOverrideValues): string | number => {
117
+ let behavior: string | number;
118
+ // If override specified
119
+ if (overrideValues && isValueAssigned(overrideValues.behavior)) {
120
+ behavior = overrideValues.behavior;
121
+ } else if (isValueAssigned(_self._behaviorMetaTag)) {
122
+ // If behavior meta tag available
123
+ behavior = _self._behaviorMetaTag;
124
+ }
125
+ return _self._getValidBehavior(behavior);
126
+ };
127
+
128
+ _self._getValidBehavior = (behavior: string | number): string | number => {
129
+ return _self._config.behaviorValidator(behavior);
130
+ };
131
+
132
+ _self._doUnload = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean => {
133
+ _initDefaults();
134
+ };
135
+
136
+ /**
137
+ * Get the specified metadata value from the collection
138
+ * If overrideValue is specified in the config that takes precedence.
139
+ * @param metaTags - Meta data.
140
+ * @param coreData - Coredata values from configuration.
141
+ * @param metaTagName - Name of the metaTag to get.
142
+ * @returns Meta data value
143
+ */
144
+ function _getMetaData(metaTags: { [name: string]: string }, coreData: ICoreData, metaTagName: string): string {
145
+ if (coreData && coreData[metaTagName]) {
146
+ return coreData[metaTagName];
147
+ }
148
+
149
+ if (metaTags) {
150
+ return metaTags[metaTagName];
151
+ }
33
152
 
153
+ return "";
154
+ }
155
+ });
34
156
  }
35
157
 
36
158
  // Fill common PartB fields
37
159
  public setBasicProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
38
- if (!isValueAssigned(event.name)) {
39
- event.pageName = DataCollector.getPageName(this._config, overrideValues);
40
- }
41
- if (!isValueAssigned(event.uri) && hasWindow) {
42
- event.uri = DataCollector.getUri(this._config, getLocation());
43
- }
160
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
44
161
  }
45
162
 
46
163
  /**
@@ -48,21 +165,19 @@ export class WebEvent {
48
165
  * @param event - The event
49
166
  */
50
167
  public setCommonProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
51
- this.setBasicProperties(event, overrideValues);
52
- this._setPageTags(event, overrideValues);
53
-
54
- // extract specific meta tags out of the pageTags.metaTags collection. These will go into assigned first class fields in the event.
55
- // the rest will go into pageTags.metaTags collection as is.
56
- this._pageTypeMetaTag = this._getMetaData(this._metaTags, this._config.coreData, "pageType");
57
- this._behaviorMetaTag = this._getMetaData(this._metaTags, this._config.coreData, "behavior");
168
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
169
+ }
58
170
 
59
- if (isValueAssigned(overrideValues.pageType)) {
60
- event.pageType = overrideValues.pageType;
61
- }
62
- // Only assign if not overriden and meta data is available
63
- if (isValueAssigned(this._pageTypeMetaTag) && !isValueAssigned(event.pageType)) {
64
- event.pageType = this._pageTypeMetaTag;
65
- }
171
+ /**
172
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
173
+ * finishes it's removal.
174
+ * @param unloadCtx - This is the context that should be used during unloading.
175
+ * @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.
176
+ * @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.
177
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
178
+ */
179
+ public _doUnload(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
180
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
66
181
  }
67
182
 
68
183
  /**
@@ -70,62 +185,16 @@ export class WebEvent {
70
185
  * @param event - The event
71
186
  */
72
187
  protected _setPageTags(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
73
- // Prepare the pageTags object that is mostly the same for all events. Event specific pageTags will be added inside event constructors.
74
-
75
- if (this._pageTagsCallback) {
76
- this._pageTags = extend(true, this._pageTags, this._pageTagsCallback());
77
- }
78
- if (isValueAssigned(overrideValues.pageTags)) {
79
- this._pageTags = extend(true, this._pageTags, overrideValues.pageTags);
80
- }
81
- // If metadata is present add it to pageTags property
82
- if (this._metaTags) {
83
- this._pageTags.metaTags = {};
84
- // Remove not supported meta data in pageTags.metaTags
85
- for (var metaTag in this._metaTags) {
86
- if (metaTag != "behavior" && metaTag != "market" && metaTag != "pageType") {
87
- this._pageTags.metaTags[metaTag] = this._metaTags[metaTag];
88
- }
89
- }
90
- }
91
- // All metadata tags that must be saved as properties have been extracted at this point. Assign pageTags as is.
92
- event.properties = event.properties || {};
93
- event.properties["pageTags"] = this._pageTags;
188
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
94
189
  }
95
190
 
96
191
  protected _getBehavior(overrideValues?: IOverrideValues): string | number {
97
- let behavior: string | number;
98
- // If override specified
99
- if (overrideValues && isValueAssigned(overrideValues.behavior)) {
100
- behavior = overrideValues.behavior;
101
- }
102
- // If behavior meta tag available
103
- else if (isValueAssigned(this._behaviorMetaTag)) {
104
- behavior = this._behaviorMetaTag;
105
- }
106
- return this._getValidBehavior(behavior);
192
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
193
+ return null;
107
194
  }
108
195
 
109
196
  protected _getValidBehavior(behavior: string | number): string | number {
110
- return this._config.behaviorValidator(behavior);
197
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
198
+ return null;
111
199
  }
112
-
113
- /**
114
- * Get the specified metadata value from the collection
115
- * If overrideValue is specified in the config that takes precedence.
116
- * @param metaTags - Meta data.
117
- * @param coreData - Coredata values from configuration.
118
- * @param metaTagName - Name of the metaTag to get.
119
- * @returns Meta data value
120
- */
121
- private _getMetaData(metaTags: { [name: string]: string }, coreData: ICoreData, metaTagName: string): string {
122
- if (coreData && coreData[metaTagName]) {
123
- return coreData[metaTagName];
124
- } else if (metaTags) {
125
- return metaTags[metaTagName];
126
- }
127
- return "";
128
- }
129
-
130
-
131
200
  }