Sub topic 8
Sessions Are Derived from Events
Prerequisites: You should understand that GA4 collects events and that a user can generate many events while using a website or app. You should also be comfortable reading basic SQL.
A session is a group of events that happen during one period of activity. GA4 does not treat a session as an independent object that you manually create. Instead, it derives sessions from event data.
When a visitor begins using a site or app, GA4 usually records a session_start event. GA4 also assigns a ga_session_id value to the events in that session. In the BigQuery export, a session is commonly identified by combining:
user_pseudo_id, which identifies the browser or app instancega_session_id, which identifies the session for that instance
The same session ID can exist for different users, so the two values must be used together.
How GA4 creates a session
By default, a session ends after 30 minutes without activity. A new event after that inactivity period starts a new session. The session timeout can be changed in a property's data settings.
For example, imagine this event sequence:
| Time | Event | Session |
|---|---|---|
| 09:00 | `page_view` and `session_start` | Session A |
| 09:05 | `view_item` | Session A |
| 09:20 | `add_to_cart` | Session A |
| 09:55 | `purchase` | Session B |
The 35-minute gap between add_to_cart and purchase exceeds the default timeout. Therefore, the purchase belongs to a new session.
A session can contain only one event or many events. It is the time grouping that GA4 derives from event timestamps and session identifiers.
Important session rules
GA4 sessions differ from Universal Analytics sessions in several ways:
- A session can continue across midnight. Midnight alone does not force a new session.
- A campaign or traffic-source change does not automatically start a new session.
- Events sent without the expected session information may be difficult to assign to the intended session.
- A session is not the same as a user. One user can have many sessions.
- A session is not the same as a page view. One session can contain many page views, or none.
A session_start event is useful for identifying the beginning of a session, but counting session_start events is not always the best way to reproduce the Sessions metric. Events can be delayed, filtered, duplicated, or sent with incomplete parameters. For exported data, count distinct combinations of user and session ID.
Counting sessions in BigQuery
The GA4 export stores event parameters in the repeated event_params field. The following query extracts ga_session_id and counts distinct session keys:
SELECT
event_date,
COUNT(DISTINCT CONCAT(
user_pseudo_id,
'.',
CAST((
SELECT value.int_value
FROM UNNEST(event_params)
WHERE key = 'ga_session_id'
) AS STRING)
)) AS sessions
FROM `my-project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
GROUP BY event_date
ORDER BY event_date;The session count can differ from the number shown in the GA4 interface because the interface may apply reporting identity, thresholding, consent modeling, or other processing. Treat the query as a direct view of the exported event data, not as a guaranteed copy of every interface metric.
Exercise
A visitor views a product at 10:00, waits 20 minutes, adds the product to a cart, then waits 40 minutes before purchasing. With the default timeout, how many sessions are represented?
Show answer
Two sessions. The first contains the product view and add-to-cart event. The purchase starts a new session after more than 30 minutes of inactivity.