DEV Community

関聖矢
関聖矢

Posted on

Why Your GA4 BigQuery Session Count Doesn't Match the GA4 UI (and How to Get a Gap You Can Explain)

Sooner or later, someone in your organisation opens the GA4 interface, looks at the session count, looks at your BigQuery report, and asks the question: "Why don't these match?"

I get asked this by clients roughly once a month. The honest answer is that the two numbers will probably never match exactly — but they should be close, and the gap should be stable. When they aren't, it's almost always one of four causes, and three of them are fixable in your query.

Cause 1: You're counting ga_session_id by itself

This is the big one. ga_session_id looks like a session identifier, but it isn't unique. It's a timestamp-derived value, and different users routinely share the same one. Count it on its own and you silently merge strangers' sessions together — your count comes out too low, by an amount that varies day to day.

A session ID in the GA4 export only becomes unique when you combine it with the user:

CONCAT(
  user_pseudo_id, '.',
  CAST(
    (SELECT value.int_value FROM UNNEST(event_params)
     WHERE key = 'ga_session_id') AS STRING)
) AS session_id
Enter fullscreen mode Exit fullscreen mode

And the daily count built on it:

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 session_count
FROM `project.dataset.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131'
GROUP BY event_date
ORDER BY event_date;
Enter fullscreen mode Exit fullscreen mode

Two details that matter:

  • The separator. Use . (or any consistent character) between the two parts. Without it, user 12 + session 345 and user 123 + session 45 can collide into the same string.
  • user_pseudo_id, not user_id. The export's user_pseudo_id is the cookie/device-based ID GA4 actually used. If your site sets user_id and you want cross-device sessions, that's a deliberate modelling choice — make it consciously, not by accident.

Cause 2: Intraday tables are sneaking into your wildcard

events_* matches more than the finished daily tables. If your project also has streaming export, the wildcard can pick up events_intraday_* data — provisional events that may still change, be deduplicated, or be replaced when the daily table lands.

For exploration that's fine. For a number you report as final, restrict yourself to completed daily tables and a date range that's fully closed. A session count that "keeps changing for yesterday" is usually this, not a GA4 bug.

Cause 3: Time zones don't line up

The GA4 UI reports in the property's time zone. The export's event_date is also in the property time zone — but the moment you start grouping by your own timestamp math (DATE(TIMESTAMP_MICROS(event_timestamp)) and friends), you're grouping in whatever time zone that expression resolves to, often UTC.

If your property is in, say, Asia/Tokyo and your query groups in UTC, sessions near midnight land on different days in the two systems. The monthly total may nearly agree while every daily number looks off. Pick one time zone — the property's — and convert explicitly:

DATE(TIMESTAMP_MICROS(event_timestamp), 'Asia/Tokyo') AS session_date
Enter fullscreen mode Exit fullscreen mode

This cause is easy to miss because it produces a plausible-looking report. Nothing errors; the numbers are just quietly shifted.

Cause 4: You expect an exact match

Even with all three fixes above, a small gap remains, and that's expected. The GA4 interface applies its own processing on top of the same underlying events — things like its handling of late-arriving data and (in larger properties) the difference between the UI's estimation methods and your exact count over raw events.

In my experience the healthy end state looks like this:

  • The gap is small — typically low single digits percent.
  • The gap is stable — roughly the same size and direction every day.
  • You can name the reason for most of it.

A gap that moves around — 2% on Monday, 15% on Tuesday — is the real warning sign. That pattern points back to causes 1–3, not to "GA4 just being GA4."

Putting it together: define the session once

If you find yourself pasting the CONCAT(user_pseudo_id, ...) expression into every query, promote it into a staging view so the definition exists in exactly one place:

CREATE OR REPLACE VIEW `project.staging.stg_sessions` AS
SELECT
  event_date,
  CONCAT(
    user_pseudo_id, '.',
    CAST((SELECT value.int_value FROM UNNEST(event_params)
          WHERE key = 'ga_session_id') AS STRING)
  ) AS session_id,
  user_pseudo_id,
  (SELECT value.int_value FROM UNNEST(event_params)
   WHERE key = 'ga_session_number') AS ga_session_number,
  collected_traffic_source.manual_source AS source,
  collected_traffic_source.manual_medium AS medium
FROM `project.dataset.events_*`
WHERE event_name = 'session_start';
Enter fullscreen mode Exit fullscreen mode

Every downstream query then counts session_id from the view, and when the definition ever needs to change, it changes once.

The short version

  1. Never count ga_session_id alone — it's user_pseudo_id + '.' + ga_session_id.
  2. Keep intraday tables out of anything you report as final.
  3. Group dates in the property's time zone, explicitly.
  4. Aim for a small, stable, explainable gap — not zero.

The session definition above is one of 20 templates in my GA4 × BigQuery SQL pack. Three of them (including this session template) are in the free sample if you want the .sql files rather than copy-pasting from articles; the full pack adds the revenue, customer and cost-monitoring templates built on the same definitions.

If your gap still moves around after these four checks, paste your query (minus anything sensitive) in the comments — this is usually diagnosable from the query alone.

Top comments (0)