@microsoft/applicationinsights-clickanalytics-js 2.8.0-beta.2203-10 → 2.8.0-beta.2203-11
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.
- package/browser/{ai.clck.2.8.0-beta.2203-10.cjs.js → ai.clck.2.8.0-beta.2203-11.cjs.js} +688 -514
- package/browser/ai.clck.2.8.0-beta.2203-11.cjs.js.map +1 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.cjs.min.js +6 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.cjs.min.js.map +1 -0
- package/browser/{ai.clck.2.8.0-beta.2203-10.gbl.js → ai.clck.2.8.0-beta.2203-11.gbl.js} +688 -514
- package/browser/ai.clck.2.8.0-beta.2203-11.gbl.js.map +1 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.gbl.min.js +6 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.gbl.min.js.map +1 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.integrity.json +66 -0
- package/browser/{ai.clck.2.8.0-beta.2203-10.js → ai.clck.2.8.0-beta.2203-11.js} +688 -514
- package/browser/ai.clck.2.8.0-beta.2203-11.js.map +1 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.min.js +6 -0
- package/browser/ai.clck.2.8.0-beta.2203-11.min.js.map +1 -0
- package/browser/ai.clck.2.cjs.js +687 -513
- package/browser/ai.clck.2.cjs.js.map +1 -1
- package/browser/ai.clck.2.cjs.min.js +2 -2
- package/browser/ai.clck.2.cjs.min.js.map +1 -1
- package/browser/ai.clck.2.gbl.js +687 -513
- package/browser/ai.clck.2.gbl.js.map +1 -1
- package/browser/ai.clck.2.gbl.min.js +2 -2
- package/browser/ai.clck.2.gbl.min.js.map +1 -1
- package/browser/ai.clck.2.js +687 -513
- package/browser/ai.clck.2.js.map +1 -1
- package/browser/ai.clck.2.min.js +2 -2
- package/browser/ai.clck.2.min.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.api.json +15 -1
- package/dist/applicationinsights-clickanalytics-js.api.md +1 -0
- package/dist/applicationinsights-clickanalytics-js.d.ts +2 -5
- package/dist/applicationinsights-clickanalytics-js.js +687 -513
- package/dist/applicationinsights-clickanalytics-js.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.min.js +2 -2
- package/dist/applicationinsights-clickanalytics-js.min.js.map +1 -1
- package/dist/applicationinsights-clickanalytics-js.rollup.d.ts +2 -5
- package/dist-esm/Behaviours.js +1 -1
- package/dist-esm/ClickAnalyticsPlugin.js +74 -50
- package/dist-esm/ClickAnalyticsPlugin.js.map +1 -1
- package/dist-esm/DataCollector.js +1 -1
- package/dist-esm/Enums.js +1 -1
- package/dist-esm/Interfaces/Datamodel.js +1 -1
- package/dist-esm/applicationinsights-clickanalytics-js.js +1 -1
- package/dist-esm/common/Utils.js +1 -1
- package/dist-esm/events/PageAction.js +128 -128
- package/dist-esm/events/PageAction.js.map +1 -1
- package/dist-esm/events/WebEvent.js +109 -94
- package/dist-esm/events/WebEvent.js.map +1 -1
- package/dist-esm/handlers/AutoCaptureHandler.js +85 -91
- package/dist-esm/handlers/AutoCaptureHandler.js.map +1 -1
- package/dist-esm/handlers/DomContentHandler.js +279 -280
- package/dist-esm/handlers/DomContentHandler.js.map +1 -1
- package/package.json +5 -5
- package/src/ClickAnalyticsPlugin.ts +91 -46
- package/src/Interfaces/Datamodel.ts +17 -18
- package/src/events/PageAction.ts +165 -134
- package/src/events/WebEvent.ts +147 -77
- package/src/handlers/AutoCaptureHandler.ts +88 -86
- package/src/handlers/DomContentHandler.ts +336 -310
- package/types/ClickAnalyticsPlugin.d.ts +1 -4
- package/types/Interfaces/Datamodel.d.ts +7 -6
- package/types/events/PageAction.d.ts +6 -6
- package/types/events/WebEvent.d.ts +17 -17
- package/types/handlers/AutoCaptureHandler.d.ts +2 -10
- package/types/handlers/DomContentHandler.d.ts +3 -50
- package/types/tsdoc-metadata.json +1 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.cjs.js.map +0 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.cjs.min.js +0 -6
- package/browser/ai.clck.2.8.0-beta.2203-10.cjs.min.js.map +0 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.gbl.js.map +0 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.gbl.min.js +0 -6
- package/browser/ai.clck.2.8.0-beta.2203-10.gbl.min.js.map +0 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.integrity.json +0 -66
- package/browser/ai.clck.2.8.0-beta.2203-10.js.map +0 -1
- package/browser/ai.clck.2.8.0-beta.2203-10.min.js +0 -6
- package/browser/ai.clck.2.8.0-beta.2203-10.min.js.map +0 -1
package/src/events/PageAction.ts
CHANGED
|
@@ -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";
|
|
8
|
+
import { ITelemetryItem, getPerformance, ICustomProperties, LoggingSeverity, objForEachKey, IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState } from "@microsoft/applicationinsights-core-js"
|
|
9
|
+
import { IClickAnalyticsConfiguration, IContentHandler, IPageActionOverrideValues, IPageActionTelemetry } from "../Interfaces/Datamodel";
|
|
9
10
|
import { extractFieldFromObject, bracketIt, isValueAssigned, extend, _ExtendedInternalMessageId } 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
|
+
_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
|
+
|
|
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
|
-
//
|
|
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,103 +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
|
-
|
|
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)) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
this.trackPageAction(pageActionEvent, pageActionProperties);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// capture performance data into PageTags
|
|
124
|
-
private _getTimeToClick() {
|
|
125
|
-
const perf = getPerformance();
|
|
126
|
-
if (perf && perf.timing) {
|
|
127
|
-
var isNavigationStart = perf.timing.navigationStart;
|
|
128
|
-
if (isNavigationStart && isNavigationStart !== 0) {
|
|
129
|
-
return new Date().getTime() - isNavigationStart;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return -1;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private _populateEventDataIfPresent(obj:any, property:any, value:any) {
|
|
136
|
-
if(isValueAssigned(value)) {
|
|
137
|
-
obj[property] = value;
|
|
138
|
-
}
|
|
192
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
139
193
|
}
|
|
140
|
-
|
|
141
|
-
private _sanitizePageActionEventContent(pageActionContent: any) {
|
|
142
|
-
if(pageActionContent) {
|
|
143
|
-
delete pageActionContent.id;
|
|
144
|
-
delete pageActionContent.parentid;
|
|
145
|
-
delete pageActionContent.parentname;
|
|
146
|
-
if(this._config && this._config.dataTags && isValueAssigned(this._config.dataTags.parentDataTag)) {
|
|
147
|
-
delete pageActionContent[this._config.dataTags.parentDataTag];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private _isUndefinedEvent(pageActionEvent: IPageActionTelemetry) {
|
|
153
|
-
if(this._config.dropInvalidEvents) {
|
|
154
|
-
if(pageActionEvent.name === strNotSpecified
|
|
155
|
-
&& pageActionEvent.parentId === strNotSpecified
|
|
156
|
-
&& pageActionEvent.content === "[{}]") {
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
194
|
}
|
package/src/events/WebEvent.ts
CHANGED
|
@@ -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(
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
52
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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,61 +185,16 @@ export class WebEvent {
|
|
|
70
185
|
* @param event - The event
|
|
71
186
|
*/
|
|
72
187
|
protected _setPageTags(event: IPageActionTelemetry, overrideValues: IOverrideValues) {
|
|
73
|
-
//
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
if (overrideValues && isValueAssigned(overrideValues.behavior)) {
|
|
100
|
-
behavior = overrideValues.behavior;
|
|
101
|
-
} else if (isValueAssigned(this._behaviorMetaTag)) {
|
|
102
|
-
// If behavior meta tag available
|
|
103
|
-
behavior = this._behaviorMetaTag;
|
|
104
|
-
}
|
|
105
|
-
return this._getValidBehavior(behavior);
|
|
192
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
193
|
+
return null;
|
|
106
194
|
}
|
|
107
195
|
|
|
108
196
|
protected _getValidBehavior(behavior: string | number): string | number {
|
|
109
|
-
|
|
197
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
198
|
+
return null;
|
|
110
199
|
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Get the specified metadata value from the collection
|
|
114
|
-
* If overrideValue is specified in the config that takes precedence.
|
|
115
|
-
* @param metaTags - Meta data.
|
|
116
|
-
* @param coreData - Coredata values from configuration.
|
|
117
|
-
* @param metaTagName - Name of the metaTag to get.
|
|
118
|
-
* @returns Meta data value
|
|
119
|
-
*/
|
|
120
|
-
private _getMetaData(metaTags: { [name: string]: string }, coreData: ICoreData, metaTagName: string): string {
|
|
121
|
-
if (coreData && coreData[metaTagName]) {
|
|
122
|
-
return coreData[metaTagName];
|
|
123
|
-
} else if (metaTags) {
|
|
124
|
-
return metaTags[metaTagName];
|
|
125
|
-
}
|
|
126
|
-
return "";
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
200
|
}
|