Cookie consent
Google Analytics cookies: what _ga and _ga_ID do and when you need consent
By the Kiescy teamUpdated 6 min readChecked against the official text on
Google Analytics 4 uses two first-party cookies on your domain to count visitors and sessions. They're small, but they're the reason most cookie banners exist: in Europe, setting them without the visitor's consent breaks the cookie rules.
This guide explains what each cookie holds, how long it lasts, what changes when a visitor says no, and how to set GA4 up so it waits for your banner. If you want the wider legal question, see is Google Analytics GDPR compliant.
The short version
Google Analytics 4 sets two cookies: _ga, which tells one visitor from another, and _ga_<container-id>, which keeps the session state. Both last 2 years by default and are renewed on every visit. They're analytics cookies, not strictly necessary ones, so visitors in the EU and UK must agree before they're set. Use Google Consent Mode or a banner that blocks the GA script until the visitor allows analytics.
Words you'll see in this guide (4)
- _ga:
- GA4's main cookie. It holds a random client ID so Analytics can tell returning visitors from new ones.
- _ga_<container-id>:
- A second cookie named after your measurement ID (for example _ga_ABC123XYZ). It keeps the session state: when it started and how many sessions there have been.
- First-party cookie:
- A cookie set on your own domain. GA4's cookies are first-party, but they still send data to Google.
- Consent Mode:
- Google's way for your banner to tell its tags what the visitor allowed, through the signals analytics_storage, ad_storage, ad_user_data and ad_personalization.
On this page
Do Google Analytics cookies need consent?
In the EU and UK, yes. The cookie rule (Article 5(3) of the ePrivacy Directive, and PECR in the UK) allows cookies without consent only when they're strictly necessary for a service the visitor asked for. Counting visitors helps you, not the visitor, so _ga and _ga_<ID> need consent first.
| Where your visitors are | What you need |
|---|---|
| EU and EEA | Opt-in before the cookies are set |
| United Kingdom | Opt-in before the cookies are set (the Data (Use and Access) Act 2025 adds some analytics exemptions, but only once the relevant provisions are in force and only for limited statistics) |
| United States | Usually no consent first; say in your privacy policy that you use Google Analytics, and honour opt-outs where state laws apply |
| India (DPDP Act) | Consent for processing not covered by a legitimate use; analytics is safest behind consent |
Turning on IP anonymisation or shortening the cookie lifetime doesn't change this. GA4 doesn't log IP addresses anyway; the cookie itself is what needs consent.
What happens when a visitor says no
It depends on how GA waits:
- Blocked by the banner (basic mode): the GA script doesn't load, so there are no cookies and no requests to Google. You get no data for that visitor.
- Consent Mode, advanced: the tag loads, but with
analytics_storagedenied it sets no cookies and sends cookieless pings. Google uses those to model the missing traffic in GA4. Some EU regulators question whether cookieless pings are fine without consent, so check what your market expects.
Basic vs advanced Consent Mode compares the two in detail.
From 15 June 2026, Google changed how Google Ads data from the GA tag is controlled: Consent Mode's ad_storage is now the single control for Google Ads cookies and identifiers sent from the Google tag, and the Google Signals setting only controls whether behavioural data is linked in reports. If GA and Google Ads share a tag, your banner's advertising choice now decides the Ads cookies.
How to make Google Analytics wait for consent
With Kiescy
Kiescy blocks googletagmanager.com, google-analytics.com and analytics.google.com in the analytics category by default, so GA4's script waits until the visitor allows analytics. It also sends Consent Mode v2 defaults (all four signals denied in the EU, UK and Switzerland) and an update when the visitor chooses. Put Kiescy's script first in <head>, before the Google tag, and there's nothing else to change.
With gtag.js by hand
Set the default before the Google tag loads, then update it from your banner:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
analytics_storage: 'denied',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
wait_for_update: 500
});
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
// When the visitor allows analytics:
gtag('consent', 'update', { analytics_storage: 'granted' });Order matters: the default must run before the Google tag, or GA sets its cookies before your default arrives. How to implement Consent Mode v2 covers Google Tag Manager, WordPress and Shopify, and how to check Consent Mode v2 shows how to confirm it.
What to put in your cookie and privacy policy
List both cookies by name under analytics, with their purpose and lifetime, and name Google as the provider. In your privacy policy, say you use Google Analytics, what it measures, that it runs only with consent where required, and how to change your choice. The free cookie policy generator has a Google Analytics preset that fills the cookie table for you, and GDPR cookie categories explains why GA belongs under analytics.
How to check what GA sets
- Open your site in a private window and open DevTools → Application → Cookies.
- Before choosing anything in the banner, there should be no
_gaor_ga_cookie. - In Network, filter for
collect: no requests to google-analytics.com yet (unless you chose advanced Consent Mode, where you'll see pings without cookies). - Accept analytics. Both cookies should now appear, and page views should reach GA4's Realtime report.
Our step-by-step guide to checking which cookies a website sets covers Chrome, Firefox and Safari.
Questions
What is the _ga cookie?
It's Google Analytics' main cookie. It holds a random client ID that lets GA4 tell returning visitors from new ones. It lasts 2 years by default.
Is _ga a necessary cookie?
No. It's an analytics cookie. In the EU and UK it needs the visitor's consent before it's set.
Does GA4 still use _gid?
A plain GA4 setup uses only _ga and _ga_<container-id>. _gid and _gat came from Universal Analytics, which stopped processing data in 2023 (and 2024 for Analytics 360).
Can I use Google Analytics without cookies?
With Consent Mode advanced, GA4 sends cookieless pings when analytics is denied and models the gaps. It doesn't give you full data, and some regulators still question the pings.
Why do my GA cookies disappear after a week in Safari?
Safari limits cookies set by JavaScript to 7 days, so returning Safari visitors often show up as new users.
Sources
The facts in this guide come from these official sources, last checked on . We review the guide whenever they change.
Does GA set cookies before consent?
Our free check opens your site as a first-time visitor and lists every cookie and Google request made before anyone clicks your banner.
Open the free toolThis guide explains the law in general terms and isn't legal advice. Laws change and how they apply depends on your situation; for high-risk processing, ask a lawyer.