ApplicationInsights-JS
ApplicationInsights-JS copied to clipboard
[BUG] Custom properties added with addTelemetryInitializer are ignored for first PageVisitTime track event
Description/Screenshot When I set autoTrackPageVisitTime to true in the ApplicationInsights configuration, the first payload for PageVisitTime does not contain any custom parameters that I added using the addTelemetryInitialiser method.
Steps to Reproduce init telemetry with custom properties:
const appInsights = new ApplicationInsights({
config: {
appId: 'test-bug-report',
connectionString: this.connectionString,
autoTrackPageVisitTime: true,
},
});
appInsights.loadAppInsights();
appInsights.trackPageView();
appInsights.addTelemetryInitializer(this.enrichTelemetry);
///
enrichTelemetry = (item: ITelemetryItem): void => {
if (item.tags == null) {
item.tags = [];
}
item.tags['ai.cloud.role'] = 'test-bug-report-roleName';
item.tags['ai.cloud.roleInstance'] = 'test-bug-report-roleInstance';
};
then visit your application and see on first track request in network section.
- OS/Browser: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'
- SDK Version [e.g. 22]: "@microsoft/applicationinsights-web": "^3.0.4"
- How you initialized the SDK:
Expected behavior
Additional context Add any other context about the problem here.
Yes, this is because you are adding the telemetry initializer "AFTER" you are triggering the page view
flip the order of these 2 functions
appInsights.trackPageView();
appInsights.addTelemetryInitializer(this.enrichTelemetry);
to
appInsights.addTelemetryInitializer(this.enrichTelemetry);
appInsights.trackPageView();
Thanks. That helps