Options to Track Authenticated Users

There are two options to track authenticated users.

Option 1

  • Set EnableAuthenticationTrackingJavaScript configuration to true in appsettings.json. With this, the default TelemetryInitializers will set the Auth Id with the username for Page View events.
  • Implement a TelemetryInitializer to set the Auth Id context property from the back-end side for all the other events.
  • Register the custom TelemetryInitializer and move app.UseAuthentication() to the position in the pipeline where you want to track.

Option 2

  • Use appInsights.setAuthenticatedUserContext(userName, null, true) to set the ai_authuser cookie on the client-side.
  • Implement a TelemetryInitializer to read the cookie on the backend-side and set the Auth Id context property
  • Register the custom TelemetryInitializer

Application Insights API for custom events and metrics - Azure Monitor | Microsoft Docs

Comments

Leave a Comment

All fields are required. Your email address will not be published.