@microsoft/applicationinsights-analytics-js 3.0.0-beta.2303-10 → 3.0.0-beta.2304-07
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/es5/applicationinsights-analytics-js.cjs.js +5452 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.js +5456 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.integrity.json +66 -0
- package/browser/{applicationinsights-analytics-js.js → es5/applicationinsights-analytics-js.js} +921 -885
- package/browser/es5/applicationinsights-analytics-js.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.min.js.map +1 -0
- package/dist/{applicationinsights-analytics-js.js → es5/applicationinsights-analytics-js.js} +921 -885
- package/dist/es5/applicationinsights-analytics-js.js.map +1 -0
- package/dist/es5/applicationinsights-analytics-js.min.js +6 -0
- package/dist/es5/applicationinsights-analytics-js.min.js.map +1 -0
- package/{dist-esm → dist-es5}/JavaScriptSDK/AnalyticsPlugin.js +2 -2
- package/{dist-esm → dist-es5}/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Timing.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
- package/{dist-esm → dist-es5}/__DynamicConstants.js +1 -1
- package/{dist-esm → dist-es5}/applicationinsights-analytics-js.js +1 -1
- package/package.json +19 -18
- package/tsconfig.json +5 -4
- package/types/applicationinsights-analytics-js.d.ts +181 -2
- package/{dist/applicationinsights-analytics-js.d.ts → types/applicationinsights-analytics-js.namespaced.d.ts} +1 -1
- package/browser/applicationinsights-analytics-js.integrity.json +0 -26
- package/browser/applicationinsights-analytics-js.js.map +0 -1
- package/browser/applicationinsights-analytics-js.min.js +0 -6
- package/browser/applicationinsights-analytics-js.min.js.map +0 -1
- package/dist/applicationinsights-analytics-js.api.json +0 -1845
- package/dist/applicationinsights-analytics-js.api.md +0 -100
- package/dist/applicationinsights-analytics-js.js.map +0 -1
- package/dist/applicationinsights-analytics-js.min.js +0 -6
- package/dist/applicationinsights-analytics-js.min.js.map +0 -1
- package/dist/applicationinsights-analytics-js.rollup.d.ts +0 -182
- package/src/JavaScriptSDK/AnalyticsPlugin.ts +0 -1064
- package/src/JavaScriptSDK/Telemetry/PageViewManager.ts +0 -249
- package/src/JavaScriptSDK/Telemetry/PageViewPerformanceManager.ts +0 -221
- package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +0 -128
- package/src/JavaScriptSDK/Timing.ts +0 -46
- package/src/JavaScriptSDK.Interfaces/ITelemetryConfig.ts +0 -13
- package/src/__DynamicConstants.ts +0 -56
- package/src/applicationinsights-analytics-js.ts +0 -5
- package/types/JavaScriptSDK/AnalyticsPlugin.d.ts +0 -140
- package/types/JavaScriptSDK/Telemetry/PageViewManager.d.ts +0 -30
- package/types/JavaScriptSDK/Telemetry/PageViewPerformanceManager.d.ts +0 -23
- package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +0 -25
- package/types/JavaScriptSDK/Timing.d.ts +0 -18
- package/types/JavaScriptSDK.Interfaces/ITelemetryConfig.d.ts +0 -10
- package/types/__DynamicConstants.d.ts +0 -44
- package/types/tsdoc-metadata.json +0 -11
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Timing.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK.Interfaces/ITelemetryConfig.js.map +0 -0
- /package/{dist-esm → dist-es5}/__DynamicConstants.js.map +0 -0
- /package/{dist-esm → dist-es5}/applicationinsights-analytics-js.js.map +0 -0
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
5
|
-
import {
|
|
6
|
-
IPageViewPerformanceTelemetryInternal, IPageViewTelemetry, IPageViewTelemetryInternal, dateTimeUtilsDuration
|
|
7
|
-
} from "@microsoft/applicationinsights-common";
|
|
8
|
-
import {
|
|
9
|
-
IAppInsightsCore, IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState, _eInternalMessageId, _throwInternal,
|
|
10
|
-
arrForEach, dumpObj, eLoggingSeverity, getDocument, getExceptionName, getLocation, isNullOrUndefined
|
|
11
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
12
|
-
import { isWebWorker } from "@nevware21/ts-utils";
|
|
13
|
-
import { PageViewPerformanceManager } from "./PageViewPerformanceManager";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal interface to pass appInsights object to subcomponents without coupling
|
|
17
|
-
*/
|
|
18
|
-
export interface IAppInsightsInternal {
|
|
19
|
-
sendPageViewInternal(pageViewItem: IPageViewTelemetryInternal, properties?: Object, systemProperties?: Object): void;
|
|
20
|
-
sendPageViewPerformanceInternal(pageViewPerformance: IPageViewPerformanceTelemetryInternal, properties?: Object, systemProperties?: Object): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Class encapsulates sending page views and page view performance telemetry.
|
|
25
|
-
*/
|
|
26
|
-
export class PageViewManager {
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
appInsights: IAppInsightsInternal,
|
|
30
|
-
overridePageViewDuration: boolean,
|
|
31
|
-
core: IAppInsightsCore,
|
|
32
|
-
pageViewPerformanceManager: PageViewPerformanceManager) {
|
|
33
|
-
|
|
34
|
-
dynamicProto(PageViewManager, this, (_self) => {
|
|
35
|
-
let intervalHandle: any = null;
|
|
36
|
-
let itemQueue: Array<() => boolean> = [];
|
|
37
|
-
let pageViewPerformanceSent: boolean = false;
|
|
38
|
-
let _logger: IDiagnosticLogger;
|
|
39
|
-
|
|
40
|
-
if (core) {
|
|
41
|
-
_logger = core.logger;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _flushChannels(isAsync: boolean) {
|
|
45
|
-
if (core) {
|
|
46
|
-
core.flush(isAsync);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _addQueue(cb:() => boolean) {
|
|
51
|
-
itemQueue.push(cb);
|
|
52
|
-
|
|
53
|
-
if (!intervalHandle) {
|
|
54
|
-
intervalHandle = setInterval((() => {
|
|
55
|
-
let allItems = itemQueue.slice(0);
|
|
56
|
-
let doFlush = false;
|
|
57
|
-
itemQueue = [];
|
|
58
|
-
arrForEach(allItems, (item) => {
|
|
59
|
-
if (!item()) {
|
|
60
|
-
// Not processed so rescheduled
|
|
61
|
-
itemQueue.push(item);
|
|
62
|
-
} else {
|
|
63
|
-
doFlush = true;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (itemQueue.length === 0) {
|
|
68
|
-
clearInterval(intervalHandle);
|
|
69
|
-
intervalHandle = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (doFlush) {
|
|
73
|
-
// We process at least one item so flush the queue
|
|
74
|
-
_flushChannels(true);
|
|
75
|
-
}
|
|
76
|
-
}), 100);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_self.trackPageView = (pageView: IPageViewTelemetry, customProperties?: { [key: string]: any }) => {
|
|
81
|
-
let name = pageView.name;
|
|
82
|
-
if (isNullOrUndefined(name) || typeof name !== "string") {
|
|
83
|
-
let doc = getDocument();
|
|
84
|
-
name = pageView.name = doc && doc.title || "";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let uri = pageView.uri;
|
|
88
|
-
if (isNullOrUndefined(uri) || typeof uri !== "string") {
|
|
89
|
-
let location = getLocation();
|
|
90
|
-
uri = pageView.uri = location && location.href || "";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// case 1a. if performance timing is not supported by the browser, send the page view telemetry with the duration provided by the user. If the user
|
|
94
|
-
// do not provide the duration, set duration to undefined
|
|
95
|
-
// Also this is case 4
|
|
96
|
-
if (!pageViewPerformanceManager.isPerformanceTimingSupported()) {
|
|
97
|
-
appInsights.sendPageViewInternal(
|
|
98
|
-
pageView,
|
|
99
|
-
customProperties
|
|
100
|
-
);
|
|
101
|
-
_flushChannels(true);
|
|
102
|
-
|
|
103
|
-
if (!isWebWorker()) {
|
|
104
|
-
// no navigation timing (IE 8, iOS Safari 8.4, Opera Mini 8 - see http://caniuse.com/#feat=nav-timing)
|
|
105
|
-
_throwInternal(_logger,
|
|
106
|
-
eLoggingSeverity.WARNING,
|
|
107
|
-
_eInternalMessageId.NavigationTimingNotSupported,
|
|
108
|
-
"trackPageView: navigation timing API used for calculation of page duration is not supported in this browser. This page view will be collected without duration and timing info.");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let pageViewSent = false;
|
|
115
|
-
let customDuration: number;
|
|
116
|
-
|
|
117
|
-
// if the performance timing is supported by the browser, calculate the custom duration
|
|
118
|
-
const start = pageViewPerformanceManager.getPerformanceTiming().navigationStart;
|
|
119
|
-
if (start > 0) {
|
|
120
|
-
customDuration = dateTimeUtilsDuration(start, +new Date);
|
|
121
|
-
if (!pageViewPerformanceManager.shouldCollectDuration(customDuration)) {
|
|
122
|
-
customDuration = undefined;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// if the user has provided duration, send a page view telemetry with the provided duration. Otherwise, if
|
|
127
|
-
// overridePageViewDuration is set to true, send a page view telemetry with the custom duration calculated earlier
|
|
128
|
-
let duration;
|
|
129
|
-
if (!isNullOrUndefined(customProperties) &&
|
|
130
|
-
!isNullOrUndefined(customProperties.duration)) {
|
|
131
|
-
duration = customProperties.duration;
|
|
132
|
-
}
|
|
133
|
-
if (overridePageViewDuration || !isNaN(duration)) {
|
|
134
|
-
if (isNaN(duration)) {
|
|
135
|
-
// case 3
|
|
136
|
-
if (!customProperties) {
|
|
137
|
-
customProperties = {};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
customProperties.duration = customDuration;
|
|
141
|
-
}
|
|
142
|
-
// case 2
|
|
143
|
-
appInsights.sendPageViewInternal(
|
|
144
|
-
pageView,
|
|
145
|
-
customProperties
|
|
146
|
-
);
|
|
147
|
-
_flushChannels(true);
|
|
148
|
-
pageViewSent = true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// now try to send the page view performance telemetry
|
|
152
|
-
const maxDurationLimit = 60000;
|
|
153
|
-
if (!customProperties) {
|
|
154
|
-
customProperties = {};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Queue the event for processing
|
|
158
|
-
_addQueue(() => {
|
|
159
|
-
let processed = false;
|
|
160
|
-
try {
|
|
161
|
-
if (pageViewPerformanceManager.isPerformanceTimingDataReady()) {
|
|
162
|
-
processed = true;
|
|
163
|
-
const pageViewPerformance: IPageViewPerformanceTelemetryInternal = {
|
|
164
|
-
name,
|
|
165
|
-
uri
|
|
166
|
-
};
|
|
167
|
-
pageViewPerformanceManager.populatePageViewPerformanceEvent(pageViewPerformance);
|
|
168
|
-
|
|
169
|
-
if (!pageViewPerformance.isValid && !pageViewSent) {
|
|
170
|
-
// If navigation timing gives invalid numbers, then go back to "override page view duration" mode.
|
|
171
|
-
// That's the best value we can get that makes sense.
|
|
172
|
-
customProperties.duration = customDuration;
|
|
173
|
-
appInsights.sendPageViewInternal(
|
|
174
|
-
pageView,
|
|
175
|
-
customProperties);
|
|
176
|
-
} else {
|
|
177
|
-
if (!pageViewSent) {
|
|
178
|
-
customProperties.duration = pageViewPerformance.durationMs;
|
|
179
|
-
appInsights.sendPageViewInternal(
|
|
180
|
-
pageView,
|
|
181
|
-
customProperties);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (!pageViewPerformanceSent) {
|
|
185
|
-
appInsights.sendPageViewPerformanceInternal(pageViewPerformance, customProperties);
|
|
186
|
-
pageViewPerformanceSent = true;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} else if (start > 0 && dateTimeUtilsDuration(start, +new Date) > maxDurationLimit) {
|
|
190
|
-
// if performance timings are not ready but we exceeded the maximum duration limit, just log a page view telemetry
|
|
191
|
-
// with the maximum duration limit. Otherwise, keep waiting until performance timings are ready
|
|
192
|
-
processed = true;
|
|
193
|
-
if (!pageViewSent) {
|
|
194
|
-
customProperties.duration = maxDurationLimit;
|
|
195
|
-
appInsights.sendPageViewInternal(
|
|
196
|
-
pageView,
|
|
197
|
-
customProperties
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
} catch (e) {
|
|
202
|
-
_throwInternal(_logger,
|
|
203
|
-
eLoggingSeverity.CRITICAL,
|
|
204
|
-
_eInternalMessageId.TrackPVFailedCalc,
|
|
205
|
-
"trackPageView failed on page load calculation: " + getExceptionName(e),
|
|
206
|
-
{ exception: dumpObj(e) });
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return processed;
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
_self.teardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => {
|
|
214
|
-
if (intervalHandle) {
|
|
215
|
-
clearInterval(intervalHandle);
|
|
216
|
-
intervalHandle = null;
|
|
217
|
-
|
|
218
|
-
let allItems = itemQueue.slice(0);
|
|
219
|
-
let doFlush = false;
|
|
220
|
-
itemQueue = [];
|
|
221
|
-
arrForEach(allItems, (item) => {
|
|
222
|
-
if (item()) {
|
|
223
|
-
doFlush = true;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Currently supported cases:
|
|
234
|
-
* 1) (default case) track page view called with default parameters, overridePageViewDuration = false. Page view is sent with page view performance when navigation timing data is available.
|
|
235
|
-
* a. If navigation timing is not supported then page view is sent right away with undefined duration. Page view performance is not sent.
|
|
236
|
-
* 2) overridePageViewDuration = true, custom duration provided. Custom duration is used, page view sends right away.
|
|
237
|
-
* 3) overridePageViewDuration = true, custom duration NOT provided. Page view is sent right away, duration is time spent from page load till now (or undefined if navigation timing is not supported).
|
|
238
|
-
* 4) overridePageViewDuration = false, custom duration is provided. Page view is sent right away with custom duration.
|
|
239
|
-
*
|
|
240
|
-
* In all cases page view performance is sent once (only for the 1st call of trackPageView), or not sent if navigation timing is not supported.
|
|
241
|
-
*/
|
|
242
|
-
public trackPageView(pageView: IPageViewTelemetry, customProperties?: { [key: string]: any }) {
|
|
243
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) {
|
|
247
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
248
|
-
}
|
|
249
|
-
}
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
5
|
-
import { IPageViewPerformanceTelemetryInternal, dateTimeUtilsDuration, msToTimeSpan } from "@microsoft/applicationinsights-common";
|
|
6
|
-
import {
|
|
7
|
-
IAppInsightsCore, IDiagnosticLogger, _eInternalMessageId, _throwInternal, eLoggingSeverity, getNavigator, getPerformance, safeGetLogger
|
|
8
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
9
|
-
import { strIndexOf } from "@nevware21/ts-utils";
|
|
10
|
-
|
|
11
|
-
const MAX_DURATION_ALLOWED = 3600000; // 1h
|
|
12
|
-
const botAgentNames = ["googlebot", "adsbot-google", "apis-google", "mediapartners-google"];
|
|
13
|
-
|
|
14
|
-
function _isPerformanceTimingSupported() {
|
|
15
|
-
let perf = getPerformance();
|
|
16
|
-
return perf && !!perf.timing;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _isPerformanceNavigationTimingSupported() {
|
|
20
|
-
let perf = getPerformance();
|
|
21
|
-
return perf && perf.getEntriesByType && perf.getEntriesByType("navigation").length > 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function _isPerformanceTimingDataReady() {
|
|
25
|
-
let perf = getPerformance();
|
|
26
|
-
const timing = perf ? perf.timing : 0;
|
|
27
|
-
|
|
28
|
-
return timing
|
|
29
|
-
&& timing.domainLookupStart > 0
|
|
30
|
-
&& timing.navigationStart > 0
|
|
31
|
-
&& timing.responseStart > 0
|
|
32
|
-
&& timing.requestStart > 0
|
|
33
|
-
&& timing.loadEventEnd > 0
|
|
34
|
-
&& timing.responseEnd > 0
|
|
35
|
-
&& timing.connectEnd > 0
|
|
36
|
-
&& timing.domLoading > 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _getPerformanceTiming(): PerformanceTiming | null {
|
|
40
|
-
if (_isPerformanceTimingSupported()) {
|
|
41
|
-
return getPerformance().timing;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function _getPerformanceNavigationTiming(): PerformanceNavigationTiming | null {
|
|
48
|
-
if (_isPerformanceNavigationTimingSupported()) {
|
|
49
|
-
return getPerformance().getEntriesByType("navigation")[0] as PerformanceNavigationTiming;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* This method tells if given durations should be excluded from collection.
|
|
57
|
-
*/
|
|
58
|
-
function _shouldCollectDuration(...durations: number[]): boolean {
|
|
59
|
-
var _navigator = getNavigator() || {} as any;
|
|
60
|
-
// a full list of Google crawlers user agent strings - https://support.google.com/webmasters/answer/1061943?hl=en
|
|
61
|
-
const userAgent = _navigator.userAgent;
|
|
62
|
-
let isGoogleBot = false;
|
|
63
|
-
|
|
64
|
-
if (userAgent) {
|
|
65
|
-
for (let i = 0; i < botAgentNames.length; i++) {
|
|
66
|
-
isGoogleBot = isGoogleBot || strIndexOf(userAgent.toLowerCase(), botAgentNames[i]) !== -1;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (isGoogleBot) {
|
|
71
|
-
// Don't report durations for GoogleBot, it is returning invalid values in performance.timing API.
|
|
72
|
-
return false;
|
|
73
|
-
} else {
|
|
74
|
-
// for other page views, don't report if it's outside of a reasonable range
|
|
75
|
-
for (let i = 0; i < durations.length; i++) {
|
|
76
|
-
if (durations[i] < 0 || durations[i] >= MAX_DURATION_ALLOWED) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Class encapsulates sending page view performance telemetry.
|
|
87
|
-
*/
|
|
88
|
-
export class PageViewPerformanceManager {
|
|
89
|
-
|
|
90
|
-
constructor(core: IAppInsightsCore) {
|
|
91
|
-
let _logger: IDiagnosticLogger = safeGetLogger(core);
|
|
92
|
-
|
|
93
|
-
dynamicProto(PageViewPerformanceManager, this, (_self) => {
|
|
94
|
-
_self.populatePageViewPerformanceEvent = (pageViewPerformance: IPageViewPerformanceTelemetryInternal): void => {
|
|
95
|
-
pageViewPerformance.isValid = false;
|
|
96
|
-
|
|
97
|
-
/*
|
|
98
|
-
* http://www.w3.org/TR/navigation-timing/#processing-model
|
|
99
|
-
* |-navigationStart
|
|
100
|
-
* | |-connectEnd
|
|
101
|
-
* | ||-requestStart
|
|
102
|
-
* | || |-responseStart
|
|
103
|
-
* | || | |-responseEnd
|
|
104
|
-
* | || | |
|
|
105
|
-
* | || | | |-loadEventEnd
|
|
106
|
-
* |---network---||---request---|---response---|---dom---|
|
|
107
|
-
* |--------------------------total----------------------|
|
|
108
|
-
*
|
|
109
|
-
* total = The difference between the load event of the current document is completed and the first recorded timestamp of the performance entry : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#duration
|
|
110
|
-
* network = Redirect time + App Cache + DNS lookup time + TCP connection time
|
|
111
|
-
* request = Request time : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#request_time
|
|
112
|
-
* response = Response time
|
|
113
|
-
* dom = Document load time : https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
|
|
114
|
-
* = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing
|
|
115
|
-
* + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading
|
|
116
|
-
*/
|
|
117
|
-
const navigationTiming = _getPerformanceNavigationTiming();
|
|
118
|
-
const timing = _getPerformanceTiming();
|
|
119
|
-
let total = 0;
|
|
120
|
-
let network = 0;
|
|
121
|
-
let request = 0;
|
|
122
|
-
let response = 0;
|
|
123
|
-
let dom = 0;
|
|
124
|
-
|
|
125
|
-
if (navigationTiming || timing) {
|
|
126
|
-
if (navigationTiming) {
|
|
127
|
-
total = navigationTiming.duration;
|
|
128
|
-
/**
|
|
129
|
-
* support both cases:
|
|
130
|
-
* - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
|
131
|
-
* - for older browsers where the startTime is not zero
|
|
132
|
-
*/
|
|
133
|
-
network = navigationTiming.startTime === 0 ? navigationTiming.connectEnd : dateTimeUtilsDuration(navigationTiming.startTime, navigationTiming.connectEnd);
|
|
134
|
-
request = dateTimeUtilsDuration(navigationTiming.requestStart, navigationTiming.responseStart);
|
|
135
|
-
response = dateTimeUtilsDuration(navigationTiming.responseStart, navigationTiming.responseEnd);
|
|
136
|
-
dom = dateTimeUtilsDuration(navigationTiming.responseEnd, navigationTiming.loadEventEnd);
|
|
137
|
-
} else {
|
|
138
|
-
total = dateTimeUtilsDuration(timing.navigationStart, timing.loadEventEnd);
|
|
139
|
-
network = dateTimeUtilsDuration(timing.navigationStart, timing.connectEnd);
|
|
140
|
-
request = dateTimeUtilsDuration(timing.requestStart, timing.responseStart);
|
|
141
|
-
response = dateTimeUtilsDuration(timing.responseStart, timing.responseEnd);
|
|
142
|
-
dom = dateTimeUtilsDuration(timing.responseEnd, timing.loadEventEnd);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (total === 0) {
|
|
146
|
-
_throwInternal(_logger,
|
|
147
|
-
eLoggingSeverity.WARNING,
|
|
148
|
-
_eInternalMessageId.ErrorPVCalc,
|
|
149
|
-
"error calculating page view performance.",
|
|
150
|
-
{ total, network, request, response, dom });
|
|
151
|
-
|
|
152
|
-
} else if (!this.shouldCollectDuration(total, network, request, response, dom)) {
|
|
153
|
-
_throwInternal(_logger,
|
|
154
|
-
eLoggingSeverity.WARNING,
|
|
155
|
-
_eInternalMessageId.InvalidDurationValue,
|
|
156
|
-
"Invalid page load duration value. Browser perf data won't be sent.",
|
|
157
|
-
{ total, network, request, response, dom });
|
|
158
|
-
|
|
159
|
-
} else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {
|
|
160
|
-
// some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT
|
|
161
|
-
// in this case, don't report client performance from this page
|
|
162
|
-
_throwInternal(_logger,
|
|
163
|
-
eLoggingSeverity.WARNING,
|
|
164
|
-
_eInternalMessageId.ClientPerformanceMathError,
|
|
165
|
-
"client performance math error.",
|
|
166
|
-
{ total, network, request, response, dom });
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
pageViewPerformance.durationMs = total;
|
|
170
|
-
// // convert to timespans
|
|
171
|
-
pageViewPerformance.perfTotal = pageViewPerformance.duration = msToTimeSpan(total);
|
|
172
|
-
pageViewPerformance.networkConnect = msToTimeSpan(network);
|
|
173
|
-
pageViewPerformance.sentRequest = msToTimeSpan(request);
|
|
174
|
-
pageViewPerformance.receivedResponse = msToTimeSpan(response);
|
|
175
|
-
pageViewPerformance.domProcessing = msToTimeSpan(dom);
|
|
176
|
-
pageViewPerformance.isValid = true;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
_self.getPerformanceTiming = _getPerformanceTiming;
|
|
182
|
-
_self.isPerformanceTimingSupported = _isPerformanceTimingSupported;
|
|
183
|
-
_self.isPerformanceTimingDataReady = _isPerformanceTimingDataReady;
|
|
184
|
-
_self.shouldCollectDuration = _shouldCollectDuration;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public populatePageViewPerformanceEvent(pageViewPerformance: IPageViewPerformanceTelemetryInternal): void {
|
|
189
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public getPerformanceTiming(): PerformanceTiming | null {
|
|
193
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Returns true is window performance timing API is supported, false otherwise.
|
|
199
|
-
*/
|
|
200
|
-
public isPerformanceTimingSupported() {
|
|
201
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* As page loads different parts of performance timing numbers get set. When all of them are set we can report it.
|
|
207
|
-
* Returns true if ready, false otherwise.
|
|
208
|
-
*/
|
|
209
|
-
public isPerformanceTimingDataReady() {
|
|
210
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* This method tells if given durations should be excluded from collection.
|
|
216
|
-
*/
|
|
217
|
-
public shouldCollectDuration(...durations: number[]): boolean {
|
|
218
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
5
|
-
import {
|
|
6
|
-
utlCanUseSessionStorage, utlGetSessionStorage, utlRemoveSessionStorage, utlSetSessionStorage
|
|
7
|
-
} from "@microsoft/applicationinsights-common";
|
|
8
|
-
import {
|
|
9
|
-
IDiagnosticLogger, _warnToConsole, dateNow, dumpObj, getJSON, hasJSON, throwError
|
|
10
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
11
|
-
import { objDefine } from "@nevware21/ts-utils";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Used to track page visit durations
|
|
15
|
-
*/
|
|
16
|
-
export class PageVisitTimeManager {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new instance of PageVisitTimeManager
|
|
20
|
-
* @param pageVisitTimeTrackingHandler - Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)
|
|
21
|
-
* @returns {}
|
|
22
|
-
*/
|
|
23
|
-
constructor(logger: IDiagnosticLogger, pageVisitTimeTrackingHandler: (pageName: string, pageUrl: string, pageVisitTime: number) => void) {
|
|
24
|
-
let prevPageVisitDataKeyName: string = "prevPageVisitData";
|
|
25
|
-
|
|
26
|
-
dynamicProto(PageVisitTimeManager, this, (_self) => {
|
|
27
|
-
_self.trackPreviousPageVisit = (currentPageName: string, currentPageUrl: string) => {
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
// Restart timer for new page view
|
|
31
|
-
const prevPageVisitTimeData = restartPageVisitTimer(currentPageName, currentPageUrl);
|
|
32
|
-
|
|
33
|
-
// If there was a page already being timed, track the visit time for it now.
|
|
34
|
-
if (prevPageVisitTimeData) {
|
|
35
|
-
pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);
|
|
36
|
-
}
|
|
37
|
-
} catch (e) {
|
|
38
|
-
_warnToConsole(logger, "Auto track page visit time failed, metric will not be collected: " + dumpObj(e));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Stops timing of current page (if exists) and starts timing for duration of visit to pageName
|
|
44
|
-
* @param pageName - Name of page to begin timing visit duration
|
|
45
|
-
* @returns {PageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.
|
|
46
|
-
*/
|
|
47
|
-
function restartPageVisitTimer(pageName: string, pageUrl: string) {
|
|
48
|
-
let prevPageVisitData: PageVisitData = null;
|
|
49
|
-
try {
|
|
50
|
-
prevPageVisitData = stopPageVisitTimer();
|
|
51
|
-
if (utlCanUseSessionStorage()) {
|
|
52
|
-
if (utlGetSessionStorage(logger, prevPageVisitDataKeyName) != null) {
|
|
53
|
-
throwError("Cannot call startPageVisit consecutively without first calling stopPageVisit");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const currPageVisitDataStr = getJSON().stringify(new PageVisitData(pageName, pageUrl));
|
|
57
|
-
utlSetSessionStorage(logger, prevPageVisitDataKeyName, currPageVisitDataStr);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
} catch (e) {
|
|
61
|
-
_warnToConsole(logger, "Call to restart failed: " + dumpObj(e));
|
|
62
|
-
prevPageVisitData = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return prevPageVisitData;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Stops timing of current page, if exists.
|
|
70
|
-
* @returns {PageVisitData} Page visit data (including duration) of pageName from call to start, if exists. Null if not.
|
|
71
|
-
*/
|
|
72
|
-
function stopPageVisitTimer() {
|
|
73
|
-
let prevPageVisitData: PageVisitData = null;
|
|
74
|
-
try {
|
|
75
|
-
if (utlCanUseSessionStorage()) {
|
|
76
|
-
|
|
77
|
-
// Define end time of page's visit
|
|
78
|
-
const pageVisitEndTime = dateNow();
|
|
79
|
-
|
|
80
|
-
// Try to retrieve page name and start time from session storage
|
|
81
|
-
const pageVisitDataJsonStr = utlGetSessionStorage(logger, prevPageVisitDataKeyName);
|
|
82
|
-
if (pageVisitDataJsonStr && hasJSON()) {
|
|
83
|
-
|
|
84
|
-
// if previous page data exists, set end time of visit
|
|
85
|
-
prevPageVisitData = getJSON().parse(pageVisitDataJsonStr);
|
|
86
|
-
prevPageVisitData.pageVisitTime = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;
|
|
87
|
-
|
|
88
|
-
// Remove data from storage since we already used it
|
|
89
|
-
utlRemoveSessionStorage(logger, prevPageVisitDataKeyName);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} catch (e) {
|
|
93
|
-
_warnToConsole(logger, "Stop page visit timer failed: " + dumpObj(e));
|
|
94
|
-
prevPageVisitData = null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return prevPageVisitData;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// For backward compatibility
|
|
101
|
-
objDefine<any>(_self, "_logger", { g: () => logger });
|
|
102
|
-
objDefine<any>(_self, "pageVisitTimeTrackingHandler", { g: () => pageVisitTimeTrackingHandler});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time
|
|
108
|
-
* @param currentPageName - Name of page to begin timing for visit duration
|
|
109
|
-
* @param currentPageUrl - Url of page to begin timing for visit duration
|
|
110
|
-
*/
|
|
111
|
-
public trackPreviousPageVisit(currentPageName: string, currentPageUrl: string): void {
|
|
112
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export class PageVisitData {
|
|
117
|
-
|
|
118
|
-
public pageName: string;
|
|
119
|
-
public pageUrl: string;
|
|
120
|
-
public pageVisitStartTime: number;
|
|
121
|
-
public pageVisitTime: number;
|
|
122
|
-
|
|
123
|
-
constructor(pageName: string, pageUrl: string) {
|
|
124
|
-
this.pageVisitStartTime = dateNow();
|
|
125
|
-
this.pageName = pageName;
|
|
126
|
-
this.pageUrl = pageUrl;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { dateTimeUtilsDuration } from "@microsoft/applicationinsights-common";
|
|
5
|
-
import { IDiagnosticLogger, eLoggingSeverity, _eInternalMessageId, _throwInternal } from "@microsoft/applicationinsights-core-js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Used to record timed events and page views.
|
|
9
|
-
*/
|
|
10
|
-
export class Timing {
|
|
11
|
-
|
|
12
|
-
public action: (name?: string, url?: string, duration?: number, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => void;
|
|
13
|
-
public start: (name: string) => void;
|
|
14
|
-
public stop: (name: string, url: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => void;
|
|
15
|
-
|
|
16
|
-
constructor(logger: IDiagnosticLogger, name: string) {
|
|
17
|
-
let _self = this;
|
|
18
|
-
let _events: { [key: string]: number; } = {}
|
|
19
|
-
|
|
20
|
-
_self.start = (name: string) => {
|
|
21
|
-
if (typeof _events[name] !== "undefined") {
|
|
22
|
-
_throwInternal(logger,
|
|
23
|
-
eLoggingSeverity.WARNING, _eInternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.",
|
|
24
|
-
{ name, key: name }, true);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_events[name] = +new Date;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
_self.stop = (name: string, url: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => {
|
|
31
|
-
const start = _events[name];
|
|
32
|
-
if (isNaN(start)) {
|
|
33
|
-
_throwInternal(logger,
|
|
34
|
-
eLoggingSeverity.WARNING, _eInternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.",
|
|
35
|
-
{ name, key: name }, true);
|
|
36
|
-
} else {
|
|
37
|
-
const end = +new Date;
|
|
38
|
-
const duration = dateTimeUtilsDuration(start, end);
|
|
39
|
-
_self.action(name, url, duration, properties, measurements);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
delete _events[name];
|
|
43
|
-
_events[name] = undefined;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
export interface ITelemetryConfig {
|
|
5
|
-
instrumentationKey: () => string;
|
|
6
|
-
accountId: () => string;
|
|
7
|
-
sessionRenewalMs: () => number;
|
|
8
|
-
sampleRate: () => number;
|
|
9
|
-
sessionExpirationMs: () => number;
|
|
10
|
-
sdkExtension: () => string;
|
|
11
|
-
isBrowserLinkTrackingEnabled: () => boolean;
|
|
12
|
-
appId: () => string;
|
|
13
|
-
}
|