Skip to content

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
  1. The GA4 cookies
  2. Do they need consent
  3. When a visitor says no
  4. Set it up
  5. Your policies
  6. Test it
  7. Questions
  8. Sources

The cookies Google Analytics 4 sets

CookieWhat it's forDefault lifetime
_gaTells visitors apart with a random client ID2 years, renewed on each visit
_ga_<container-id>Keeps the session state for your property2 years, renewed on each visit

Google's developer guide says you can change the cookie lifetime, domain and name in the tag's settings. Browsers have the last word, though: Chrome caps any cookie at 400 days, and Safari limits cookies set by JavaScript to 7 days, so in practice a returning Safari visitor after a week counts as new.

Older guides list _gid, _gat and __utma-style cookies. Those belonged to Universal Analytics and the older ga.js library. A plain GA4 setup uses only the two cookies above. If you see others, they usually come from Google Ads, a GTM tag you forgot, or an old snippet still on some pages.

Example

A London bakery checks its cookie list and finds _ga, _ga_7KQ2… and _gcl_au. The first two are Analytics. _gcl_au comes from Google Ads conversion linking, which belongs in the advertising category, not analytics.

What happens when a visitor says no

Diagram: the page loads with the analytics script in the head, the consent banner holds it back with no cookies or requests. If the visitor allows the category, the script runs and cookies like _ga are set. If they reject, the script never runs and nothing is sent to the vendor.Page loadsPixel / analytics script in <head>Consent banner holds it backScript waits, no cookies, no requestAllows categoryScript runsRejectsScript never runsCookies such as _ga or_fbp are set from hereNo tracker cookies,nothing sent to the vendor
With a blocking banner, the GA script doesn't run at all until analytics is allowed.

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_storage denied 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:

gtag.js consent default and update
<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

  1. Open your site in a private window and open DevTools → Application → Cookies.
  2. Before choosing anything in the banner, there should be no _ga or _ga_ cookie.
  3. 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).
  4. 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.

  1. Google Analytics Help: [GA4] Cookie usage on websites
  2. Google for Developers: Google Analytics cookie usage on websites
  3. Google Analytics Help: changes to Google Ads data controls in Google Analytics (15 June 2026)
  4. ePrivacy Directive 2002/58/EC, Article 5(3) (EUR-Lex)

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 tool

This 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.

Keep reading

All guides

Get compliant this afternoon, not this quarter.

Set up your policies, banner and request form in one place. Free while Kiescy is in early access.