Session duration is the elapsed time from a browsing session’s first recorded event to its last. It turns event-level app activity into a session-level measure, so questions about browsing time can be answered without modeling every rapid app open and close. section 12.5.1
Build the metric from cleaned event data:
- Check whether a session ID can occur for multiple users; group by both user ID and session ID when needed to keep sessions distinct. section 12.5.1
- For each session, take the minimum timestamp as its start and the maximum as its end, then subtract start from end and convert to minutes. section 12.5.1
- Aggregate session durations per user with a median to create an average-session-length feature for user-level analysis. section 12.5.2
- Record cleaning choices: removing Closed events changes the reconstructed duration distribution and can prevent an exact match with an earlier analysis. section 12.5.1
Reading the distribution
A histogram of users’ typical session durations shows most sessions below two minutes, alongside a long tail that includes sessions longer than ten minutes. This makes unusually long browsing behavior visible rather than hiding it inside a single overall average. section 12.5.1
sessions = (
app_data_reduced
.groupby(["user_id", "session_id"])
.agg(start=("timestamp", "min"),
end=("timestamp", "max"))
.reset_index()
.assign(
duration_mins=lambda _df: (_df["end"] - _df["start"]).dt.seconds/60
)
)
sessions.head()
This transformation produces one row per user session with start time, end time, and duration in minutes. section 12.5.1
