@microsoft/applicationinsights-analytics-js 2.8.5-nightly.2206-02 → 2.8.5-nightly.2206-06
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-analytics-js.integrity.json +9 -9
- package/browser/applicationinsights-analytics-js.js +1419 -1239
- package/browser/applicationinsights-analytics-js.js.map +1 -1
- package/browser/applicationinsights-analytics-js.min.js +2 -2
- package/browser/applicationinsights-analytics-js.min.js.map +1 -1
- package/dist/applicationinsights-analytics-js.api.json +64 -27
- package/dist/applicationinsights-analytics-js.d.ts +1 -1
- package/dist/applicationinsights-analytics-js.js +1419 -1239
- package/dist/applicationinsights-analytics-js.js.map +1 -1
- package/dist/applicationinsights-analytics-js.min.js +2 -2
- package/dist/applicationinsights-analytics-js.min.js.map +1 -1
- package/dist/applicationinsights-analytics-js.rollup.d.ts +1 -1
- package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js +115 -112
- package/dist-esm/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js +29 -23
- package/dist-esm/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +159 -153
- package/dist-esm/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +90 -87
- package/dist-esm/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Timing.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
- package/dist-esm/__DynamicConstants.js +61 -0
- package/dist-esm/__DynamicConstants.js.map +1 -0
- package/dist-esm/applicationinsights-analytics-js.js +1 -1
- package/package.json +9 -6
- package/src/JavaScriptSDK/AnalyticsPlugin.ts +49 -51
- package/src/JavaScriptSDK/Telemetry/PageViewManager.ts +18 -18
- package/src/JavaScriptSDK/Telemetry/PageViewPerformanceManager.ts +183 -160
- package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +108 -100
- package/src/__DynamicConstants.ts +59 -0
- package/types/JavaScriptSDK/AnalyticsPlugin.d.ts +5 -5
- package/types/JavaScriptSDK/Telemetry/PageViewManager.d.ts +1 -1
- package/types/JavaScriptSDK/Telemetry/PageViewPerformanceManager.d.ts +1 -8
- package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +0 -20
- package/types/__DynamicConstants.d.ts +47 -0
- package/types/tsdoc-metadata.json +1 -1
|
@@ -1,169 +1,175 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Web Analytics, 2.8.5-nightly.2206-
|
|
2
|
+
* Application Insights JavaScript SDK - Web Analytics, 2.8.5-nightly.2206-06
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
7
8
|
import { dateTimeUtilsDuration, msToTimeSpan } from "@microsoft/applicationinsights-common";
|
|
8
|
-
import { getNavigator, getPerformance,
|
|
9
|
+
import { _throwInternal, getNavigator, getPerformance, safeGetLogger } from "@microsoft/applicationinsights-core-js";
|
|
10
|
+
import { _DYN_CONNECT_END, _DYN_DURATION, _DYN_GET_ENTRIES_BY_TYPE, _DYN_GET_PERFORMANCE_TIMI17, _DYN_IS_PERFORMANCE_TIMIN16, _DYN_IS_PERFORMANCE_TIMIN19, _DYN_LENGTH, _DYN_LOAD_EVENT_END, _DYN_NAVIGATION_START, _DYN_POPULATE_PAGE_VIEW_P12, _DYN_REQUEST_START, _DYN_RESPONSE_END, _DYN_RESPONSE_START, _DYN_SHOULD_COLLECT_DURAT18 } from "../../__DynamicConstants";
|
|
11
|
+
var MAX_DURATION_ALLOWED = 3600000; // 1h
|
|
12
|
+
var botAgentNames = ["googlebot", "adsbot-google", "apis-google", "mediapartners-google"];
|
|
13
|
+
function _isPerformanceTimingSupported() {
|
|
14
|
+
var perf = getPerformance();
|
|
15
|
+
return perf && !!perf.timing;
|
|
16
|
+
}
|
|
17
|
+
function _isPerformanceNavigationTimingSupported() {
|
|
18
|
+
var perf = getPerformance();
|
|
19
|
+
return perf && perf.getEntriesByType && perf.getEntriesByType("navigation")[_DYN_LENGTH /* @min:%2elength */] > 0;
|
|
20
|
+
}
|
|
21
|
+
function _isPerformanceTimingDataReady() {
|
|
22
|
+
var perf = getPerformance();
|
|
23
|
+
var timing = perf ? perf.timing : 0;
|
|
24
|
+
return timing
|
|
25
|
+
&& timing.domainLookupStart > 0
|
|
26
|
+
&& timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */] > 0
|
|
27
|
+
&& timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */] > 0
|
|
28
|
+
&& timing[_DYN_REQUEST_START /* @min:%2erequestStart */] > 0
|
|
29
|
+
&& timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */] > 0
|
|
30
|
+
&& timing[_DYN_RESPONSE_END /* @min:%2eresponseEnd */] > 0
|
|
31
|
+
&& timing[_DYN_CONNECT_END /* @min:%2econnectEnd */] > 0
|
|
32
|
+
&& timing.domLoading > 0;
|
|
33
|
+
}
|
|
34
|
+
function _getPerformanceTiming() {
|
|
35
|
+
if (_isPerformanceTimingSupported()) {
|
|
36
|
+
return getPerformance().timing;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function _getPerformanceNavigationTiming() {
|
|
41
|
+
if (_isPerformanceNavigationTimingSupported()) {
|
|
42
|
+
return getPerformance()[_DYN_GET_ENTRIES_BY_TYPE /* @min:%2egetEntriesByType */]("navigation")[0];
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This method tells if given durations should be excluded from collection.
|
|
48
|
+
*/
|
|
49
|
+
function _shouldCollectDuration() {
|
|
50
|
+
var durations = [];
|
|
51
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
52
|
+
durations[_i] = arguments[_i];
|
|
53
|
+
}
|
|
54
|
+
var _navigator = getNavigator() || {};
|
|
55
|
+
// a full list of Google crawlers user agent strings - https://support.google.com/webmasters/answer/1061943?hl=en
|
|
56
|
+
var userAgent = _navigator.userAgent;
|
|
57
|
+
var isGoogleBot = false;
|
|
58
|
+
if (userAgent) {
|
|
59
|
+
for (var i = 0; i < botAgentNames[_DYN_LENGTH /* @min:%2elength */]; i++) {
|
|
60
|
+
isGoogleBot = isGoogleBot || userAgent.toLowerCase().indexOf(botAgentNames[i]) !== -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (isGoogleBot) {
|
|
64
|
+
// Don't report durations for GoogleBot, it is returning invalid values in performance.timing API.
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// for other page views, don't report if it's outside of a reasonable range
|
|
69
|
+
for (var i = 0; i < durations[_DYN_LENGTH /* @min:%2elength */]; i++) {
|
|
70
|
+
if (durations[i] < 0 || durations[i] >= MAX_DURATION_ALLOWED) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
9
77
|
/**
|
|
10
78
|
* Class encapsulates sending page view performance telemetry.
|
|
11
79
|
*/
|
|
12
80
|
var PageViewPerformanceManager = /** @class */ (function () {
|
|
13
81
|
function PageViewPerformanceManager(core) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing
|
|
39
|
-
* + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading
|
|
40
|
-
*/
|
|
41
|
-
var navigationTiming = this.getPerformanceNavigationTiming();
|
|
42
|
-
var timing = this.getPerformanceTiming();
|
|
43
|
-
var total = 0;
|
|
44
|
-
var network = 0;
|
|
45
|
-
var request = 0;
|
|
46
|
-
var response = 0;
|
|
47
|
-
var dom = 0;
|
|
48
|
-
if (navigationTiming || timing) {
|
|
49
|
-
if (navigationTiming) {
|
|
50
|
-
total = navigationTiming.duration;
|
|
51
|
-
/**
|
|
52
|
-
* support both cases:
|
|
53
|
-
* - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
|
54
|
-
* - for older browsers where the startTime is not zero
|
|
82
|
+
var _this = this;
|
|
83
|
+
var _logger = safeGetLogger(core);
|
|
84
|
+
dynamicProto(PageViewPerformanceManager, this, function (_self) {
|
|
85
|
+
_self[_DYN_POPULATE_PAGE_VIEW_P12 /* @min:%2epopulatePageViewPerformanceEvent */] = function (pageViewPerformance) {
|
|
86
|
+
pageViewPerformance.isValid = false;
|
|
87
|
+
/*
|
|
88
|
+
* http://www.w3.org/TR/navigation-timing/#processing-model
|
|
89
|
+
* |-navigationStart
|
|
90
|
+
* | |-connectEnd
|
|
91
|
+
* | ||-requestStart
|
|
92
|
+
* | || |-responseStart
|
|
93
|
+
* | || | |-responseEnd
|
|
94
|
+
* | || | |
|
|
95
|
+
* | || | | |-loadEventEnd
|
|
96
|
+
* |---network---||---request---|---response---|---dom---|
|
|
97
|
+
* |--------------------------total----------------------|
|
|
98
|
+
*
|
|
99
|
+
* 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
|
|
100
|
+
* network = Redirect time + App Cache + DNS lookup time + TCP connection time
|
|
101
|
+
* request = Request time : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#request_time
|
|
102
|
+
* response = Response time
|
|
103
|
+
* dom = Document load time : https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
|
|
104
|
+
* = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing
|
|
105
|
+
* + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading
|
|
55
106
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Returns true is window PerformanceNavigationTiming API is supported, false otherwise.
|
|
106
|
-
*/
|
|
107
|
-
PageViewPerformanceManager.prototype.isPerformanceNavigationTimingSupported = function () {
|
|
108
|
-
var perf = getPerformance();
|
|
109
|
-
return perf && perf.getEntriesByType && perf.getEntriesByType("navigation").length > 0;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Returns true is window performance timing API is supported, false otherwise.
|
|
113
|
-
*/
|
|
114
|
-
PageViewPerformanceManager.prototype.isPerformanceTimingSupported = function () {
|
|
115
|
-
var perf = getPerformance();
|
|
116
|
-
return perf && perf.timing;
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* As page loads different parts of performance timing numbers get set. When all of them are set we can report it.
|
|
120
|
-
* Returns true if ready, false otherwise.
|
|
121
|
-
*/
|
|
122
|
-
PageViewPerformanceManager.prototype.isPerformanceTimingDataReady = function () {
|
|
123
|
-
var perf = getPerformance();
|
|
124
|
-
var timing = perf ? perf.timing : 0;
|
|
125
|
-
return timing
|
|
126
|
-
&& timing.domainLookupStart > 0
|
|
127
|
-
&& timing.navigationStart > 0
|
|
128
|
-
&& timing.responseStart > 0
|
|
129
|
-
&& timing.requestStart > 0
|
|
130
|
-
&& timing.loadEventEnd > 0
|
|
131
|
-
&& timing.responseEnd > 0
|
|
132
|
-
&& timing.connectEnd > 0
|
|
133
|
-
&& timing.domLoading > 0;
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* This method tells if given durations should be excluded from collection.
|
|
137
|
-
*/
|
|
138
|
-
PageViewPerformanceManager.prototype.shouldCollectDuration = function () {
|
|
139
|
-
var durations = [];
|
|
140
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
141
|
-
durations[_i] = arguments[_i];
|
|
142
|
-
}
|
|
143
|
-
var _navigator = getNavigator() || {};
|
|
144
|
-
// a full list of Google crawlers user agent strings - https://support.google.com/webmasters/answer/1061943?hl=en
|
|
145
|
-
var botAgentNames = ["googlebot", "adsbot-google", "apis-google", "mediapartners-google"];
|
|
146
|
-
var userAgent = _navigator.userAgent;
|
|
147
|
-
var isGoogleBot = false;
|
|
148
|
-
if (userAgent) {
|
|
149
|
-
for (var i = 0; i < botAgentNames.length; i++) {
|
|
150
|
-
isGoogleBot = isGoogleBot || userAgent.toLowerCase().indexOf(botAgentNames[i]) !== -1;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (isGoogleBot) {
|
|
154
|
-
// Don't report durations for GoogleBot, it is returning invalid values in performance.timing API.
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// for other page views, don't report if it's outside of a reasonable range
|
|
159
|
-
for (var i = 0; i < durations.length; i++) {
|
|
160
|
-
if (durations[i] < 0 || durations[i] >= this.MAX_DURATION_ALLOWED) {
|
|
161
|
-
return false;
|
|
107
|
+
var navigationTiming = _getPerformanceNavigationTiming();
|
|
108
|
+
var timing = _getPerformanceTiming();
|
|
109
|
+
var total = 0;
|
|
110
|
+
var network = 0;
|
|
111
|
+
var request = 0;
|
|
112
|
+
var response = 0;
|
|
113
|
+
var dom = 0;
|
|
114
|
+
if (navigationTiming || timing) {
|
|
115
|
+
if (navigationTiming) {
|
|
116
|
+
total = navigationTiming[_DYN_DURATION /* @min:%2eduration */];
|
|
117
|
+
/**
|
|
118
|
+
* support both cases:
|
|
119
|
+
* - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
|
120
|
+
* - for older browsers where the startTime is not zero
|
|
121
|
+
*/
|
|
122
|
+
network = navigationTiming.startTime === 0 ? navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */] : dateTimeUtilsDuration(navigationTiming.startTime, navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */]);
|
|
123
|
+
request = dateTimeUtilsDuration(navigationTiming.requestStart, navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);
|
|
124
|
+
response = dateTimeUtilsDuration(navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */], navigationTiming[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);
|
|
125
|
+
dom = dateTimeUtilsDuration(navigationTiming.responseEnd, navigationTiming[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
total = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
129
|
+
network = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_CONNECT_END /* @min:%2econnectEnd */]);
|
|
130
|
+
request = dateTimeUtilsDuration(timing.requestStart, timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);
|
|
131
|
+
response = dateTimeUtilsDuration(timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */], timing[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);
|
|
132
|
+
dom = dateTimeUtilsDuration(timing.responseEnd, timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
133
|
+
}
|
|
134
|
+
if (total === 0) {
|
|
135
|
+
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 10 /* _eInternalMessageId.ErrorPVCalc */, "error calculating page view performance.", { total: total, network: network, request: request, response: response, dom: dom });
|
|
136
|
+
}
|
|
137
|
+
else if (!_this[_DYN_SHOULD_COLLECT_DURAT18 /* @min:%2eshouldCollectDuration */](total, network, request, response, dom)) {
|
|
138
|
+
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 45 /* _eInternalMessageId.InvalidDurationValue */, "Invalid page load duration value. Browser perf data won't be sent.", { total: total, network: network, request: request, response: response, dom: dom });
|
|
139
|
+
}
|
|
140
|
+
else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {
|
|
141
|
+
// some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT
|
|
142
|
+
// in this case, don't report client performance from this page
|
|
143
|
+
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 8 /* _eInternalMessageId.ClientPerformanceMathError */, "client performance math error.", { total: total, network: network, request: request, response: response, dom: dom });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
pageViewPerformance.durationMs = total;
|
|
147
|
+
// // convert to timespans
|
|
148
|
+
pageViewPerformance.perfTotal = pageViewPerformance[_DYN_DURATION /* @min:%2eduration */] = msToTimeSpan(total);
|
|
149
|
+
pageViewPerformance.networkConnect = msToTimeSpan(network);
|
|
150
|
+
pageViewPerformance.sentRequest = msToTimeSpan(request);
|
|
151
|
+
pageViewPerformance.receivedResponse = msToTimeSpan(response);
|
|
152
|
+
pageViewPerformance.domProcessing = msToTimeSpan(dom);
|
|
153
|
+
pageViewPerformance.isValid = true;
|
|
154
|
+
}
|
|
162
155
|
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
};
|
|
157
|
+
_self[_DYN_GET_PERFORMANCE_TIMI17 /* @min:%2egetPerformanceTiming */] = _getPerformanceTiming;
|
|
158
|
+
_self[_DYN_IS_PERFORMANCE_TIMIN16 /* @min:%2eisPerformanceTimingSupported */] = _isPerformanceTimingSupported;
|
|
159
|
+
_self[_DYN_IS_PERFORMANCE_TIMIN19 /* @min:%2eisPerformanceTimingDataReady */] = _isPerformanceTimingDataReady;
|
|
160
|
+
_self[_DYN_SHOULD_COLLECT_DURAT18 /* @min:%2eshouldCollectDuration */] = _shouldCollectDuration;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// Removed Stub for PageViewPerformanceManager.prototype.populatePageViewPerformanceEvent.
|
|
164
|
+
// Removed Stub for PageViewPerformanceManager.prototype.getPerformanceTiming.
|
|
165
|
+
// Removed Stub for PageViewPerformanceManager.prototype.isPerformanceTimingSupported.
|
|
166
|
+
// Removed Stub for PageViewPerformanceManager.prototype.isPerformanceTimingDataReady.
|
|
167
|
+
// Removed Stub for PageViewPerformanceManager.prototype.shouldCollectDuration.
|
|
168
|
+
// This is a workaround for an IE8 bug when using dynamicProto() with classes that don't have any
|
|
169
|
+
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
170
|
+
// this will be removed when ES3 support is dropped.
|
|
171
|
+
PageViewPerformanceManager.__ieDyn=1;
|
|
172
|
+
|
|
167
173
|
return PageViewPerformanceManager;
|
|
168
174
|
}());
|
|
169
175
|
export { PageViewPerformanceManager };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageViewPerformanceManager.js.map","sources":["PageViewPerformanceManager.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { dateTimeUtilsDuration, msToTimeSpan } from \"@microsoft/applicationinsights-common\";\r\nimport { getNavigator, getPerformance, _throwInternal } from \"@microsoft/applicationinsights-core-js\";\r\n/**\r\n * Class encapsulates sending page view performance telemetry.\r\n */\r\nvar PageViewPerformanceManager = /** @class */ (function () {\r\n function PageViewPerformanceManager(core) {\r\n this.MAX_DURATION_ALLOWED = 3600000; // 1h\r\n if (core) {\r\n this._logger = core.logger;\r\n }\r\n }\r\n PageViewPerformanceManager.prototype.populatePageViewPerformanceEvent = function (pageViewPerformance) {\r\n pageViewPerformance.isValid = false;\r\n /*\r\n * http://www.w3.org/TR/navigation-timing/#processing-model\r\n * |-navigationStart\r\n * | |-connectEnd\r\n * | ||-requestStart\r\n * | || |-responseStart\r\n * | || | |-responseEnd\r\n * | || | |\r\n * | || | | |-loadEventEnd\r\n * |---network---||---request---|---response---|---dom---|\r\n * |--------------------------total----------------------|\r\n *\r\n * 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\r\n * network = Redirect time + App Cache + DNS lookup time + TCP connection time\r\n * request = Request time : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#request_time\r\n * response = Response time\r\n * dom = Document load time : https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info\r\n * = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing\r\n * + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading\r\n */\r\n var navigationTiming = this.getPerformanceNavigationTiming();\r\n var timing = this.getPerformanceTiming();\r\n var total = 0;\r\n var network = 0;\r\n var request = 0;\r\n var response = 0;\r\n var dom = 0;\r\n if (navigationTiming || timing) {\r\n if (navigationTiming) {\r\n total = navigationTiming.duration;\r\n /**\r\n * support both cases:\r\n * - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming\r\n * - for older browsers where the startTime is not zero\r\n */\r\n network = navigationTiming.startTime === 0 ? navigationTiming.connectEnd : dateTimeUtilsDuration(navigationTiming.startTime, navigationTiming.connectEnd);\r\n request = dateTimeUtilsDuration(navigationTiming.requestStart, navigationTiming.responseStart);\r\n response = dateTimeUtilsDuration(navigationTiming.responseStart, navigationTiming.responseEnd);\r\n dom = dateTimeUtilsDuration(navigationTiming.responseEnd, navigationTiming.loadEventEnd);\r\n }\r\n else {\r\n total = dateTimeUtilsDuration(timing.navigationStart, timing.loadEventEnd);\r\n network = dateTimeUtilsDuration(timing.navigationStart, timing.connectEnd);\r\n request = dateTimeUtilsDuration(timing.requestStart, timing.responseStart);\r\n response = dateTimeUtilsDuration(timing.responseStart, timing.responseEnd);\r\n dom = dateTimeUtilsDuration(timing.responseEnd, timing.loadEventEnd);\r\n }\r\n var logger = this._logger;\r\n if (total === 0) {\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 10 /* _eInternalMessageId.ErrorPVCalc */, \"error calculating page view performance.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else if (!this.shouldCollectDuration(total, network, request, response, dom)) {\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 45 /* _eInternalMessageId.InvalidDurationValue */, \"Invalid page load duration value. Browser perf data won't be sent.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {\r\n // some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT\r\n // in this case, don't report client performance from this page\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 8 /* _eInternalMessageId.ClientPerformanceMathError */, \"client performance math error.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else {\r\n pageViewPerformance.durationMs = total;\r\n // // convert to timespans\r\n pageViewPerformance.perfTotal = pageViewPerformance.duration = msToTimeSpan(total);\r\n pageViewPerformance.networkConnect = msToTimeSpan(network);\r\n pageViewPerformance.sentRequest = msToTimeSpan(request);\r\n pageViewPerformance.receivedResponse = msToTimeSpan(response);\r\n pageViewPerformance.domProcessing = msToTimeSpan(dom);\r\n pageViewPerformance.isValid = true;\r\n }\r\n }\r\n };\r\n PageViewPerformanceManager.prototype.getPerformanceTiming = function () {\r\n if (this.isPerformanceTimingSupported()) {\r\n return getPerformance().timing;\r\n }\r\n return null;\r\n };\r\n PageViewPerformanceManager.prototype.getPerformanceNavigationTiming = function () {\r\n if (this.isPerformanceNavigationTimingSupported()) {\r\n return getPerformance().getEntriesByType(\"navigation\")[0];\r\n }\r\n return null;\r\n };\r\n /**\r\n * Returns true is window PerformanceNavigationTiming API is supported, false otherwise.\r\n */\r\n PageViewPerformanceManager.prototype.isPerformanceNavigationTimingSupported = function () {\r\n var perf = getPerformance();\r\n return perf && perf.getEntriesByType && perf.getEntriesByType(\"navigation\").length > 0;\r\n };\r\n /**\r\n * Returns true is window performance timing API is supported, false otherwise.\r\n */\r\n PageViewPerformanceManager.prototype.isPerformanceTimingSupported = function () {\r\n var perf = getPerformance();\r\n return perf && perf.timing;\r\n };\r\n /**\r\n * As page loads different parts of performance timing numbers get set. When all of them are set we can report it.\r\n * Returns true if ready, false otherwise.\r\n */\r\n PageViewPerformanceManager.prototype.isPerformanceTimingDataReady = function () {\r\n var perf = getPerformance();\r\n var timing = perf ? perf.timing : 0;\r\n return timing\r\n && timing.domainLookupStart > 0\r\n && timing.navigationStart > 0\r\n && timing.responseStart > 0\r\n && timing.requestStart > 0\r\n && timing.loadEventEnd > 0\r\n && timing.responseEnd > 0\r\n && timing.connectEnd > 0\r\n && timing.domLoading > 0;\r\n };\r\n /**\r\n * This method tells if given durations should be excluded from collection.\r\n */\r\n PageViewPerformanceManager.prototype.shouldCollectDuration = function () {\r\n var durations = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n durations[_i] = arguments[_i];\r\n }\r\n var _navigator = getNavigator() || {};\r\n // a full list of Google crawlers user agent strings - https://support.google.com/webmasters/answer/1061943?hl=en\r\n var botAgentNames = [\"googlebot\", \"adsbot-google\", \"apis-google\", \"mediapartners-google\"];\r\n var userAgent = _navigator.userAgent;\r\n var isGoogleBot = false;\r\n if (userAgent) {\r\n for (var i = 0; i < botAgentNames.length; i++) {\r\n isGoogleBot = isGoogleBot || userAgent.toLowerCase().indexOf(botAgentNames[i]) !== -1;\r\n }\r\n }\r\n if (isGoogleBot) {\r\n // Don't report durations for GoogleBot, it is returning invalid values in performance.timing API.\r\n return false;\r\n }\r\n else {\r\n // for other page views, don't report if it's outside of a reasonable range\r\n for (var i = 0; i < durations.length; i++) {\r\n if (durations[i] < 0 || durations[i] >= this.MAX_DURATION_ALLOWED) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n };\r\n return PageViewPerformanceManager;\r\n}());\r\nexport { PageViewPerformanceManager };\r\n//# sourceMappingURL=PageViewPerformanceManager.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"PageViewPerformanceManager.js.map","sources":["PageViewPerformanceManager.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { dateTimeUtilsDuration, msToTimeSpan } from \"@microsoft/applicationinsights-common\";\r\nimport { _throwInternal, getNavigator, getPerformance, safeGetLogger } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_CONNECT_END, _DYN_DURATION, _DYN_GET_ENTRIES_BY_TYPE, _DYN_GET_PERFORMANCE_TIMI17, _DYN_IS_PERFORMANCE_TIMIN16, _DYN_IS_PERFORMANCE_TIMIN19, _DYN_LENGTH, _DYN_LOAD_EVENT_END, _DYN_NAVIGATION_START, _DYN_POPULATE_PAGE_VIEW_P12, _DYN_REQUEST_START, _DYN_RESPONSE_END, _DYN_RESPONSE_START, _DYN_SHOULD_COLLECT_DURAT18 } from \"../../__DynamicConstants\";\r\nvar MAX_DURATION_ALLOWED = 3600000; // 1h\r\nvar botAgentNames = [\"googlebot\", \"adsbot-google\", \"apis-google\", \"mediapartners-google\"];\r\nfunction _isPerformanceTimingSupported() {\r\n var perf = getPerformance();\r\n return perf && !!perf.timing;\r\n}\r\nfunction _isPerformanceNavigationTimingSupported() {\r\n var perf = getPerformance();\r\n return perf && perf.getEntriesByType && perf.getEntriesByType(\"navigation\")[_DYN_LENGTH /* @min:%2elength */] > 0;\r\n}\r\nfunction _isPerformanceTimingDataReady() {\r\n var perf = getPerformance();\r\n var timing = perf ? perf.timing : 0;\r\n return timing\r\n && timing.domainLookupStart > 0\r\n && timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */] > 0\r\n && timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */] > 0\r\n && timing[_DYN_REQUEST_START /* @min:%2erequestStart */] > 0\r\n && timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */] > 0\r\n && timing[_DYN_RESPONSE_END /* @min:%2eresponseEnd */] > 0\r\n && timing[_DYN_CONNECT_END /* @min:%2econnectEnd */] > 0\r\n && timing.domLoading > 0;\r\n}\r\nfunction _getPerformanceTiming() {\r\n if (_isPerformanceTimingSupported()) {\r\n return getPerformance().timing;\r\n }\r\n return null;\r\n}\r\nfunction _getPerformanceNavigationTiming() {\r\n if (_isPerformanceNavigationTimingSupported()) {\r\n return getPerformance()[_DYN_GET_ENTRIES_BY_TYPE /* @min:%2egetEntriesByType */](\"navigation\")[0];\r\n }\r\n return null;\r\n}\r\n/**\r\n* This method tells if given durations should be excluded from collection.\r\n*/\r\nfunction _shouldCollectDuration() {\r\n var durations = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n durations[_i] = arguments[_i];\r\n }\r\n var _navigator = getNavigator() || {};\r\n // a full list of Google crawlers user agent strings - https://support.google.com/webmasters/answer/1061943?hl=en\r\n var userAgent = _navigator.userAgent;\r\n var isGoogleBot = false;\r\n if (userAgent) {\r\n for (var i = 0; i < botAgentNames[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n isGoogleBot = isGoogleBot || userAgent.toLowerCase().indexOf(botAgentNames[i]) !== -1;\r\n }\r\n }\r\n if (isGoogleBot) {\r\n // Don't report durations for GoogleBot, it is returning invalid values in performance.timing API.\r\n return false;\r\n }\r\n else {\r\n // for other page views, don't report if it's outside of a reasonable range\r\n for (var i = 0; i < durations[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n if (durations[i] < 0 || durations[i] >= MAX_DURATION_ALLOWED) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n}\r\n/**\r\n * Class encapsulates sending page view performance telemetry.\r\n */\r\nvar PageViewPerformanceManager = /** @class */ (function () {\r\n function PageViewPerformanceManager(core) {\r\n var _this = this;\r\n var _logger = safeGetLogger(core);\r\n dynamicProto(PageViewPerformanceManager, this, function (_self) {\r\n _self[_DYN_POPULATE_PAGE_VIEW_P12 /* @min:%2epopulatePageViewPerformanceEvent */] = function (pageViewPerformance) {\r\n pageViewPerformance.isValid = false;\r\n /*\r\n * http://www.w3.org/TR/navigation-timing/#processing-model\r\n * |-navigationStart\r\n * | |-connectEnd\r\n * | ||-requestStart\r\n * | || |-responseStart\r\n * | || | |-responseEnd\r\n * | || | |\r\n * | || | | |-loadEventEnd\r\n * |---network---||---request---|---response---|---dom---|\r\n * |--------------------------total----------------------|\r\n *\r\n * 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\r\n * network = Redirect time + App Cache + DNS lookup time + TCP connection time\r\n * request = Request time : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#request_time\r\n * response = Response time\r\n * dom = Document load time : https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info\r\n * = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing\r\n * + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading\r\n */\r\n var navigationTiming = _getPerformanceNavigationTiming();\r\n var timing = _getPerformanceTiming();\r\n var total = 0;\r\n var network = 0;\r\n var request = 0;\r\n var response = 0;\r\n var dom = 0;\r\n if (navigationTiming || timing) {\r\n if (navigationTiming) {\r\n total = navigationTiming[_DYN_DURATION /* @min:%2eduration */];\r\n /**\r\n * support both cases:\r\n * - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming\r\n * - for older browsers where the startTime is not zero\r\n */\r\n network = navigationTiming.startTime === 0 ? navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */] : dateTimeUtilsDuration(navigationTiming.startTime, navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */]);\r\n request = dateTimeUtilsDuration(navigationTiming.requestStart, navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);\r\n response = dateTimeUtilsDuration(navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */], navigationTiming[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);\r\n dom = dateTimeUtilsDuration(navigationTiming.responseEnd, navigationTiming[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);\r\n }\r\n else {\r\n total = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);\r\n network = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_CONNECT_END /* @min:%2econnectEnd */]);\r\n request = dateTimeUtilsDuration(timing.requestStart, timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);\r\n response = dateTimeUtilsDuration(timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */], timing[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);\r\n dom = dateTimeUtilsDuration(timing.responseEnd, timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);\r\n }\r\n if (total === 0) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 10 /* _eInternalMessageId.ErrorPVCalc */, \"error calculating page view performance.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else if (!_this[_DYN_SHOULD_COLLECT_DURAT18 /* @min:%2eshouldCollectDuration */](total, network, request, response, dom)) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 45 /* _eInternalMessageId.InvalidDurationValue */, \"Invalid page load duration value. Browser perf data won't be sent.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {\r\n // some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT\r\n // in this case, don't report client performance from this page\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 8 /* _eInternalMessageId.ClientPerformanceMathError */, \"client performance math error.\", { total: total, network: network, request: request, response: response, dom: dom });\r\n }\r\n else {\r\n pageViewPerformance.durationMs = total;\r\n // // convert to timespans\r\n pageViewPerformance.perfTotal = pageViewPerformance[_DYN_DURATION /* @min:%2eduration */] = msToTimeSpan(total);\r\n pageViewPerformance.networkConnect = msToTimeSpan(network);\r\n pageViewPerformance.sentRequest = msToTimeSpan(request);\r\n pageViewPerformance.receivedResponse = msToTimeSpan(response);\r\n pageViewPerformance.domProcessing = msToTimeSpan(dom);\r\n pageViewPerformance.isValid = true;\r\n }\r\n }\r\n };\r\n _self[_DYN_GET_PERFORMANCE_TIMI17 /* @min:%2egetPerformanceTiming */] = _getPerformanceTiming;\r\n _self[_DYN_IS_PERFORMANCE_TIMIN16 /* @min:%2eisPerformanceTimingSupported */] = _isPerformanceTimingSupported;\r\n _self[_DYN_IS_PERFORMANCE_TIMIN19 /* @min:%2eisPerformanceTimingDataReady */] = _isPerformanceTimingDataReady;\r\n _self[_DYN_SHOULD_COLLECT_DURAT18 /* @min:%2eshouldCollectDuration */] = _shouldCollectDuration;\r\n });\r\n }\r\n PageViewPerformanceManager.prototype.populatePageViewPerformanceEvent = function (pageViewPerformance) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n PageViewPerformanceManager.prototype.getPerformanceTiming = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Returns true is window performance timing API is supported, false otherwise.\r\n */\r\n PageViewPerformanceManager.prototype.isPerformanceTimingSupported = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return true;\r\n };\r\n /**\r\n * As page loads different parts of performance timing numbers get set. When all of them are set we can report it.\r\n * Returns true if ready, false otherwise.\r\n */\r\n PageViewPerformanceManager.prototype.isPerformanceTimingDataReady = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return true;\r\n };\r\n /**\r\n * This method tells if given durations should be excluded from collection.\r\n */\r\n PageViewPerformanceManager.prototype.shouldCollectDuration = function () {\r\n var durations = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n durations[_i] = arguments[_i];\r\n }\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return true;\r\n };\r\n return PageViewPerformanceManager;\r\n}());\r\nexport { PageViewPerformanceManager };\r\n//# sourceMappingURL=PageViewPerformanceManager.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;+EAgCM,CAAC;;;;;;sCAC+B;AACtC;AACA;AACA"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Web Analytics, 2.8.5-nightly.2206-
|
|
2
|
+
* Application Insights JavaScript SDK - Web Analytics, 2.8.5-nightly.2206-06
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
7
8
|
import { utlCanUseSessionStorage, utlGetSessionStorage, utlRemoveSessionStorage, utlSetSessionStorage } from "@microsoft/applicationinsights-common";
|
|
8
|
-
import {
|
|
9
|
+
import { _warnToConsole, dateNow, dumpObj, getJSON, hasJSON, objDefineAccessors, throwError } from "@microsoft/applicationinsights-core-js";
|
|
10
|
+
import { _DYN_PAGE_VISIT_START_TIM20, _DYN_TRACK_PREVIOUS_PAGE_9 } from "../../__DynamicConstants";
|
|
9
11
|
/**
|
|
10
12
|
* Used to track page visit durations
|
|
11
13
|
*/
|
|
@@ -16,102 +18,103 @@ var PageVisitTimeManager = /** @class */ (function () {
|
|
|
16
18
|
* @returns {}
|
|
17
19
|
*/
|
|
18
20
|
function PageVisitTimeManager(logger, pageVisitTimeTrackingHandler) {
|
|
19
|
-
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
var prevPageVisitDataKeyName = "prevPageVisitData";
|
|
22
|
+
dynamicProto(PageVisitTimeManager, this, function (_self) {
|
|
23
|
+
_self[_DYN_TRACK_PREVIOUS_PAGE_9 /* @min:%2etrackPreviousPageVisit */] = function (currentPageName, currentPageUrl) {
|
|
24
|
+
try {
|
|
25
|
+
// Restart timer for new page view
|
|
26
|
+
var prevPageVisitTimeData = restartPageVisitTimer(currentPageName, currentPageUrl);
|
|
27
|
+
// If there was a page already being timed, track the visit time for it now.
|
|
28
|
+
if (prevPageVisitTimeData) {
|
|
29
|
+
pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
_warnToConsole(logger, "Auto track page visit time failed, metric will not be collected: " + dumpObj(e));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Stops timing of current page (if exists) and starts timing for duration of visit to pageName
|
|
38
|
+
* @param pageName Name of page to begin timing visit duration
|
|
39
|
+
* @returns {PageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.
|
|
40
|
+
*/
|
|
41
|
+
function restartPageVisitTimer(pageName, pageUrl) {
|
|
42
|
+
var prevPageVisitData = null;
|
|
43
|
+
try {
|
|
44
|
+
prevPageVisitData = stopPageVisitTimer();
|
|
45
|
+
startPageVisitTimer(pageName, pageUrl);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
_warnToConsole(logger, "Call to restart failed: " + dumpObj(e));
|
|
49
|
+
prevPageVisitData = null;
|
|
50
|
+
}
|
|
51
|
+
return prevPageVisitData;
|
|
35
52
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Starts timing visit duration of pageName
|
|
59
|
-
* @param pageName
|
|
60
|
-
* @returns {}
|
|
61
|
-
*/
|
|
62
|
-
PageVisitTimeManager.prototype.startPageVisitTimer = function (pageName, pageUrl) {
|
|
63
|
-
try {
|
|
64
|
-
if (utlCanUseSessionStorage()) {
|
|
65
|
-
if (utlGetSessionStorage(this._logger, this.prevPageVisitDataKeyName) != null) {
|
|
66
|
-
throwError("Cannot call startPageVisit consecutively without first calling stopPageVisit");
|
|
53
|
+
/**
|
|
54
|
+
* Starts timing visit duration of pageName
|
|
55
|
+
* @param pageName
|
|
56
|
+
* @returns {}
|
|
57
|
+
*/
|
|
58
|
+
function startPageVisitTimer(pageName, pageUrl) {
|
|
59
|
+
try {
|
|
60
|
+
if (utlCanUseSessionStorage()) {
|
|
61
|
+
if (utlGetSessionStorage(logger, prevPageVisitDataKeyName) != null) {
|
|
62
|
+
throwError("Cannot call startPageVisit consecutively without first calling stopPageVisit");
|
|
63
|
+
}
|
|
64
|
+
var currPageVisitData = new PageVisitData(pageName, pageUrl);
|
|
65
|
+
var currPageVisitDataStr = getJSON().stringify(currPageVisitData);
|
|
66
|
+
utlSetSessionStorage(logger, prevPageVisitDataKeyName, currPageVisitDataStr);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
// TODO: Remove this catch in next phase, since if start is called twice in a row the exception needs to be propagated out
|
|
71
|
+
_warnToConsole(logger, "Call to start failed: " + dumpObj(e));
|
|
67
72
|
}
|
|
68
|
-
var currPageVisitData = new PageVisitData(pageName, pageUrl);
|
|
69
|
-
var currPageVisitDataStr = getJSON().stringify(currPageVisitData);
|
|
70
|
-
utlSetSessionStorage(this._logger, this.prevPageVisitDataKeyName, currPageVisitDataStr);
|
|
71
73
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
prevPageVisitData.pageVisitTime = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;
|
|
93
|
-
// Remove data from storage since we already used it
|
|
94
|
-
utlRemoveSessionStorage(this._logger, this.prevPageVisitDataKeyName);
|
|
95
|
-
// Return page visit data
|
|
96
|
-
return prevPageVisitData;
|
|
74
|
+
/**
|
|
75
|
+
* Stops timing of current page, if exists.
|
|
76
|
+
* @returns {PageVisitData} Page visit data (including duration) of pageName from call to start, if exists. Null if not.
|
|
77
|
+
*/
|
|
78
|
+
function stopPageVisitTimer() {
|
|
79
|
+
var prevPageVisitData = null;
|
|
80
|
+
try {
|
|
81
|
+
if (utlCanUseSessionStorage()) {
|
|
82
|
+
// Define end time of page's visit
|
|
83
|
+
var pageVisitEndTime = dateNow();
|
|
84
|
+
// Try to retrieve page name and start time from session storage
|
|
85
|
+
var pageVisitDataJsonStr = utlGetSessionStorage(logger, prevPageVisitDataKeyName);
|
|
86
|
+
if (pageVisitDataJsonStr && hasJSON()) {
|
|
87
|
+
// if previous page data exists, set end time of visit
|
|
88
|
+
prevPageVisitData = getJSON().parse(pageVisitDataJsonStr);
|
|
89
|
+
prevPageVisitData.pageVisitTime = pageVisitEndTime - prevPageVisitData[_DYN_PAGE_VISIT_START_TIM20 /* @min:%2epageVisitStartTime */];
|
|
90
|
+
// Remove data from storage since we already used it
|
|
91
|
+
utlRemoveSessionStorage(logger, prevPageVisitDataKeyName);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
97
94
|
}
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
catch (e) {
|
|
96
|
+
_warnToConsole(logger, "Stop page visit timer failed: " + dumpObj(e));
|
|
97
|
+
prevPageVisitData = null;
|
|
100
98
|
}
|
|
99
|
+
return prevPageVisitData;
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
// For backward compatibility
|
|
102
|
+
objDefineAccessors(_self, "_logger", function () { return logger; });
|
|
103
|
+
objDefineAccessors(_self, "pageVisitTimeTrackingHandler", function () { return pageVisitTimeTrackingHandler; });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Removed Stub for PageVisitTimeManager.prototype.trackPreviousPageVisit.
|
|
107
|
+
// This is a workaround for an IE8 bug when using dynamicProto() with classes that don't have any
|
|
108
|
+
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
109
|
+
// this will be removed when ES3 support is dropped.
|
|
110
|
+
PageVisitTimeManager.__ieDyn=1;
|
|
111
|
+
|
|
109
112
|
return PageVisitTimeManager;
|
|
110
113
|
}());
|
|
111
114
|
export { PageVisitTimeManager };
|
|
112
115
|
var PageVisitData = /** @class */ (function () {
|
|
113
116
|
function PageVisitData(pageName, pageUrl) {
|
|
114
|
-
this
|
|
117
|
+
this[_DYN_PAGE_VISIT_START_TIM20 /* @min:%2epageVisitStartTime */] = dateNow();
|
|
115
118
|
this.pageName = pageName;
|
|
116
119
|
this.pageUrl = pageUrl;
|
|
117
120
|
}
|