Analytics Data API best practice
This page is a work in progress.
You can access GOV.UK GA4 data via the Analytics Data 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 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.