Analytics cookie · Google Analytics 4
_ga_<container-id> Cookie: What It Is, Who Sets It, and Consent Rules
Last verified 2026-10-16 · Updated 2026-10-17
On this page
- What the _ga_<container-id> cookie does
- Who sets the _ga_<container-id> cookie
- Does the _ga_<container-id> cookie need consent?
- How to block the _ga_<container-id> cookie
- How long the _ga_<container-id> cookie lasts
- Cookies that work with _ga_<container-id>
- Scripts and requests of Google Analytics 4
- _ga_<container-id> cookie FAQs
What the _ga_<container-id> Cookie Does on Your Site
The _ga_<container-id> cookie is a first-party analytics cookie that Google Analytics 4 sets to keep the session state of a single property. The _ga_<container-id> cookie stores the start time of the current session, the number of sessions, and the time of the last hit. Google describes the _ga_<container-id> cookie as "Used to persist session state". The <container-id> part is the measurement ID of the property without the G- prefix, so the measurement ID G-CSJ3Z71FRB writes a cookie named _ga_CSJ3Z71FRB.
The value of the _ga_<container-id> cookie looks like GS2.1.s1712345678$o3$g1$t1712349999$j55$l0$h0. The table explains each part. Google publishes no value format. Read the meanings in the table as an interpretation that Google has not confirmed.
| Part of the value | Meaning |
|---|---|
GS2.1 | The format version of the cookie and a number the Google tag sets from the domain. |
s1712345678 | The start time of the current session as a Unix timestamp in seconds. |
o3 | The session number, here the third session of the browser on the property. |
g1 | Whether the session counts as engaged, with 1 for engaged and 0 for not engaged. |
t1712349999 | The time of the last hit as a Unix timestamp in seconds. |
j55, l0, h0 | Fields that Google documents nowhere, so check them again before you rely on them. |
| Cookie name | _ga_<container-id> |
|---|---|
| Vendor | Google Analytics 4 |
| Company | Google LLC (Google Ireland Limited for visitors in the EU) |
| Category | Analytics |
| Party | First-party |
| Domain | Your own root domain, for example .example.com |
| Set by | JavaScript, through the Google tag (gtag.js) or Google Tag Manager |
| Retention | 2 years (730 days), renewed at every page view |
| Value example | GS2.1.s1712345678$o3$g1$t1712349999$j55$l0$h0 |
| HttpOnly | No |
| Secure | No |
| SameSite | Not set by the Google tag, so browsers apply Lax |
| Cookie Consent category | tracking |
| Privacy Consent vendor category | Analytics (analytics) |
Who Sets the _ga_<container-id> Cookie
Google Analytics 4 sets the _ga_<container-id> cookie through the same Google tag (gtag.js) that writes the _ga cookie, added to the page directly or through Google Tag Manager. Each Google Analytics 4 property on the page writes its own cookie, named after its measurement ID. A site that sends data to 2 properties carries 2 _ga_<container-id> cookies next to a single _ga cookie.
The Google tag writes the cookie with JavaScript on your own domain, which makes the cookie a first-party cookie. Google describes the purpose as keeping the session state, so Google Analytics 4 knows whether a page view belongs to a running session or starts a new session.
Read how Google LLC handles the data in the Google Analytics 4 privacy policy, and sign the Google Ads Data Processing Terms, which cover Google Analytics before you collect data from visitors in the EU or the UK. Both documents appear in the sources at the end of this page.
Does the _ga_<container-id> Cookie Need Consent?
Yes, the _ga_<container-id> cookie needs consent in the EU, needs consent in the UK unless the statistics exception covers your setup, and needs no prior opt-in in California. The table gives the rule for each law.
| Law | Consent before the cookie is set | Opt-out right | Source |
|---|---|---|---|
| EU ePrivacy Directive + GDPR | Required | Withdraw at any time | Article 5(3), ePrivacy Directive |
| UK PECR | Required unless exempt | Withdraw at any time | Regulation 6 and Schedule A1, PECR |
| California CCPA | No general opt-in | None while the vendor acts as a service provider | Cal. Civ. Code 1798.120 |
The consent table describes what each law requires and is not legal advice. Whether a law applies to your site depends on where your visitors are, where your business is based, and how you set up Google Analytics 4, such as Google signals and the data sharing settings of the account.
The ePrivacy Directive requires consent before a site sets the _ga_<container-id> cookie. The General Data Protection Regulation (GDPR) sets the standard for that consent: freely given, specific, informed, and unambiguous.
The UK Privacy and Electronic Communications Regulations (PECR) exempt analytics cookies that produce aggregate statistics to improve the site. The exemption comes from the Data (Use and Access) Act 2025 and took effect on 5 February 2026. The exemption needs clear information for visitors and a simple and free way to object, according to the ICO guidance on the exceptions. The exemption allows no tracking or profiling of individual visitors. The vendor needs to act as your processor, and recordings of individual visitors and advertising purposes stay outside the exemption. The exemption covers the _ga_<container-id> cookie only while Google acts as your processor. Turn off Google signals and the data sharing settings of the account before you rely on the exemption, and check your setup against the ICO guidance.
The California Consumer Privacy Act (CCPA) sets no general opt-in requirement before a site sets the _ga_<container-id> cookie. Visitors get no right to opt out of the _ga_<container-id> cookie while Google Analytics 4 acts as your service provider. The service provider role needs a contract that limits the use of the data to the service for your site.
Read how each law decides which cookies need consent in the EU ePrivacy Directive + GDPR guide, the UK PECR guide, and the California CCPA guide.
How to Block the _ga_<container-id> Cookie Until Visitors Accept
Block the _ga_<container-id> cookie by holding back the Google tag (gtag.js) until the visitor accepts analytics cookies. TermsFeed Free Cookie Consent and TermsFeed Privacy Consent place Google Analytics 4 in the analytics category. Check whether an exemption applies to your own use of Google Analytics 4 in the consent rules for the _ga_<container-id> cookie.
Block the _ga_<container-id> Cookie With TermsFeed Free Cookie Consent
TermsFeed Free Cookie Consent runs a tagged script only after the visitor accepts its category. Change type="text/javascript" to type="text/plain" and add data-cookie-consent="tracking", the Cookie Consent category for analytics cookies. The tagged the Google tag (gtag.js) looks like this.
<script type="text/plain" data-cookie-consent="tracking" async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script type="text/plain" data-cookie-consent="tracking">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
Cookie Consent runs the tagged code after the visitor clicks "I agree" or accepts the tracking category in the Preferences Center. The illustration shows the consent banner and the script it releases.
tracking. Illustration of the consent banner.Cookie Consent is free and needs no account. Build your free consent banner with TermsFeed Free Cookie Consent.
Block the _ga_<container-id> Cookie With TermsFeed Privacy Consent
Add Google Analytics 4 from its template in TermsFeed Privacy Consent, and Privacy Consent loads the Google tag and sends Google Consent Mode v2 for you. Type your measurement ID, which starts with G-, and the template fills the vendor, the Analytics vendor category, and the consent signals.
The template runs the Google tag in advanced consent mode, so Google Analytics 4 sets the _ga cookies only after the visitor accepts the Analytics vendor category. Run Google Analytics 4 without the template, in basic consent mode, where your legal advice asks for no request to Google before consent.
The Google Analytics 4 template asks for the Measurement ID and fills every other field of the vendor. Pick the "Google Analytics 4" card under Analytics, enter the Measurement ID, and click "Add Google Analytics 4". Find the Measurement ID in Google Analytics under Admin › Data streams › your web stream. The illustration shows the template form in the TermsFeed app.
Privacy Consent detects the location of each visitor and records every answer in a consent log. Set up Google Analytics 4 from its template with TermsFeed Privacy Consent.
Block the _ga_<container-id> Cookie With Google Consent Mode v2
Google Consent Mode v2 loads the Google tag before consent and stops the Google Analytics 4 cookies while analytics_storage is denied. Google tags "won't read or write first-party analytics cookies" while analytics_storage is denied, according to the Google consent mode documentation.
Advanced consent mode sends measurements without cookies to Google while consent is denied, and Google uses them for modeling. Basic consent mode loads no Google tag before the visitor answers. Choose basic consent mode to send no request to Google before consent.
Set up the default and the update calls with how to integrate Google Consent Mode v2 with Cookie Consent.
How to Verify That the _ga_<container-id> Cookie Waits for Consent
Verify the setup in a private window. Open Chrome DevTools, select the Application tab, and open Cookies. Click "I decline" on the consent banner and reload the page. The _ga_<container-id> cookie must not appear in the list until you accept analytics cookies.
How Long the _ga_<container-id> Cookie Lasts
The _ga_<container-id> cookie lasts 2 years (730 days), and the lifetime restarts at every page view. Chrome keeps the cookie for 400 days (about 13 months) at most, according to the Chrome team. Safari caps the cookies that JavaScript sets at 7 days of Safari use without an interaction with your site, according to the WebKit team behind Safari.
The session inside the cookie ends long before the cookie expires. A session times out after 30 minutes without activity by default, and the next page view starts a new session in the same cookie, according to Google. Change the session timeout in Google Analytics under Admin, Data streams, Configure tag settings, and Adjust session timeout.
The Override cookie settings in the Google Analytics interface and the cookie_expires setting of the Google tag change the lifetime of the Google Analytics cookies. The _ga and _ga_<container-id> cookies therefore keep the same lifetime.
Scripts and Requests of Google Analytics 4 That Come With the _ga_<container-id> Cookie
The catalog lists 6 scripts, pixels, and data endpoints of Google Analytics 4, which a cookie scanner or the Network tab of Chrome DevTools shows next to the _ga_<container-id> cookie. Block the main script, and the requests in the table stop with the main script.
| Type | Resource | Host | What it does |
|---|---|---|---|
| Script | Google tag for Google Analytics 4 (gtag.js) | www.googletagmanager.com | The Google tag loads Google Analytics 4 on the page and writes the _ga and _ga_<container-id> cookies. |
| Data endpoint | Google Analytics 4 collection endpoint | region1.google-analytics.comwww.google-analytics.comanalytics.google.com | The collection endpoint receives every page view and event, with the client ID from the _ga cookie in the cid parameter. |
| Data endpoint | Google signals collection endpoint | stats.g.doubleclick.net | Google Analytics 4 sends measurements to stats.g.doubleclick.net while Google signals is on, which links visits to signed-in Google accounts. |
| Pixel | Google Analytics audiences pixel | www.google.comwww.google.frwww.google.de | The ga-audiences pixel adds the visitor to Google Ads remarketing audiences built in Google Analytics, and the TermsFeed website auditor found the pixel firing after consent on scanned sites. |
| Script | Universal Analytics library (analytics.js) | www.google-analytics.com | The analytics.js library ran Universal Analytics and wrote the _ga, _gid, and _gat cookies. |
| Data endpoint | Universal Analytics collection endpoint | www.google-analytics.com | The Universal Analytics endpoint received hits from analytics.js until 1 July 2023. |
_ga_<container-id> Cookie FAQs
Why does my site have 2 _ga_ cookies?
Your site sends data to 2 Google Analytics 4 properties, and each property writes its own _ga_<container-id> cookie. Compare the part after _ga_ with the measurement IDs in Google Analytics, under Admin and Data streams, to find both properties. Remove the tag of the property you no longer use, and the extra cookie stops at the next visit.
Is the _ga_ cookie necessary?
No, the _ga_<container-id> cookie is not a strictly necessary cookie. Firstly, the cookie serves the analytics reports of your site, not a service the visitor asks for. Secondly, your site works the same for a visitor who refuses analytics cookies. Thirdly, Google tags read and write no first-party analytics cookies while analytics_storage is denied in Google Consent Mode v2, according to Google.
How do I rename the _ga_ cookie?
Add a cookie_prefix value to the configuration of the Google tag, and the Google tag adds the prefix to the names of the Google Analytics cookies. A cookie scanner then reports the cookies under the new names. Update your Cookies Policy with the new names, so the list matches what visitors find in the browser.
Sources for the _ga_<container-id> Cookie
The facts on this page come from the documentation Google publishes, checked on 2026-10-16. The catalog lists every source so you check each fact yourself.