Application insight - Manage and drive Sessions

Ferro, Enrica 20 Reputation points
2023-03-22T07:51:56.5166667+00:00

Hi everyone,
I started to work with Application Insight and Sessions. I need to drive my session without referring on cookies.
There is any way to control the beginning and the end of a session in the code by AI method?

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,661 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-03-24T00:25:58.47+00:00

    To run Application Insights without referring to cookies, you can use the disableCookiesUsage configuration option which is available in the [javascript SDK]. When this option is set to true, the SDK won't store or read any data from cookies, and the User and Session cookies will be disabled. You can also use the isStorageUseDisabled configuration option to disable the SDK from storing or reading any data from local and session storage.


    EDIT 2023 Apr 6: To track specific users, overwrite the user_Id field when the user starts a new session. By default, Application Insights randomly generates this value, see Managing personal data in Log Analytics and Application Insights.

    TelemetryClient telemetryClient = new TelemetryClient();
    telemetryClient.Context.User.Id = "unique_user_id";
    

    Once you've set the user_id, you can query for the session in Application Insights, for example counting the number of user sessions in the last 24 hours.

    requests
    | where timestamp > ago(1d)
    | summarize numSessions_24h = dcount(user_Id) by user_Id
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.