Sub topic 11
Linking GA4 to BigQuery
This chapter assumes that you know the GA4 Admin interface, data streams, events, and event parameters. You should also know basic SQL, including SELECT, WHERE, and GROUP BY.
BigQuery is Google's cloud data warehouse. A BigQuery link copies GA4 event data into a Google Cloud project so that you can query detailed data with SQL. The data flow is mainly one way: GA4 sends exported events to BigQuery. BigQuery does not change the reports in GA4.
Create the BigQuery link
Before linking, choose the Google Cloud project that will contain the export dataset. Confirm that you have:
- Editor access to the GA4 property.
- Permission to use the selected Google Cloud project.
- Permission to create a BigQuery dataset and enable required services.
- A billing setup if your BigQuery queries or storage require it.
In GA4, open Admin, then choose BigQuery links under Product links. Select Link, choose the Google Cloud project, and select a dataset location.
The location is the geographic region where BigQuery stores the dataset. Choose it carefully. You generally cannot change a dataset's location after it has been created. Your organization's data-residency rules, query locations, and other data sources may affect this choice.
Next, choose the export options. A daily export creates tables for completed days. A streaming export makes recent events available sooner, but the data may be incomplete or change as processing finishes. A user export is an on-demand export of user data when the property and account support that option.
| Export | Best for | Main limitation |
|---|---|---|
| Daily | Stable reporting and scheduled analysis | Data is available after daily processing |
| Streaming | Near-real-time monitoring | Data can be incomplete or change |
| User | Extracting selected user information | Not a continuous event export |
Review the settings and create the link. GA4 creates a dataset named with the pattern analytics_ followed by the property ID, such as analytics_123456789.
Check the dataset and query events
Use the BigQuery console or the command-line tool to confirm that tables arrived:
bq ls --project_id=my-project analytics_123456789
bq ls --project_id=my-project --max_results=5 analytics_123456789Daily tables use names such as events_20250131. Intraday tables use names such as events_intraday_20250131. The export stores event parameters in a repeated field called event_params. UNNEST converts the repeated values into rows that a query can inspect.
This query counts sessions by day. A session is identified by combining the anonymous user identifier with the ga_session_id event parameter:
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 '20250101' AND '20250131'
GROUP BY event_date
ORDER BY event_date;The wildcard table reads matching daily tables. _TABLE_SUFFIX limits the date range and reduces the data scanned. Always add a date filter when querying a large export.
Exercise
Why should you select the BigQuery dataset location before creating the link?
Show answer
The location controls where the data is stored and generally cannot be changed after the dataset is created.