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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/browser/ai.clck.2.7.5.cjs.js +2011 -0
  2. package/browser/ai.clck.2.7.5.cjs.js.map +1 -0
  3. package/browser/ai.clck.2.7.5.cjs.min.js +6 -0
  4. package/browser/ai.clck.2.7.5.cjs.min.js.map +1 -0
  5. package/browser/ai.clck.2.7.5.gbl.js +2015 -0
  6. package/browser/ai.clck.2.7.5.gbl.js.map +1 -0
  7. package/browser/ai.clck.2.7.5.gbl.min.js +6 -0
  8. package/browser/ai.clck.2.7.5.gbl.min.js.map +1 -0
  9. package/browser/ai.clck.2.7.5.integrity.json +66 -0
  10. package/browser/ai.clck.2.7.5.js +2017 -0
  11. package/browser/ai.clck.2.7.5.js.map +1 -0
  12. package/browser/ai.clck.2.7.5.min.js +6 -0
  13. package/browser/ai.clck.2.7.5.min.js.map +1 -0
  14. package/browser/ai.clck.2.cjs.js +810 -1682
  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 +810 -1682
  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 +810 -1682
  23. package/browser/ai.clck.2.js.map +1 -1
  24. package/browser/ai.clck.2.min.js +2 -2
  25. package/browser/ai.clck.2.min.js.map +1 -1
  26. package/dist/applicationinsights-clickanalytics-js.api.json +27 -29
  27. package/dist/applicationinsights-clickanalytics-js.api.md +0 -1
  28. package/dist/applicationinsights-clickanalytics-js.d.ts +5 -2
  29. package/dist/applicationinsights-clickanalytics-js.js +810 -1682
  30. package/dist/applicationinsights-clickanalytics-js.js.map +1 -1
  31. package/dist/applicationinsights-clickanalytics-js.min.js +2 -2
  32. package/dist/applicationinsights-clickanalytics-js.min.js.map +1 -1
  33. package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +5 -2
  34. package/dist-esm/Behaviours.js +1 -1
  35. package/dist-esm/ClickAnalyticsPlugin.js +50 -74
  36. package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
  37. package/dist-esm/DataCollector.js +2 -4
  38. package/dist-esm/DataCollector.js.map +1 -1
  39. package/dist-esm/Enums.js +1 -1
  40. package/dist-esm/Interfaces/Datamodel.js +1 -1
  41. package/dist-esm/applicationinsights-clickanalytics-js.js +1 -1
  42. package/dist-esm/common/Utils.js +1 -1
  43. package/dist-esm/events/PageAction.js +126 -128
  44. package/dist-esm/events/PageAction.js.map +1 -1
  45. package/dist-esm/events/WebEvent.js +94 -109
  46. package/dist-esm/events/WebEvent.js.map +1 -1
  47. package/dist-esm/handlers/AutoCaptureHandler.js +83 -85
  48. package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
  49. package/dist-esm/handlers/DomContentHandler.js +276 -279
  50. package/dist-esm/handlers/DomContentHandler.js.map +1 -1
  51. package/package.json +56 -59
  52. package/src/ClickAnalyticsPlugin.ts +47 -92
  53. package/src/DataCollector.ts +22 -24
  54. package/src/Interfaces/Datamodel.ts +21 -20
  55. package/src/common/Utils.ts +8 -8
  56. package/src/events/PageAction.ts +131 -165
  57. package/src/events/WebEvent.ts +78 -147
  58. package/src/handlers/AutoCaptureHandler.ts +79 -89
  59. package/src/handlers/DomContentHandler.ts +303 -336
  60. package/types/ClickAnalyticsPlugin.d.ts +4 -1
  61. package/types/Interfaces/Datamodel.d.ts +2 -3
  62. package/types/events/PageAction.d.ts +6 -6
  63. package/types/events/WebEvent.d.ts +17 -17
  64. package/types/handlers/AutoCaptureHandler.d.ts +10 -2
  65. package/types/handlers/DomContentHandler.d.ts +50 -3
  66. package/types/tsdoc-metadata.json +1 -1
  67. package/browser/ai.clck.2.7.5-nightly.2203-03.cjs.js +0 -2883
  68. package/browser/ai.clck.2.7.5-nightly.2203-03.cjs.js.map +0 -1
  69. package/browser/ai.clck.2.7.5-nightly.2203-03.cjs.min.js +0 -6
  70. package/browser/ai.clck.2.7.5-nightly.2203-03.cjs.min.js.map +0 -1
  71. package/browser/ai.clck.2.7.5-nightly.2203-03.gbl.js +0 -2887
  72. package/browser/ai.clck.2.7.5-nightly.2203-03.gbl.js.map +0 -1
  73. package/browser/ai.clck.2.7.5-nightly.2203-03.gbl.min.js +0 -6
  74. package/browser/ai.clck.2.7.5-nightly.2203-03.gbl.min.js.map +0 -1
  75. package/browser/ai.clck.2.7.5-nightly.2203-03.integrity.json +0 -66
  76. package/browser/ai.clck.2.7.5-nightly.2203-03.js +0 -2889
  77. package/browser/ai.clck.2.7.5-nightly.2203-03.js.map +0 -1
  78. package/browser/ai.clck.2.7.5-nightly.2203-03.min.js +0 -6
  79. package/browser/ai.clck.2.7.5-nightly.2203-03.min.js.map +0 -1
@@ -2,183 +2,55 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
- import dynamicProto from "@microsoft/dynamicproto-js";
6
5
  import { WebEvent } from "./WebEvent";
7
6
  import * as DataCollector from "../DataCollector";
8
- import { ITelemetryItem, getPerformance, ICustomProperties, LoggingSeverity, objForEachKey, IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState } from "@microsoft/applicationinsights-core-js"
9
- import { IClickAnalyticsConfiguration, IContentHandler, IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
7
+ import { ITelemetryItem, getPerformance, ICustomProperties, LoggingSeverity, objForEachKey } from "@microsoft/applicationinsights-core-js"
8
+ import { IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
10
9
  import { extractFieldFromObject, bracketIt, isValueAssigned, extend, _ExtendedInternalMessageId } from "../common/Utils";
11
10
  import { strNotSpecified } from "@microsoft/applicationinsights-common";
12
- import { ClickAnalyticsPlugin } from "../ClickAnalyticsPlugin";
13
11
 
14
12
  export class PageAction extends WebEvent {
15
13
 
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
- _self._traceLogger.throwInternal(
102
- LoggingSeverity.WARNING,
103
- _ExtendedInternalMessageId.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
-
175
14
  /**
176
15
  * API to send pageAction event
177
16
  * @param pageActionEvent - PageAction event
178
17
  * @param properties - PageAction properties(Part C)
179
18
  */
180
19
  public trackPageAction(pageActionEvent: IPageActionTelemetry, properties?: ICustomProperties): void {
181
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
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);
182
54
  }
183
55
 
184
56
  /**
@@ -189,6 +61,100 @@ export class PageAction extends WebEvent {
189
61
  * @param isRightClick - Flag for mouse right clicks
190
62
  */
191
63
  public capturePageAction(element: Element, overrideValues?: IPageActionOverrideValues, customProperties?: { [name: string]: string | number | boolean | string[] | number[] | boolean[] | object }, isRightClick?: boolean): void {
192
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
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
+ }
193
137
  }
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
+
194
160
  }
@@ -2,27 +2,21 @@
2
2
  * @copyright Microsoft 2020
3
3
  */
4
4
 
5
- import dynamicProto from "@microsoft/dynamicproto-js";
5
+
6
6
  import {
7
7
  isValueAssigned, extend
8
8
  } from "../common/Utils";
9
9
  import * as DataCollector from "../DataCollector";
10
- import { IDiagnosticLogger, getLocation, hasWindow, IUnloadableComponent, IProcessTelemetryUnloadContext, ITelemetryUnloadState } from "@microsoft/applicationinsights-core-js";
10
+ import { IDiagnosticLogger, getLocation, hasWindow } 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 implements IUnloadableComponent {
14
+ export class WebEvent {
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;
26
20
 
27
21
  /**
28
22
  * @param clickAnalyticsPlugin - Click Analytics plugin instance
@@ -33,131 +27,20 @@ export class WebEvent implements IUnloadableComponent {
33
27
  * @param metaTags - Meta tags
34
28
  * @param traceLogger - Trace logger to log to console.
35
29
  */
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
- }
30
+ constructor(protected _clickAnalyticsPlugin: ClickAnalyticsPlugin, protected _config: IClickAnalyticsConfiguration, protected _contentHandler: IContentHandler,
31
+ protected _pageTagsCallback: any, protected _metaTags: { [name: string]: string },
32
+ protected _traceLogger: IDiagnosticLogger) {
152
33
 
153
- return "";
154
- }
155
- });
156
34
  }
157
35
 
158
36
  // Fill common PartB fields
159
37
  public setBasicProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
160
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
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
+ }
161
44
  }
162
45
 
163
46
  /**
@@ -165,19 +48,21 @@ export class WebEvent implements IUnloadableComponent {
165
48
  * @param event - The event
166
49
  */
167
50
  public setCommonProperties(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
168
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
169
- }
51
+ this.setBasicProperties(event, overrideValues);
52
+ this._setPageTags(event, overrideValues);
170
53
 
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
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");
58
+
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
+ }
181
66
  }
182
67
 
183
68
  /**
@@ -185,16 +70,62 @@ export class WebEvent implements IUnloadableComponent {
185
70
  * @param event - The event
186
71
  */
187
72
  protected _setPageTags(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
188
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
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;
189
94
  }
190
95
 
191
96
  protected _getBehavior(overrideValues?: IOverrideValues): string | number {
192
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
193
- return null;
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);
194
107
  }
195
108
 
196
109
  protected _getValidBehavior(behavior: string | number): string | number {
197
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
198
- return null;
110
+ return this._config.behaviorValidator(behavior);
199
111
  }
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
+
200
131
  }