[main] fix startTime timestamp (#2183)
This commit is contained in:
Родитель
36856e1b80
Коммит
d0f2a3508b
|
@ -21,7 +21,7 @@ import {
|
|||
isNullOrUndefined, isString, isUndefined, mergeEvtNamespace, onConfigChange, safeGetCookieMgr, strUndefined, throwError
|
||||
} from "@microsoft/applicationinsights-core-js";
|
||||
import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
|
||||
import { getPerformance, isError, objDeepFreeze, objDefine, scheduleTimeout, strIndexOf } from "@nevware21/ts-utils";
|
||||
import { isError, objDeepFreeze, objDefine, scheduleTimeout, strIndexOf } from "@nevware21/ts-utils";
|
||||
import { IAppInsightsInternal, PageViewManager } from "./Telemetry/PageViewManager";
|
||||
import { PageViewPerformanceManager } from "./Telemetry/PageViewPerformanceManager";
|
||||
import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
|
||||
|
@ -285,22 +285,11 @@ export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights
|
|||
if (doc) {
|
||||
pageView.refUri = pageView.refUri === undefined ? doc.referrer : pageView.refUri;
|
||||
}
|
||||
|
||||
let perf = getPerformance();
|
||||
// Access the performance timing object
|
||||
const navigationEntries = (perf && perf.getEntriesByType && perf.getEntriesByType("navigation"));
|
||||
|
||||
// Edge Case the navigation Entries may return an empty array and the timeOrigin is not supported on IE
|
||||
if (navigationEntries && navigationEntries[0] && !isUndefined(perf.timeOrigin)) {
|
||||
// Get the value of loadEventStart
|
||||
const loadEventStart = (navigationEntries[0] as PerformanceNavigationTiming).loadEventStart;
|
||||
pageView.startTime = new Date(perf.timeOrigin + loadEventStart);
|
||||
} else {
|
||||
if (isNullOrUndefined(pageView.startTime)) {
|
||||
// calculate the start time manually
|
||||
let duration = ((properties || pageView.properties || {}).duration || 0);
|
||||
pageView.startTime = new Date(new Date().getTime() - duration);
|
||||
}
|
||||
|
||||
let telemetryItem = createTelemetryItem<IPageViewTelemetryInternal>(
|
||||
pageView,
|
||||
PageView.dataType,
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
IAppInsightsCore, IDiagnosticLogger, IProcessTelemetryUnloadContext, ITelemetryUnloadState, _eInternalMessageId, _throwInternal,
|
||||
arrForEach, dumpObj, eLoggingSeverity, getDocument, getExceptionName, getLocation, isNullOrUndefined
|
||||
} from "@microsoft/applicationinsights-core-js";
|
||||
import { ITimerHandler, isWebWorker, scheduleTimeout } from "@nevware21/ts-utils";
|
||||
import { ITimerHandler, getPerformance, isUndefined, isWebWorker, scheduleTimeout } from "@nevware21/ts-utils";
|
||||
import { PageViewPerformanceManager } from "./PageViewPerformanceManager";
|
||||
|
||||
/**
|
||||
|
@ -35,6 +35,7 @@ export class PageViewManager {
|
|||
let queueTimer: ITimerHandler = null;
|
||||
let itemQueue: Array<() => boolean> = [];
|
||||
let pageViewPerformanceSent: boolean = false;
|
||||
let firstPageViewSent: boolean = false;
|
||||
let _logger: IDiagnosticLogger;
|
||||
|
||||
if (core) {
|
||||
|
@ -95,6 +96,24 @@ export class PageViewManager {
|
|||
let location = getLocation();
|
||||
uri = pageView.uri = location && location.href || "";
|
||||
}
|
||||
|
||||
if (!firstPageViewSent){
|
||||
let perf = getPerformance();
|
||||
// Access the performance timing object
|
||||
const navigationEntries = (perf && perf.getEntriesByType && perf.getEntriesByType("navigation"));
|
||||
|
||||
// Edge Case the navigation Entries may return an empty array and the timeOrigin is not supported on IE
|
||||
if (navigationEntries && navigationEntries[0] && !isUndefined(perf.timeOrigin)) {
|
||||
// Get the value of loadEventStart
|
||||
const loadEventStart = (navigationEntries[0] as PerformanceNavigationTiming).loadEventStart;
|
||||
pageView.startTime = new Date(perf.timeOrigin + loadEventStart);
|
||||
} else {
|
||||
// calculate the start time manually
|
||||
let duration = ((customProperties || pageView.properties || {}).duration || 0);
|
||||
pageView.startTime = new Date(new Date().getTime() - duration);
|
||||
}
|
||||
firstPageViewSent = true;
|
||||
}
|
||||
|
||||
// case 1a. if performance timing is not supported by the browser, send the page view telemetry with the duration provided by the user. If the user
|
||||
// do not provide the duration, set duration to undefined
|
||||
|
|
|
@ -47,6 +47,11 @@ export interface IPageViewTelemetry extends IPartC {
|
|||
* iKey String - custom defined iKey.
|
||||
*/
|
||||
iKey?: string;
|
||||
|
||||
/**
|
||||
* Time first page view is triggered
|
||||
*/
|
||||
startTime?: Date;
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,5 +67,4 @@ export interface IPageViewTelemetryInternal extends IPageViewTelemetry {
|
|||
* Version of the part B schema, todo: set this value in trackpageView
|
||||
*/
|
||||
ver?: string;
|
||||
startTime?: Date;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче