First-Party Cookie

A first-party cookie (1P cookie) is a small key–value file set by the website domain you’re actually visiting. The browser stores it and sends it back only to that same domain on subsequent requests. In web analytics, 1P cookies are the backbone for measuring a session, identifying a returning unique visitor, and powering sane personalization without spraying data across the open web like confetti.

How it works (short and practical)

When a page from example.com loads, the server (or client-side script) can set Set-Cookie headers for example.com. On the next pageview, the browser automatically attaches those cookies to requests to example.com. This enables durable, privacy-respecting tracking compared to a third-party cookie, which modern browsers increasingly block.

Common uses in analytics

  • Visitor identity (pseudonymous): store a generated uid to count unique visitors.
  • Sessionization: keep a session id to stitch hits into a session.
  • Attribution: hold the latest campaign source (e.g., UTM parameters) for conversion credit in your attribution model.
  • Consent state: remember a user’s consent choices.
  • Feature flags/personalization: toggle experiences without server round-trips.

Minimal formula + micro-example

Unique visitors (period) = COUNT(DISTINCT uid_cookie)

Example: same browser visits Mon (uid=abc) and Thu (uid=abc) → counts as 1 unique visitor in that period.

Key properties you actually touch

PropertyNotes
Domain / PathScope the cookie to a hostname/subpath. Use the apex if you need subdomain sharing.
Expires / Max-AgeControls lifetime; shorter is safer, longer improves return-visit recognition.
Secure, HttpOnlySecure restricts to HTTPS; HttpOnly hides from JS to reduce XSS risk.
SameSiteLax by default in modern browsers; limits cross-site sends and helps prevent CSRF.

Why analysts prefer 1P today

First-party cookies survive modern tracking protections far better than third-party ones, keep data within your own domain, and are transparent to users. They are the pragmatic core for privacy-aware measurement: clean, scoped, and under your control. Just remember to document lifetimes, respect consent, and mirror key values into your data layer when needed.