Skip to main content

Analytics Data API best practice

You can access GOV.UK GA4 data via the Data API.

The Data API can be used to obtain data for a variety of general reporting needs. For data science and more detailed work, we would recommend you consider using the raw GOV.UK GA4 data in BigQuery.

API best practice

Cardinality and sampling

Data extracted from the API can be subject to issues associated with cardinality and sampling.

If you are trying to figure out whether the results of a certain query are impacted by cardinality or sampling, you can use the dataLossFromOtherRow or samplingMetadatas fields in the metadata of the response.

Be particularly careful when using same-day data. GA4 data on GOV.UK takes several hours to be processed, so same-day data is often very unreliable. It is usually better to set your date range to exclude today’s data, unless there is a specific reason you need to look at today.

Quotas

Be aware that API queries are subject to the Google Analytics Data API quotas. If you are querying the API directly, please follow Google’s quota management best practices.

Most usage of GOV.UK GA4 data occurs within work hours. If you have a query set up to run daily, you may want to consider scheduling it to run outside of core work hours to reduce the likelihood of hitting an hourly quota.

Using the GA4 Reports Builder

You can query the Google Analytics Data API data in Google Sheets using the GA4 Reports Builder.

This is subject to the same cardinality, sampling and quota issues detailed above.

This page was last reviewed on 11 December 2024. It needs to be reviewed again on 11 June 2025 .
This page was set to be reviewed before 11 June 2025. This might mean the content is out of date.