Track sessions

Session Measurement and Tracking in Mobile and Web Applications

Session measurement is an important metric for product analysis as it allows us to determine how frequently and for how long users interact with our website or application. However, it is important to note that session tracking methods on mobile and web applications have their own peculiarities. When a user starts a session in the application, the SDK recognizes that the application is active, indicating that it has gained focus (when the app is brought into the foreground). If the last recorded activity was more than 10 minutes ago, a Session Start event is sent.

Application activity refers to the period of time when the application is in focus, meaning the application or web page is open and the device screen is active. The focus is lost if the application goes into the background or if another website is opened in the current tab.

We measure the duration of application activity using a technical event called User Engagement (UE). It starts counting the time as soon as the application receives focus and sends the activity counter data to the server.

If, for any reason, the information about the duration of the activity couldn't be sent, it will be sent the next time the application is initialized and has internet access. However, the activity will only be included in devtodev reports if it has been less than 7 days since the session, as events from a previous period more than 7 days ago are ignored.

Thus, we have information about "Session start" and the duration of activity, but there is no specific "Session end" event. All events performed by the user are marked with the session start date in which they occurred (sessionid field in SQL tables)

For mobile applications, it is difficult to determine the beginning and end of a session because users often switch between screens of different applications. If an application on a mobile device receives focus and the last active time (in focus) was more than 10 minutes ago, a new session will be started and an event will be sent to devtodev.

For example, the user opens the application, spends a minute in it, and then puts the application in the background, a Session Start event will be sent to devtodev in the first second. After a minute, when the application goes into the background or is closed, an event with information about the duration of activity (UE) will be sent to the server as the focus is lost.

For web projects, it is not possible to detect when the user closes the page. Therefore, the UE event (duration of activity) is sent to the server every 2 minutes. To minimize the loss of information about the session duration to no more than two minutes in case of session termination, the SDK additionally saves the duration every 5 seconds and will send the information about the last duration upon the next activity. If there is no next session, the information about the last two minutes may be lost.

Let's consider an example where a user opens a webpage, spends 1.5 minutes on it, then opens another page on the site and spends another 1.5 minutes there. In devtodev, a Session Start event will be sent in the first second, and every 5 seconds, information about the activity will be saved. After 2 minutes from the start of the session, a UE event with 2 minutes of activity will be sent to the server, and after the third minute, the activity of 1 minute will be recorded in the Local Storage. Information about this activity will be sent during the next user session. The metric Average session length is calculated from the data obtained from session starts and user activity time during those sessions. It is defined as the sum of the length of all sessions divided by the number of sessions within a given period

In Basic Metrics, Engagement-> Sessions, and other reports, we encounter the following metrics:

Session duration: Shows the average session time of one user. It is calculated as (Total Sessions Length / Number of sessions) averaged by users Number of sessions: Shows the average number of sessions per user. It is calculated as the Number of sessions divided by the Number of users Total daily time spent: Represents the average total time per day spent in the user application. It is calculated as Total Sessions Length divided by the number of Active Users Sessions: Sessions by user shows the average number of sessions made by one user during the period Sessions by user: It shows the average number of sessions made by one user during the period

For the calculation of the necessary metrics:

  • In the SQL wizard, there is a parameter called session.Duration, which is tracked by the UE event. The session.Duration parameter represents the duration of the activity, i.e., the time the application is in focus, and it is not equal to the session duration.

  • sessions.Count is the number of Session Start received from the user

  • Table .sessions has two types of eventtype field in SQL: ss: represents the Session Start event received from the user ue: represents the time that the application was in focus (active), providing information about time parameters and activity duration.

From this data, you can calculate the average session length by dividing the sum of activity lengths from all rows for the desired period by the sum of all session starts for the same period. We recommend using extended time periods to obtain a more reliable result.

Last updated