serkankaya.
Türkçe sürüm
Let’s work together ↗

What Is a First-Party Cookie? A Practical Guide

What is a first-party cookie and how does it differ from a third-party cookie? Browser limits, Safari ITP, server-set cookies and server-side tracking.

A first-party cookie is a cookie that belongs to the same domain as the site the user sees in the address bar, and only that site can read it. Staying signed in, remembering a shopping cart and on-site measurement all work through these cookies. In this post I explain how a first-party cookie differs from a third-party cookie, which limits browsers apply, and how it relates to server-side tracking.

A first-party cookie is created either by a Set-Cookie header that the site’s server adds to its HTTP response, or by JavaScript on the page writing to document.cookie. A cookie is a small piece of data that the server sends to the browser and that the browser sends back with later requests.[2] The browser stores the cookie and returns it to the server in the Cookie header with every new request to the same site.

According to MDN, a cookie is tied to a particular domain and scheme (usually https). If the cookie’s domain and scheme match the address of the page the user is looking at, the cookie counts as first-party.[1] A first-party cookie can be set when the user first visits a site, follows an internal link to another page, or loads an image, font or script from the same site.[1]

User opens the site Server sends Set-Cookie Browser stores the cookie Sends it back next request
The life cycle of a first-party cookie: the site the user visits is the one that writes and reads it.

Attributes define how a cookie behaves. Expires or Max-Age say how long the cookie is kept; without them the cookie becomes a session cookie and is deleted when the browser closes.[2] Secure ensures the cookie is only sent over HTTPS. HttpOnly prevents JavaScript from reading the cookie. SameSite decides whether the cookie is sent with cross-site requests.[2]

Set-Cookie: session=a3fWa; Domain=example.com; Path=/; Max-Age=2592000; Secure; HttpOnly; SameSite=Lax

In the example above, the Domain=example.com attribute lets subdomains such as www.example.com and metrics.example.com read the cookie too. This detail matters when you move a measurement server to a subdomain.

Short answer

The difference is which domain the cookie belongs to. A cookie that belongs to the same domain as the site in the user’s address bar is a first-party cookie; a cookie that belongs to a different domain is a third-party cookie. Safari and Firefox restrict third-party cookies by default because they are used for cross-site tracking, while first-party cookies keep powering the site’s core functions.

A third-party cookie is a cookie written to another domain when an embedded ad, video player or tracking script loads from that domain. MDN notes that calling these “cross-site cookies” is arguably more accurate.[1] The reason is simple: the problem is not that a company owns the cookie, but that it can recognize the same user across several sites.

First-party cookie

  • Belongs to the domain of the visited site
  • Only that site can read it
  • Sessions, carts, language, on-site measurement
  • Browsers do not block it by default

Third-party cookie

  • Belongs to a different domain
  • Can recognize the same user across sites
  • Cross-site advertising and tracking
  • Safari and Firefox restrict it by default
Both cookie types use the same technology; the difference is which domain the cookie is bound to and in which context it can be read.

The distinction is not about who runs the code. The Google Analytics script loads from Google’s servers, but the _ga cookie it writes goes to your domain. Google’s list of advertising and measurement cookies shows _ga with a 2-year lifetime and the Google Ads _gcl_au and _gcl_aw cookies with a 90-day lifetime, all listed as set from the partner’s domain.[4] In technical terms, these are first-party cookies.

Lifetime of the Google Analytics _ga cookie
2 years
Lifetime of the Google Ads _gcl_au and _gcl_aw cookies
90 days
Lifetime of the server-side FPLC cookie
20 hours
Source: Google, Advertising and measurement cookies

I cover these cookies from the click ID angle in my post on the Google Ads GCLID.

How do browsers restrict first-party cookies?

Browsers do not block first-party cookies, but some shorten the lifetime of first-party cookies written by JavaScript. For measurement, this distinction matters more than third-party cookie blocking. Most advertising and analytics tags store the user identifier in a first-party cookie written by JavaScript.

According to MDN’s browser overview, Firefox runs Total Cookie Protection through Enhanced Tracking Protection, which is on by default and gives every site a separate cookie jar.[1] In Safari, ITP (Intelligent Tracking Prevention) applies similar protections by default. Chrome, according to MDN, does not block third-party cookies by default; it only blocks them in Incognito mode or when the user changes the setting.[1]

The WebKit team’s documentation spells out Safari’s rules. ITP blocks all third-party cookies with no exceptions.[3] First-party cookies created by JavaScript are deleted after 7 days without interaction with the site. If the user arrives through a link carrying tracking parameters, cookies written by JavaScript on the landing page are capped at 24 hours.[3]

This directly affects ad measurement. A user clicks an ad, looks at a product and comes back 10 days later to buy; by then the JavaScript cookie may already be gone. The sale happens, but it can no longer be tied to the ad click. In reports, this loss shows up not as a drop in conversions but as sales that cannot be attributed.

Server-side tracking partly solves the first-party cookie lifetime problem when the tagging server runs on the site’s own domain. The server writes the cookie in its HTTP response, and the limits Safari applies to JavaScript cookies do not apply to it. I explain the overall architecture in what is server-side tracking.

Google Tag Manager’s server-side documentation gives a clear recommendation here. If the tagging server runs on the default endpoint, the data reaches the server but stays in a third-party context.[5] To unlock the benefits of a first-party context, such as more durable cookies, the tagging server and the website have to run on the same domain.[5] Google presents a same-origin setup such as www.example.com/metrics as the best practice and a subdomain setup such as metrics.example.com as a valid option.

SetupExample addressCookie contextNote
Same originwww.example.com/metricsFirst-partyRequires request forwarding via a CDN or load balancer
Subdomainmetrics.example.comFirst-partyUpdate the DNS record; who owns the IP matters
Default domainProvider’s addressThird-partyComes pre-configured, gives no cookie durability

WebKit documents an important exception here. If the measurement subdomain resolves through a CNAME to a third-party domain, or points to a third-party IP address, cookies set in that response are also capped at 7 days.[3] So pointing a subdomain at a service is not enough on its own. The infrastructure and IP the server runs on decide the outcome.

Google’s cookie list includes the FPID cookie related to server-side tagging with a 2-year lifetime and the FPLC cookie with a 20-hour lifetime.[4] FPID is used to keep the Google Analytics client ID in a cookie set by the server. You can find the setup steps in my server-side GTM setup guide.

Whether a cookie is first-party or third-party does not decide on its own whether consent is required. The cookie’s purpose does. Strictly necessary cookies such as sessions and carts are treated differently from analytics and advertising cookies.

In Turkey this framework is set by KVKK (Law No. 6698, Turkey’s data protection law), and in the EU by the GDPR and the ePrivacy rules. An analytics or advertising cookie keeps the same personal data purpose even when it is written by the server as a first-party cookie. Using server-side tracking as a way around cookie consent carries legal risk and conflicts with the policies of ad platforms.

In Google tags, consent status is managed with Consent Mode. When a user rejects analytics or advertising cookies, tags have to behave according to that choice. The choice should also be passed on to the server container. I cover the details in what is Consent Mode v2.

No, first-party data and a first-party cookie are different concepts. First-party data is the data a business collects directly from its customers: order history, CRM records, email lists or form answers. A first-party cookie carries a small browser-side piece of that data, usually an identifier.

In ad measurement the two complement each other. The cookie recognizes the user across visits. First-party data proves that the sale or qualified lead actually happened. Methods such as Meta Conversions API and Google Ads Enhanced Conversions use hashed first-party data as a matching signal where the cookie falls short. For the Meta side of the setup, see what is Meta Conversions API.

The quickest way to audit a first-party cookie setup is to inspect the cookies one by one in the browser’s developer tools. For each measurement cookie, check the domain, how it is written, its lifetime and its consent status. The list below sums up what I look at in a tracking audit.

It is worth testing this list separately in Safari. If a cookie’s expiry date looks shorter in Safari than in Chrome, the cookie is most likely written by JavaScript, or the server resolves to third-party infrastructure.

Conclusion

A first-party cookie is a cookie written to the visited site’s own domain, and it carries many jobs from the site’s core functions to measurement. As browsers restricted third-party cookies, the weight of measurement shifted to first-party cookies. Safari’s rules, however, show that how a first-party cookie is written matters too.

As a next step, check the measurement cookies on your site against the list above. See which ones are written by JavaScript and which by the server. If you are considering server-side tracking to fix cookie lifetime, plan from the start to run the tagging server on your own domain and to carry your consent setup over to the server. I explain how measurement infrastructure connects to ad performance on my performance marketing page.

Key terms

First-party cookie
First-party cookie is a cookie that belongs to the same domain and scheme as the site the user sees in the address bar. Sessions, shopping carts, language preferences and on-site measurement all rely on first-party cookies.
Third-party cookie
Third-party cookie is a cookie that belongs to a domain other than the page being visited, usually written by embedded content, ads or tracking code. Because it is used for cross-site tracking, Safari and Firefox restrict it by default.
HttpOnly
HttpOnly is a Set-Cookie attribute that prevents a cookie from being read by JavaScript. A cookie with this attribute is only sent to the server in HTTP requests, which reduces the risk of a malicious script stealing it.
SameSite
SameSite is a Set-Cookie attribute that controls whether a cookie is sent with cross-site requests. It takes the values Strict, Lax and None; None can only be used together with the Secure attribute.

Frequently asked questions

What is the difference between a first-party cookie and a third-party cookie?

The difference is which domain the cookie belongs to. A cookie that matches the site in the address bar is first-party; a cookie that belongs to a different domain is third-party. Browsers restrict third-party cookies far more strictly because they are used for cross-site tracking.

Are first-party cookies being blocked?

No, browsers do not block first-party cookies by default; sessions, shopping carts and language preferences depend on them. Safari does, however, shorten the lifetime of first-party cookies written by JavaScript under certain conditions. Users can still delete or block all cookies in their browser settings.

Do first-party cookies require cookie consent?

Whether a cookie is first-party or third-party does not decide on its own whether consent is needed; its purpose does. Cookies that are strictly necessary for the site to work are treated differently from analytics or advertising cookies. Analytics and advertising cookies usually require consent even when they are first-party; ask a legal expert for a definitive assessment.

Is the Google Analytics cookie a first-party cookie?

Yes. According to Google's cookie list, the Google Analytics _ga cookie is written to the domain of the site being measured and lasts 2 years. The Google Ads _gcl_au and _gcl_aw cookies are also written to the site's own domain and are kept for 90 days.

Does server-side tracking solve the first-party cookie problem?

Partly. If the tagging server runs on the site's own domain, it can set the cookie in the HTTP response, so the short lifetime Safari applies to JavaScript cookies does not apply. If the server resolves to a third-party IP or CNAME, the limit still applies, and cookie consent can never be bypassed.

Sources

  1. MDN Web Docs: Third-party cookies
  2. MDN Web Docs: Using HTTP cookies
  3. WebKit: Tracking Prevention in WebKit
  4. Google: Advertising and measurement cookies
  5. Google Tag Manager: Custom domain configuration