First-party cookie

Definition

A first-party cookie is a text file set by the domain of the visited site (not by a third-party domain). In the context of web analytics, first-party cookies primarily serve to identify a user across visits and to maintain browsing sessions.

GA4 first-party cookies

GA4 uses the _ga cookie (2-year lifespan) to store a unique client identifier, and the _ga_<MEASUREMENT_ID> cookie for session data. These cookies are set in first-party context, meaning under the site’s domain (e.g., .yoursite.com), making them more resilient than third-party cookies.

Even as first-party, analytics cookies require user consent in Europe. Without consent, Consent Mode prevents the cookie from being set and GA4 operates in degraded mode. Additionally, Safari (ITP) limits the lifespan of JavaScript-set first-party cookies to 7 days, fragmenting user identification on Apple devices.

Best practices

To maximize first-party cookie lifespan and bypass browser restrictions, server-side tracking allows cookies to be set from the server (via an HTTP Set-Cookie header), exempting them from ITP limitations. This is a major advantage of server-side tracking for data quality.

Have an analytics project?

Let's discuss your tracking, measurement and data needs. Free initial consultation, no commitment.

Book a call