Sub topic 6
How GA4 defines a session
This chapter assumes you know what an event and an event parameter are, which the earlier chapters cover. It also assumes you can read a GA4 report. You should be comfortable with the idea that a session is one visit. Here you will see how GA4 decides when that visit starts and ends, and which events and numbers depend on that decision.
A session is a group of events
GA4 has no separate "session" hit type. A session is a set of events from one user that share a session identifier and occur close together in time. Everything that looks like a session in a report is derived from those events.
Two pieces of event data define a session:
session_startis an event that GA4 generates automatically when a user opens a page or screen and has no active session.ga_session_idis an event parameter that holds the session's identifier. On the web it is the Unix timestamp, in seconds, of the moment the session began. Every later event in the same session carries the same value.
ga_session_number is a companion parameter. It counts how many sessions this browser has had, starting at 1.
On a user's first ever visit, GA4 also generates a first_visit event. Both first_visit and session_start appear for that visit, but they mean different things. first_visit happens once per browser, and session_start happens once per session.
When a session starts and ends
A session starts when an event arrives and no session is active. A session stays active as long as events keep arriving. It ends when no event has arrived for the session timeout. The timeout is 30 minutes by default.
The timeout counts from the last event, not from the start of the session. Each new event resets the clock. A user who stays on your site for three hours and triggers an event every few minutes is still in one session.
An expired session is not a distinct state that GA4 records. Nothing is sent when a session ends. GA4 learns that a session ended only because a later event arrives with a new ga_session_id, or because no later event arrives at all.
Changing the timeout
You can change the timeout for a web data stream. In Admin, open the data stream, choose Configure tag settings, then Show all, then Adjust session timeout. The allowed range is 5 minutes to 7 hours 55 minutes.
Choose a longer timeout when your users read long articles or watch long videos with few events. Choose a shorter one when you want brief pauses to count as separate visits. The change affects only sessions formed after you save it. It does not rewrite history.
What does not end a session in GA4
Many analysts arrive from Universal Analytics (UA), where several things ended a session. GA4 follows fewer rules, and this affects how you compare numbers.
| Situation | Universal Analytics | GA4 |
|---|---|---|
| 30 minutes with no activity | New session | New session (default timeout, adjustable) |
| Midnight passes | New session | Same session continues |
| Campaign or traffic source changes mid-visit | New session | Same session continues |
| User opens a second tab on your site | Same session | Same session |
| User clears cookies or switches browser | New session | New session |
Two consequences follow.
First, a session can span two calendar days. Event-level metrics such as event count are reported on the date of each event, so date breakdowns can split one session across two days.
Second, a session keeps its original source even if the user returns through a different link without waiting out the timeout. If someone lands from a search result, leaves for a payment provider, and comes back within 30 minutes, the return does not create a new session. The visit keeps the original source and medium. A payment provider that is not excluded can therefore cost you attribution only in the sense that traffic after the timeout looks like a fresh visit from that provider. Check the unwanted referrals list in your data stream settings for this case.
How the session identifier is stored
On the web, gtag.js stores session state in a first-party cookie named _ga_<MEASUREMENT-ID-SUFFIX>. The cookie holds the session ID and the session number, among other values. Every tab in the same browser reads the same cookie, which is why several tabs share one session.
Deleting the cookie, using a private window, or switching browsers means no session state is found. The next event starts a new session. A user who moves from a phone to a laptop is always a new session on the second device.
You can read the current session ID in the page with the get command:
// Replace G-XXXXXXXXXX with your measurement ID.
// gtag.js must already be loaded on the page.
gtag('get', 'G-XXXXXXXXXX', 'session_id', (sessionId) => {
console.log('Current ga_session_id:', sessionId);
});This is useful when you need to join GA4 data to your own system, for example by storing the session ID with a form submission. The callback receives undefined if no session exists yet, which happens before any event has been sent or when consent blocks storage.
Sessions and the Measurement Protocol
Events that you send from a server with the Measurement Protocol are only tied to a browser visit if you include the right session parameters. Include session_id with the value from the user's cookie, and include engagement_time_msec so the event contributes engagement time.
If you omit session_id, the event is not attached to the user's website session. It can then show up in the Events report, but session-based metrics will not count it with the visit it belongs to. This is a frequent cause of server-side purchase events that appear in the Events report but not in session-based views.
Where sessions appear in reports
The session concept feeds several numbers you will use in later chapters:
- Sessions is the number of sessions that began in the selected period. In practice it tracks the number of
session_startevents, but the two figures are computed separately and may not match exactly. - Engaged sessions is the subset of sessions that met an engagement condition. The next chapter defines that condition.
- Session-scoped dimensions, such as session source, session medium, and session default channel group, describe the traffic source of the whole session, taken from its first events.
- Landing page is the page of the first event in a session that carried a page location. A later chapter covers it.
Because engagement rate and bounce rate are ratios with sessions in the denominator, any change to how sessions are counted changes both rates.
Querying sessions with the Data API
You can check the session count and its engaged subset by date with a runReport request. Send this body to properties/PROPERTY_ID:runReport:
{
"dateRanges": [{ "startDate": "7daysAgo", "endDate": "yesterday" }],
"dimensions": [{ "name": "date" }],
"metrics": [
{ "name": "sessions" },
{ "name": "engagedSessions" }
],
"orderBys": [{ "dimension": { "dimensionName": "date" } }]
}Each row holds one day. Compare the two metric values on each row. Engaged sessions can never exceed sessions, because each engaged session is also a session.
Common problems and how to diagnose them
Sessions look inflated
Look for tags that fire on a different domain without cross-domain measurement configured. When a user crosses from www.example.com to shop.example.com or a separate checkout domain, the second domain cannot read the first domain's cookie. GA4 then starts a new session, and the new session often carries a referral source from your own site. Configure cross-domain measurement for your data stream so the session identifier travels in the link.
Sessions look too few
Consent settings can prevent storage of the cookie, so some visits are never recorded. A tag that loads only after the user interacts with the page also misses the earliest part of a session. If the first event fires late, session_start fires late, and the landing page is the page where the tag first loaded.
Session counts differ between reports
Standard reports, explorations, and the Data API can show different session numbers for the same period. Typical reasons are data thresholds, sampling in explorations, and the time that GA4 needs to finish processing recent data. Compare the same date range after processing is complete, and use the same dimensions on both sides.
Practical rules
- Think of a session as "events that share a
ga_session_id", not as a visit with a clear end. - Keep the timeout at the default unless you have a content-based reason to change it, and record any change.
- Include
session_idin Measurement Protocol events that belong to a web visit. - Configure cross-domain measurement before you judge session counts on a multi-domain site.
- Do not compare GA4 session counts directly with UA session counts, because the two products end sessions under different rules.
Exercise
A user lands on your site at 23:50, browses with regular clicks until 00:20 the next day, and arrived from a Google search. They then follow a link from an email newsletter at 00:30 and keep browsing. Assuming the default 30-minute timeout, how many GA4 sessions does this produce, and what is the source of each?
Show answer
The 00:20 to 00:30 gap is 10 minutes, which is less than 30 minutes, and neither midnight nor a source change ends a session in GA4. So the whole visit is one session, which started at 23:50 and carries the Google organic source. The email link does not create a new session. In Universal Analytics, midnight and the campaign change would each have started a new session.
Exercise
A server-side purchase event appears in the Events report, but the sessions metric does not count it with the user's website visit. What parameter is probably missing from the Measurement Protocol request, and where can you read its value in the browser?
Show answer
The session_id parameter is probably missing. In the browser you can read it from the _ga_<ID> cookie, or by calling gtag('get', 'G-XXXXXXXXXX', 'session_id', callback), then pass it to your server.