@microsoft/applicationinsights-analytics-js 3.4.0-nightlybeta3.2505-36 → 3.4.0-nightlybeta3.2507-23
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 +471 -422
- package/browser/es5/applicationinsights-analytics-js.cjs.js.map +1 -1
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js +2 -2
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js.map +1 -1
- package/browser/es5/applicationinsights-analytics-js.gbl.js +473 -424
- package/browser/es5/applicationinsights-analytics-js.gbl.js.map +1 -1
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js +2 -2
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js.map +1 -1
- package/browser/es5/applicationinsights-analytics-js.integrity.json +25 -25
- package/browser/es5/applicationinsights-analytics-js.js +473 -424
- package/browser/es5/applicationinsights-analytics-js.js.map +1 -1
- package/browser/es5/applicationinsights-analytics-js.min.js +2 -2
- package/browser/es5/applicationinsights-analytics-js.min.js.map +1 -1
- package/dist/es5/applicationinsights-analytics-js.js +471 -422
- package/dist/es5/applicationinsights-analytics-js.js.map +1 -1
- package/dist/es5/applicationinsights-analytics-js.min.js +2 -2
- package/dist/es5/applicationinsights-analytics-js.min.js.map +1 -1
- package/dist-es5/JavaScriptSDK/AnalyticsPlugin.js +40 -41
- package/dist-es5/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
- package/dist-es5/JavaScriptSDK/Interfaces/IAnalyticsConfig.js +8 -0
- package/dist-es5/JavaScriptSDK/Interfaces/IAnalyticsConfig.js.map +1 -0
- package/dist-es5/JavaScriptSDK/Telemetry/PageViewManager.js +175 -178
- package/dist-es5/JavaScriptSDK/Telemetry/PageViewManager.js.map +1 -1
- package/dist-es5/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +86 -96
- package/dist-es5/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +1 -1
- package/dist-es5/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +85 -92
- package/dist-es5/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +1 -1
- package/dist-es5/JavaScriptSDK/Timing.js +18 -15
- package/dist-es5/JavaScriptSDK/Timing.js.map +1 -1
- package/dist-es5/__DynamicConstants.js +7 -4
- package/dist-es5/__DynamicConstants.js.map +1 -1
- package/dist-es5/applicationinsights-analytics-js.js +1 -1
- package/package.json +5 -5
- package/types/applicationinsights-analytics-js.d.ts +100 -1
- package/types/applicationinsights-analytics-js.namespaced.d.ts +381 -14
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.
|
|
2
|
+
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.2507-23
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
7
|
import { dateTimeUtilsDuration, msToTimeSpan } from "@microsoft/applicationinsights-common";
|
|
9
8
|
import { _throwInternal, getNavigator, getPerformance, safeGetLogger } from "@microsoft/applicationinsights-core-js";
|
|
10
9
|
import { mathFloor, strIndexOf } from "@nevware21/ts-utils";
|
|
@@ -76,100 +75,91 @@ function _shouldCollectDuration() {
|
|
|
76
75
|
return true;
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
79
|
-
*
|
|
78
|
+
* Factory function to create a PageViewPerformanceManager instance.
|
|
79
|
+
* @param core - App Insights core instance
|
|
80
|
+
* @returns A new IPageViewPerformanceManager instance.
|
|
81
|
+
* @internal
|
|
80
82
|
*/
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 (!_self[_DYN_SHOULD_COLLECT_DURAT17 /* @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 < mathFloor(network) + mathFloor(request) + mathFloor(response) + mathFloor(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
|
-
}
|
|
83
|
+
export function createPageViewPerformanceManager(core) {
|
|
84
|
+
var _a;
|
|
85
|
+
var _logger = safeGetLogger(core);
|
|
86
|
+
return _a = {},
|
|
87
|
+
_a[_DYN_POPULATE_PAGE_VIEW_P4 /* @min:populatePageViewPerformanceEvent */] = function (pageViewPerformance) {
|
|
88
|
+
pageViewPerformance.isValid = false;
|
|
89
|
+
/*
|
|
90
|
+
* http://www.w3.org/TR/navigation-timing/#processing-model
|
|
91
|
+
* |-navigationStart
|
|
92
|
+
* | |-connectEnd
|
|
93
|
+
* | ||-requestStart
|
|
94
|
+
* | || |-responseStart
|
|
95
|
+
* | || | |-responseEnd
|
|
96
|
+
* | || | |
|
|
97
|
+
* | || | | |-loadEventEnd
|
|
98
|
+
* |---network---||---request---|---response---|---dom---|
|
|
99
|
+
* |--------------------------total----------------------|
|
|
100
|
+
*
|
|
101
|
+
* 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
|
|
102
|
+
* network = Redirect time + App Cache + DNS lookup time + TCP connection time
|
|
103
|
+
* request = Request time : https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings#request_time
|
|
104
|
+
* response = Response time
|
|
105
|
+
* dom = Document load time : https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
|
|
106
|
+
* = Document processing time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#document_processing
|
|
107
|
+
* + Loading time : https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/#loading
|
|
108
|
+
*/
|
|
109
|
+
var navigationTiming = _getPerformanceNavigationTiming();
|
|
110
|
+
var timing = _getPerformanceTiming();
|
|
111
|
+
var total = 0;
|
|
112
|
+
var network = 0;
|
|
113
|
+
var request = 0;
|
|
114
|
+
var response = 0;
|
|
115
|
+
var dom = 0;
|
|
116
|
+
if (navigationTiming || timing) {
|
|
117
|
+
if (navigationTiming) {
|
|
118
|
+
total = navigationTiming[_DYN_DURATION /* @min:%2eduration */];
|
|
119
|
+
/**
|
|
120
|
+
* support both cases:
|
|
121
|
+
* - startTime is always zero: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
|
122
|
+
* - for older browsers where the startTime is not zero
|
|
123
|
+
*/
|
|
124
|
+
network = navigationTiming[_DYN_START_TIME /* @min:%2estartTime */] === 0 ? navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */] : dateTimeUtilsDuration(navigationTiming[_DYN_START_TIME /* @min:%2estartTime */], navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */]);
|
|
125
|
+
request = dateTimeUtilsDuration(navigationTiming.requestStart, navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);
|
|
126
|
+
response = dateTimeUtilsDuration(navigationTiming[_DYN_RESPONSE_START /* @min:%2eresponseStart */], navigationTiming[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);
|
|
127
|
+
dom = dateTimeUtilsDuration(navigationTiming.responseEnd, navigationTiming[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
155
128
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
129
|
+
else {
|
|
130
|
+
total = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
131
|
+
network = dateTimeUtilsDuration(timing[_DYN_NAVIGATION_START /* @min:%2enavigationStart */], timing[_DYN_CONNECT_END /* @min:%2econnectEnd */]);
|
|
132
|
+
request = dateTimeUtilsDuration(timing.requestStart, timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */]);
|
|
133
|
+
response = dateTimeUtilsDuration(timing[_DYN_RESPONSE_START /* @min:%2eresponseStart */], timing[_DYN_RESPONSE_END /* @min:%2eresponseEnd */]);
|
|
134
|
+
dom = dateTimeUtilsDuration(timing.responseEnd, timing[_DYN_LOAD_EVENT_END /* @min:%2eloadEventEnd */]);
|
|
135
|
+
}
|
|
136
|
+
if (total === 0) {
|
|
137
|
+
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 10 /* _eInternalMessageId.ErrorPVCalc */, "error calculating page view performance.", { total: total, network: network, request: request, response: response, dom: dom });
|
|
138
|
+
}
|
|
139
|
+
else if (!_shouldCollectDuration(total, network, request, response, dom)) {
|
|
140
|
+
_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 });
|
|
141
|
+
}
|
|
142
|
+
else if (total < mathFloor(network) + mathFloor(request) + mathFloor(response) + mathFloor(dom)) {
|
|
143
|
+
// some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT
|
|
144
|
+
// in this case, don't report client performance from this page
|
|
145
|
+
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 8 /* _eInternalMessageId.ClientPerformanceMathError */, "client performance math error.", { total: total, network: network, request: request, response: response, dom: dom });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
pageViewPerformance.durationMs = total;
|
|
149
|
+
// // convert to timespans
|
|
150
|
+
pageViewPerformance.perfTotal = pageViewPerformance[_DYN_DURATION /* @min:%2eduration */] = msToTimeSpan(total);
|
|
151
|
+
pageViewPerformance.networkConnect = msToTimeSpan(network);
|
|
152
|
+
pageViewPerformance.sentRequest = msToTimeSpan(request);
|
|
153
|
+
pageViewPerformance.receivedResponse = msToTimeSpan(response);
|
|
154
|
+
pageViewPerformance.domProcessing = msToTimeSpan(dom);
|
|
155
|
+
pageViewPerformance.isValid = true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
_a[_DYN_GET_PERFORMANCE_TIMI16 /* @min:getPerformanceTiming */] = _getPerformanceTiming,
|
|
160
|
+
_a[_DYN_IS_PERFORMANCE_TIMIN15 /* @min:isPerformanceTimingSupported */] = _isPerformanceTimingSupported,
|
|
161
|
+
_a[_DYN_IS_PERFORMANCE_TIMIN18 /* @min:isPerformanceTimingDataReady */] = _isPerformanceTimingDataReady,
|
|
162
|
+
_a[_DYN_SHOULD_COLLECT_DURAT17 /* @min:shouldCollectDuration */] = _shouldCollectDuration,
|
|
163
|
+
_a;
|
|
164
|
+
}
|
|
175
165
|
//# sourceMappingURL=PageViewPerformanceManager.js.map
|
|
@@ -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 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 { mathFloor, strIndexOf } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CONNECT_END, _DYN_DURATION, _DYN_GET_ENTRIES_BY_TYPE, _DYN_GET_PERFORMANCE_TIMI16, _DYN_IS_PERFORMANCE_TIMIN15, _DYN_IS_PERFORMANCE_TIMIN18, _DYN_LENGTH, _DYN_LOAD_EVENT_END, _DYN_NAVIGATION_START, _DYN_POPULATE_PAGE_VIEW_P4, _DYN_REQUEST_START, _DYN_RESPONSE_END, _DYN_RESPONSE_START, _DYN_SHOULD_COLLECT_DURAT17, _DYN_START_TIME } 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 || strIndexOf(userAgent.toLowerCase(), 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 _logger = safeGetLogger(core);\r\n dynamicProto(PageViewPerformanceManager, this, function (_self) {\r\n _self[_DYN_POPULATE_PAGE_VIEW_P4 /* @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[_DYN_START_TIME /* @min:%2estartTime */] === 0 ? navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */] : dateTimeUtilsDuration(navigationTiming[_DYN_START_TIME /* @min:%2estartTime */], 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 (!_self[_DYN_SHOULD_COLLECT_DURAT17 /* @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 < mathFloor(network) + mathFloor(request) + mathFloor(response) + mathFloor(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_TIMI16 /* @min:%2egetPerformanceTiming */] = _getPerformanceTiming;\r\n _self[_DYN_IS_PERFORMANCE_TIMIN15 /* @min:%2eisPerformanceTimingSupported */] = _isPerformanceTimingSupported;\r\n _self[_DYN_IS_PERFORMANCE_TIMIN18 /* @min:%2eisPerformanceTimingDataReady */] = _isPerformanceTimingDataReady;\r\n _self[_DYN_SHOULD_COLLECT_DURAT17 /* @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
|
+
{"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 { _throwInternal, getNavigator, getPerformance, safeGetLogger } from \"@microsoft/applicationinsights-core-js\";\r\nimport { mathFloor, strIndexOf } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CONNECT_END, _DYN_DURATION, _DYN_GET_ENTRIES_BY_TYPE, _DYN_GET_PERFORMANCE_TIMI16, _DYN_IS_PERFORMANCE_TIMIN15, _DYN_IS_PERFORMANCE_TIMIN18, _DYN_LENGTH, _DYN_LOAD_EVENT_END, _DYN_NAVIGATION_START, _DYN_POPULATE_PAGE_VIEW_P4, _DYN_REQUEST_START, _DYN_RESPONSE_END, _DYN_RESPONSE_START, _DYN_SHOULD_COLLECT_DURAT17, _DYN_START_TIME } 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 || strIndexOf(userAgent.toLowerCase(), 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 * Factory function to create a PageViewPerformanceManager instance.\r\n * @param core - App Insights core instance\r\n * @returns A new IPageViewPerformanceManager instance.\r\n * @internal\r\n */\r\nexport function createPageViewPerformanceManager(core) {\r\n var _a;\r\n var _logger = safeGetLogger(core);\r\n return _a = {},\r\n _a[_DYN_POPULATE_PAGE_VIEW_P4 /* @min: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 = _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[_DYN_START_TIME /* @min:%2estartTime */] === 0 ? navigationTiming[_DYN_CONNECT_END /* @min:%2econnectEnd */] : dateTimeUtilsDuration(navigationTiming[_DYN_START_TIME /* @min:%2estartTime */], 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 (!_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 < mathFloor(network) + mathFloor(request) + mathFloor(response) + mathFloor(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 _a[_DYN_GET_PERFORMANCE_TIMI16 /* @min:getPerformanceTiming */] = _getPerformanceTiming,\r\n _a[_DYN_IS_PERFORMANCE_TIMIN15 /* @min:isPerformanceTimingSupported */] = _isPerformanceTimingSupported,\r\n _a[_DYN_IS_PERFORMANCE_TIMIN18 /* @min:isPerformanceTimingDataReady */] = _isPerformanceTimingDataReady,\r\n _a[_DYN_SHOULD_COLLECT_DURAT17 /* @min:shouldCollectDuration */] = _shouldCollectDuration,\r\n _a;\r\n}\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"}
|
|
@@ -1,109 +1,102 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.
|
|
2
|
+
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.2507-23
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
7
|
import { utlCanUseSessionStorage, utlGetSessionStorage, utlRemoveSessionStorage, utlSetSessionStorage } from "@microsoft/applicationinsights-common";
|
|
9
8
|
import { _warnToConsole, dateNow, dumpObj, getJSON, hasJSON, throwError } from "@microsoft/applicationinsights-core-js";
|
|
10
|
-
import {
|
|
11
|
-
import { _DYN_TRACK_PREVIOUS_PAGE_1 } from "../../__DynamicConstants";
|
|
9
|
+
import { _DYN_PAGE_VISIT_TIME } from "../../__DynamicConstants";
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
11
|
+
* Factory function to create a page visit data object
|
|
12
|
+
* @param pageName - Name of the page
|
|
13
|
+
* @param pageUrl - URL of the page
|
|
14
|
+
* @returns IPageVisitData instance
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
export function createPageVisitData(pageName, pageUrl) {
|
|
17
|
+
return {
|
|
18
|
+
pageVisitStartTime: dateNow(),
|
|
19
|
+
pageName: pageName,
|
|
20
|
+
pageUrl: pageUrl,
|
|
21
|
+
pageVisitTime: 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Factory function to create a PageVisitTimeManager instance.
|
|
26
|
+
* @param logger - Diagnostic logger
|
|
27
|
+
* @param pageVisitTimeTrackingHandler - Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)
|
|
28
|
+
* @returns A new IPageVisitTimeManager instance.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export function createPageVisitTimeManager(logger, pageVisitTimeTrackingHandler) {
|
|
32
|
+
var prevPageVisitDataKeyName = "prevPageVisitData";
|
|
16
33
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param
|
|
19
|
-
* @returns {}
|
|
34
|
+
* Stops timing of current page (if exists) and starts timing for duration of visit to pageName
|
|
35
|
+
* @param pageName - Name of page to begin timing visit duration
|
|
36
|
+
* @returns {IPageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.
|
|
20
37
|
*/
|
|
21
|
-
function
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// If there was a page already being timed, track the visit time for it now.
|
|
29
|
-
if (prevPageVisitTimeData) {
|
|
30
|
-
pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
_warnToConsole(logger, "Auto track page visit time failed, metric will not be collected: " + dumpObj(e));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Stops timing of current page (if exists) and starts timing for duration of visit to pageName
|
|
39
|
-
* @param pageName - Name of page to begin timing visit duration
|
|
40
|
-
* @returns {PageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.
|
|
41
|
-
*/
|
|
42
|
-
function restartPageVisitTimer(pageName, pageUrl) {
|
|
43
|
-
var prevPageVisitData = null;
|
|
44
|
-
try {
|
|
45
|
-
prevPageVisitData = stopPageVisitTimer();
|
|
46
|
-
if (utlCanUseSessionStorage()) {
|
|
47
|
-
if (utlGetSessionStorage(logger, prevPageVisitDataKeyName) != null) {
|
|
48
|
-
throwError("Cannot call startPageVisit consecutively without first calling stopPageVisit");
|
|
49
|
-
}
|
|
50
|
-
var currPageVisitDataStr = getJSON().stringify(new PageVisitData(pageName, pageUrl));
|
|
51
|
-
utlSetSessionStorage(logger, prevPageVisitDataKeyName, currPageVisitDataStr);
|
|
52
|
-
}
|
|
38
|
+
function restartPageVisitTimer(pageName, pageUrl) {
|
|
39
|
+
var prevPageVisitData = null;
|
|
40
|
+
try {
|
|
41
|
+
prevPageVisitData = stopPageVisitTimer();
|
|
42
|
+
if (utlCanUseSessionStorage()) {
|
|
43
|
+
if (utlGetSessionStorage(logger, prevPageVisitDataKeyName) != null) {
|
|
44
|
+
throwError("Cannot call startPageVisit consecutively without first calling stopPageVisit");
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
prevPageVisitData = null;
|
|
57
|
-
}
|
|
58
|
-
return prevPageVisitData;
|
|
46
|
+
var currPageVisitDataStr = getJSON().stringify(createPageVisitData(pageName, pageUrl));
|
|
47
|
+
utlSetSessionStorage(logger, prevPageVisitDataKeyName, currPageVisitDataStr);
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
_warnToConsole(logger, "Call to restart failed: " + dumpObj(e));
|
|
52
|
+
prevPageVisitData = null;
|
|
53
|
+
}
|
|
54
|
+
return prevPageVisitData;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Stops timing of current page, if exists.
|
|
58
|
+
* @returns {IPageVisitData} Page visit data (including duration) of pageName from call to start, if exists. Null if not.
|
|
59
|
+
*/
|
|
60
|
+
function stopPageVisitTimer() {
|
|
61
|
+
var prevPageVisitData = null;
|
|
62
|
+
try {
|
|
63
|
+
if (utlCanUseSessionStorage()) {
|
|
64
|
+
// Define end time of page's visit
|
|
65
|
+
var pageVisitEndTime = dateNow();
|
|
66
|
+
// Try to retrieve page name and start time from session storage
|
|
67
|
+
var pageVisitDataJsonStr = utlGetSessionStorage(logger, prevPageVisitDataKeyName);
|
|
68
|
+
if (pageVisitDataJsonStr && hasJSON()) {
|
|
69
|
+
// if previous page data exists, set end time of visit
|
|
70
|
+
prevPageVisitData = getJSON().parse(pageVisitDataJsonStr);
|
|
71
|
+
prevPageVisitData[_DYN_PAGE_VISIT_TIME /* @min:%2epageVisitTime */] = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;
|
|
72
|
+
// Remove data from storage since we already used it
|
|
73
|
+
utlRemoveSessionStorage(logger, prevPageVisitDataKeyName);
|
|
84
74
|
}
|
|
85
|
-
return prevPageVisitData;
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// This is a workaround for an IE bug when using dynamicProto() with classes that don't have any
|
|
94
|
-
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
95
|
-
PageVisitTimeManager.__ieDyn=1;
|
|
96
|
-
|
|
97
|
-
return PageVisitTimeManager;
|
|
98
|
-
}());
|
|
99
|
-
export { PageVisitTimeManager };
|
|
100
|
-
var PageVisitData = /** @class */ (function () {
|
|
101
|
-
function PageVisitData(pageName, pageUrl) {
|
|
102
|
-
this.pageVisitStartTime = dateNow();
|
|
103
|
-
this.pageName = pageName;
|
|
104
|
-
this.pageUrl = pageUrl;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
_warnToConsole(logger, "Stop page visit timer failed: " + dumpObj(e));
|
|
79
|
+
prevPageVisitData = null;
|
|
80
|
+
}
|
|
81
|
+
return prevPageVisitData;
|
|
105
82
|
}
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
83
|
+
return {
|
|
84
|
+
trackPreviousPageVisit: function (currentPageName, currentPageUrl) {
|
|
85
|
+
try {
|
|
86
|
+
// Restart timer for new page view
|
|
87
|
+
var prevPageVisitTimeData = restartPageVisitTimer(currentPageName, currentPageUrl);
|
|
88
|
+
// If there was a page already being timed, track the visit time for it now.
|
|
89
|
+
if (prevPageVisitTimeData) {
|
|
90
|
+
pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData[_DYN_PAGE_VISIT_TIME /* @min:%2epageVisitTime */]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
_warnToConsole(logger, "Auto track page visit time failed, metric will not be collected: " + dumpObj(e));
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
// Expose for backward compatibility with tests
|
|
98
|
+
_logger: logger,
|
|
99
|
+
pageVisitTimeTrackingHandler: pageVisitTimeTrackingHandler
|
|
100
|
+
};
|
|
101
|
+
}
|
|
109
102
|
//# sourceMappingURL=PageVisitTimeManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageVisitTimeManager.js.map","sources":["PageVisitTimeManager.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport
|
|
1
|
+
{"version":3,"file":"PageVisitTimeManager.js.map","sources":["PageVisitTimeManager.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { utlCanUseSessionStorage, utlGetSessionStorage, utlRemoveSessionStorage, utlSetSessionStorage } from \"@microsoft/applicationinsights-common\";\r\nimport { _warnToConsole, dateNow, dumpObj, getJSON, hasJSON, throwError } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_PAGE_VISIT_TIME } from \"../../__DynamicConstants\";\r\n/**\r\n * Factory function to create a page visit data object\r\n * @param pageName - Name of the page\r\n * @param pageUrl - URL of the page\r\n * @returns IPageVisitData instance\r\n */\r\nexport function createPageVisitData(pageName, pageUrl) {\r\n return {\r\n pageVisitStartTime: dateNow(),\r\n pageName: pageName,\r\n pageUrl: pageUrl,\r\n pageVisitTime: 0\r\n };\r\n}\r\n/**\r\n * Factory function to create a PageVisitTimeManager instance.\r\n * @param logger - Diagnostic logger\r\n * @param pageVisitTimeTrackingHandler - Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)\r\n * @returns A new IPageVisitTimeManager instance.\r\n * @internal\r\n */\r\nexport function createPageVisitTimeManager(logger, pageVisitTimeTrackingHandler) {\r\n var prevPageVisitDataKeyName = \"prevPageVisitData\";\r\n /**\r\n * Stops timing of current page (if exists) and starts timing for duration of visit to pageName\r\n * @param pageName - Name of page to begin timing visit duration\r\n * @returns {IPageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not.\r\n */\r\n function restartPageVisitTimer(pageName, pageUrl) {\r\n var prevPageVisitData = null;\r\n try {\r\n prevPageVisitData = stopPageVisitTimer();\r\n if (utlCanUseSessionStorage()) {\r\n if (utlGetSessionStorage(logger, prevPageVisitDataKeyName) != null) {\r\n throwError(\"Cannot call startPageVisit consecutively without first calling stopPageVisit\");\r\n }\r\n var currPageVisitDataStr = getJSON().stringify(createPageVisitData(pageName, pageUrl));\r\n utlSetSessionStorage(logger, prevPageVisitDataKeyName, currPageVisitDataStr);\r\n }\r\n }\r\n catch (e) {\r\n _warnToConsole(logger, \"Call to restart failed: \" + dumpObj(e));\r\n prevPageVisitData = null;\r\n }\r\n return prevPageVisitData;\r\n }\r\n /**\r\n * Stops timing of current page, if exists.\r\n * @returns {IPageVisitData} Page visit data (including duration) of pageName from call to start, if exists. Null if not.\r\n */\r\n function stopPageVisitTimer() {\r\n var prevPageVisitData = null;\r\n try {\r\n if (utlCanUseSessionStorage()) {\r\n // Define end time of page's visit\r\n var pageVisitEndTime = dateNow();\r\n // Try to retrieve page name and start time from session storage\r\n var pageVisitDataJsonStr = utlGetSessionStorage(logger, prevPageVisitDataKeyName);\r\n if (pageVisitDataJsonStr && hasJSON()) {\r\n // if previous page data exists, set end time of visit\r\n prevPageVisitData = getJSON().parse(pageVisitDataJsonStr);\r\n prevPageVisitData[_DYN_PAGE_VISIT_TIME /* @min:%2epageVisitTime */] = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;\r\n // Remove data from storage since we already used it\r\n utlRemoveSessionStorage(logger, prevPageVisitDataKeyName);\r\n }\r\n }\r\n }\r\n catch (e) {\r\n _warnToConsole(logger, \"Stop page visit timer failed: \" + dumpObj(e));\r\n prevPageVisitData = null;\r\n }\r\n return prevPageVisitData;\r\n }\r\n return {\r\n trackPreviousPageVisit: function (currentPageName, currentPageUrl) {\r\n try {\r\n // Restart timer for new page view\r\n var prevPageVisitTimeData = restartPageVisitTimer(currentPageName, currentPageUrl);\r\n // If there was a page already being timed, track the visit time for it now.\r\n if (prevPageVisitTimeData) {\r\n pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData[_DYN_PAGE_VISIT_TIME /* @min:%2epageVisitTime */]);\r\n }\r\n }\r\n catch (e) {\r\n _warnToConsole(logger, \"Auto track page visit time failed, metric will not be collected: \" + dumpObj(e));\r\n }\r\n },\r\n // Expose for backward compatibility with tests\r\n _logger: logger,\r\n pageVisitTimeTrackingHandler: pageVisitTimeTrackingHandler\r\n };\r\n}\r\n//# sourceMappingURL=PageVisitTimeManager.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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.
|
|
2
|
+
* Application Insights JavaScript SDK - Web Analytics, 3.4.0-nightlybeta3.2507-23
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -7,19 +7,23 @@
|
|
|
7
7
|
import { dateTimeUtilsDuration } from "@microsoft/applicationinsights-common";
|
|
8
8
|
import { _throwInternal } from "@microsoft/applicationinsights-core-js";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Factory function to create a Timing instance.
|
|
11
|
+
* @param logger - Diagnostic logger
|
|
12
|
+
* @param name - Name identifier for timing operations
|
|
13
|
+
* @returns A new ITiming instance.
|
|
14
|
+
* @internal
|
|
11
15
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
export function createTiming(logger, name) {
|
|
17
|
+
var _events = {};
|
|
18
|
+
var timing = {
|
|
19
|
+
action: null,
|
|
20
|
+
start: function (name) {
|
|
17
21
|
if (typeof _events[name] !== "undefined") {
|
|
18
22
|
_throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 62 /* _eInternalMessageId.StartCalledMoreThanOnce */, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
|
|
19
23
|
}
|
|
20
24
|
_events[name] = +new Date;
|
|
21
|
-
}
|
|
22
|
-
|
|
25
|
+
},
|
|
26
|
+
stop: function (name, url, properties, measurements) {
|
|
23
27
|
var start = _events[name];
|
|
24
28
|
if (isNaN(start)) {
|
|
25
29
|
_throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 63 /* _eInternalMessageId.StopCalledWithoutStart */, "stop was called without a corresponding start.", { name: name, key: name }, true);
|
|
@@ -27,13 +31,12 @@ var Timing = /** @class */ (function () {
|
|
|
27
31
|
else {
|
|
28
32
|
var end = +new Date;
|
|
29
33
|
var duration = dateTimeUtilsDuration(start, end);
|
|
30
|
-
|
|
34
|
+
timing.action(name, url, duration, properties, measurements);
|
|
31
35
|
}
|
|
32
36
|
delete _events[name];
|
|
33
37
|
_events[name] = undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
export { Timing };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return timing;
|
|
41
|
+
}
|
|
39
42
|
//# sourceMappingURL=Timing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timing.js.map","sources":["Timing.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { dateTimeUtilsDuration } from \"@microsoft/applicationinsights-common\";\r\nimport { _throwInternal } from \"@microsoft/applicationinsights-core-js\";\r\n/**\r\n *
|
|
1
|
+
{"version":3,"file":"Timing.js.map","sources":["Timing.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { dateTimeUtilsDuration } from \"@microsoft/applicationinsights-common\";\r\nimport { _throwInternal } from \"@microsoft/applicationinsights-core-js\";\r\n/**\r\n * Factory function to create a Timing instance.\r\n * @param logger - Diagnostic logger\r\n * @param name - Name identifier for timing operations\r\n * @returns A new ITiming instance.\r\n * @internal\r\n */\r\nexport function createTiming(logger, name) {\r\n var _events = {};\r\n var timing = {\r\n action: null,\r\n start: function (name) {\r\n if (typeof _events[name] !== \"undefined\") {\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 62 /* _eInternalMessageId.StartCalledMoreThanOnce */, \"start was called more than once for this event without calling stop.\", { name: name, key: name }, true);\r\n }\r\n _events[name] = +new Date;\r\n },\r\n stop: function (name, url, properties, measurements) {\r\n var start = _events[name];\r\n if (isNaN(start)) {\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 63 /* _eInternalMessageId.StopCalledWithoutStart */, \"stop was called without a corresponding start.\", { name: name, key: name }, true);\r\n }\r\n else {\r\n var end = +new Date;\r\n var duration = dateTimeUtilsDuration(start, end);\r\n timing.action(name, url, duration, properties, measurements);\r\n }\r\n delete _events[name];\r\n _events[name] = undefined;\r\n }\r\n };\r\n return timing;\r\n}\r\n//# sourceMappingURL=Timing.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"}
|