You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to track what a user does over time, Application Insights needs
33
+
an ID for each user or session. Include the following IDs in every
34
+
custom event or page view.
29
35
30
-
In order to track what a user does over time, Application Insights needs an ID for each user or session. Include the following IDs in every custom event or page view.
31
36
- Users, Funnels, Retention, and Cohorts: Include user ID.
32
37
- Sessions: Include session ID.
33
38
34
39
If your app is integrated with the [JavaScript SDK](https://docs.microsoft.com/azure/application-insights/app-insights-javascript#set-up-application-insights-for-your-web-page), user ID is tracked automatically.
35
40
36
41
## Choosing user IDs
37
42
38
-
User IDs should persist across user sessions to track how users behave over time. There are various approaches for persisting the ID.
43
+
User IDs should persist across user sessions to track how users behave
44
+
over time. There are various approaches for persisting the ID.
45
+
39
46
- A definition of a user that you already have in your service.
40
47
- If the service has access to a browser, it can pass the browser a cookie with an ID in it. The ID will persist for as long as the cookie remains in the user's browser.
41
48
- If necessary, you can use a new ID each session, but the results about users will be limited. For example, you won't be able to see how a user's behavior changes over time.
@@ -46,50 +53,92 @@ If the ID contains personally identifying information about the user, it is not
46
53
47
54
## ASP.NET apps: Setting the user context in an ITelemetryInitializer
48
55
49
-
Create a telemetry initializer, as described in detail [here](https://docs.microsoft.com/azure/application-insights/app-insights-api-filtering-sampling#add-properties-itelemetryinitializer), and set the Context.User.Id and the Context.Session.Id.
56
+
Create a telemetry initializer, as described in detail [here](https://docs.microsoft.com/azure/application-insights/app-insights-api-filtering-sampling#add-properties-itelemetryinitializer). Pass the session ID through the request telemetry, and set the Context.User.Id and the Context.Session.Id.
50
57
51
58
This example sets the user ID to an identifier that expires after the session. If possible, use a user ID that persists across sessions.
52
59
53
-
```csharp
54
-
55
-
usingSystem;
56
-
usingSystem.Web;
57
-
usingMicrosoft.ApplicationInsights.Channel;
58
-
usingMicrosoft.ApplicationInsights.Extensibility;
60
+
### Telemetry initializer
59
61
60
-
namespaceMvcWebRole.Telemetry
62
+
```csharp
63
+
usingSystem;
64
+
usingSystem.Web;
65
+
usingMicrosoft.ApplicationInsights.Channel;
66
+
usingMicrosoft.ApplicationInsights.Extensibility;
67
+
68
+
namespaceMvcWebRole.Telemetry
69
+
{
70
+
/*
71
+
* Custom TelemetryInitializer that sets the user ID.
0 commit comments