How Cookie Tracking Works

The mechanisms behind web cookies, how they enable tracking, and the laws that regulate them.

Quick Summary

  • HTTP cookies are small data files stored by the browser to maintain state.
  • First-party cookies are set by your domain; third-party cookies are set by external domains.
  • Third-party cookies enable cross-site user profiling and retargeting.
  • Safari and Firefox block third-party cookies by default; Chrome is following.
  • Under the ePrivacy Directive, all non-essential cookies require explicit consent.

Introduction

Cookies are the backbone of how the web remembers users. Every login session, shopping cart, and “remember me” checkbox depends on them. But cookies have a dark side: the same technology that powers essential functionality is also the primary mechanism for tracking users across the internet.

Understanding the difference between first-party and third-party cookies, and how regulations like the GDPR and ePrivacy Directive govern them, is essential for anyone building or managing a website. Getting it wrong can result in regulatory fines, broken user trust, and compliance failures.

This guide explains how cookies work, the different types, how they enable tracking, and what you need to do to stay compliant. Whether you are a developer implementing a cookie consent banner or a founder trying to understand what your marketing tools are doing, this is the guide for you.

Session vs Persistent Cookies

Cookie Lifespans

TypeLifetimeDeleted WhenUse CaseRisk Level
SessionBrowser sessionBrowser closesShopping cart, navigationLow
PersistentDefined expiry (days/years)Expiry date or manual clearRemember login, track usersMedium–High

Long-Lived Cookies

Persistent cookies with multi-year lifetimes (e.g., Max-Age=31536000) are commonly used for permanent user tracking and are a key regulatory concern. GDPR regulators view unnecessarily long cookie durations as disproportionate data collection.

From a privacy perspective, session cookies are generally lower risk because they disappear when the browser closes. Persistent cookies, however, can track a user for months or years, even if they clear their browsing history, the cookie remains until its expiry date.

First-Party vs Third-Party Cookies

Who Owns the Cookie?

AspectFirst-PartyThird-Party
Set byYour domain (e.g., siteprivacyscore.com)External domain (e.g., facebook.com)
PurposeCore site functionalityAdvertising, retargeting
Cross-site trackingNoYes, builds profiles across sites
Browser supportFully supportedBlocked in Safari, Firefox; Chrome phasing out
Consent requiredOnly if non-essentialAlways (used for marketing)

How Third-Party Cookies Connect the Web

How Third-Party Cookies Track Users Across SitesUser visits Site AUser visits Site BAd pixel loadsSame ad pixel loadsAd Network ServerCross-site user profile built

How Third-Party Tracking Works

A user views shoes on Site A. An ad network drops a third-party cookie. When the user visits Site B with the same ad network, it reads the cookie and shows shoe ads. The ad network now knows the user visited both sites, building a cross-site browsing profile without the user's knowledge.

This cross-site profiling is the core reason third-party cookies have become the primary target of both browser vendors and privacy regulations. When a user visits 50 sites that all load the same ad network pixel, that network can build a comprehensive browsing history.

Want to see which cookies your website is setting?

Run Free Cookie Scanner

Real-World Examples

Regulatory Actions

Cookie tracking has been at the center of some of the largest privacy enforcement actions:

OrganizationFine / ActionIssue
Google (CNIL, France)€150 millionNon-compliant cookie consent, reject option harder than accept
Amazon (CNIL, France)€35 millionDropping cookies without prior consent
Clearview AI€20 millionCollecting biometric data via cookies without consent
Criteo€40 millionCross-site tracking cookies without valid opt-in

The Cookie Wall Ban

EU regulators have explicitly banned “cookie walls”, blocking access to content until users accept all cookies. This practice does not constitute “freely given” consent under the ePrivacy Directive.

How to Detect Cookie Issues

  1. Run a cookie scan: Use the Cookie Scanner to identify every cookie your site sets, including domain, duration, and classification (essential vs. marketing).
  2. Check browser DevTools: Open DevTools → Application tab → Cookies. Look for cookies from external domains, these are third-party cookies.
  3. Test consent behavior: Reject all cookies via your banner, then check whether third-party cookies still appear. If they do, your consent banner is non-functional.
  4. Run a GDPR check: Use the GDPR Quick Check for a comprehensive compliance assessment that includes cookie analysis.
  5. Check for trackers: Many trackers set cookies. Run the Tracker Detector to identify all tracking scripts on your pages.

How to Fix Cookie Issues

Compliance & Development Steps

  1. Implement a compliant consent banner: See the Cookie Consent Banner guide for requirements. The banner must actually block non-essential scripts until the user explicitly opts in.
  2. Classify your cookies: Audit every cookie your site sets and classify each as “strictly essential” (no consent needed) or “non-essential” (requires consent).
  3. Use secure cookie attributes:

Secure Cookie Configuration

Set-Cookie: session=abc; HttpOnly; Secure; SameSite=Lax; Path=/

HttpOnly prevents JavaScript access. Secure ensures HTTPS only. SameSite=Lax mitigates CSRF attacks.

  1. Minimize cookie durations: Set the shortest Max-Age necessary. Session cookies (no Max-Age) are preferable when possible.
  2. Self-host analytics: Replace third-party analytics with self-hosted alternatives (e.g., Plausible, Umami) to eliminate third-party cookie dependencies entirely.

Best Practices

  1. Always use HttpOnly and Secure flags, prevents JavaScript from reading session cookies and ensures they are only sent over HTTPS.
  2. Set SameSite=Lax or Strict, mitigates cross-site request forgery (CSRF) and limits cookie sending to same-site contexts.
  3. Minimize cookie scope, use Path=/ only when necessary. Restrict cookies to the specific paths that need them.
  4. Audit cookies quarterly, marketing teams frequently add new scripts that set cookies. Regular audits prevent “cookie creep.”
  5. Document every cookie, maintain a cookie register listing each cookie, its purpose, its duration, and whether it requires consent.
  6. Implement consent before scripts, ensure your consent banner actually blocks script execution, not just hides a popup.
  7. Use security headers, headers like CSP and Referrer-Policy complement cookie security by restricting which domains can be contacted.

Common Mistakes

The False Illusion of Compliance

  • Showing a banner but not blocking scripts: The most common violation. The banner appears, but analytics and ad scripts fire immediately on page load, before any consent is given.
  • Treating first-party analytics as “essential”: Analytics cookies are not essential under the ePrivacy Directive, even if they are first-party. They still require consent.
  • Setting cookies with unnecessarily long lifetimes: A 10-year cookie for a preference setting is disproportionate. Use the shortest duration necessary.
  • Missing HttpOnly on session cookies: Without HttpOnly, a successful XSS attack can steal session cookies via JavaScript.
  • Forgetting server-side cookies: Cookies set by server-side code (e.g., tracking pixels, A/B testing) are often overlooked in audits. They still need consent if non-essential.
  • Not testing in all browsers: Safari and Firefox block third-party cookies by default. A feature that works in Chrome may silently fail in Safari if it depends on third-party cookies.

Conclusion

Cookies are a fundamental web technology, but their use for tracking has made them the most regulated aspect of web development. Understanding the difference between session and persistent cookies, first-party and third-party cookies, and the legal frameworks that govern them is not optional, it is a compliance requirement.

Start by auditing your current cookies, implement a compliant consent mechanism, and establish a regular review process to catch new cookies added by marketing scripts.

Scan Your Website

Scan your website with SitePrivacyScore to detect cookie tracking issues automatically. Our free scanner identifies every cookie, classifies them, and checks your consent implementation.

Related Guides

Frequently Asked Questions

Can I use LocalStorage instead to avoid the cookie law?+
No. The ePrivacy Directive is technology-neutral. It governs any storage of, or access to, information on a user's device, including LocalStorage, SessionStorage, and IndexedDB.
What defines an 'essential' cookie that doesn't need consent?+
An essential cookie is strictly necessary for a core function the user explicitly requested. Examples: authentication tokens, shopping cart IDs, load-balancing pins. Analytics cookies are NOT essential.
Are first-party cookies safe?+
Safer, but not exempt from regulation. First-party analytics cookies still require consent under the ePrivacy Directive if they track user behavior beyond basic functionality.
What happens when third-party cookies are fully blocked?+
Advertisers shift to first-party data, server-side tracking, and fingerprinting. Websites must adapt their analytics and attribution strategies accordingly.
How do I scan my website's cookies?+
Use the free Cookie Scanner to get a full list of cookies set by your site, including their domain, duration, and classification.
How long should cookies last?+
Session cookies expire when the browser closes. For persistent cookies, set the shortest lifespan necessary. GDPR regulators scrutinize cookies with multi-year durations.
Do I need a cookie banner if I only use essential cookies?+
Technically no, the ePrivacy Directive exempts strictly essential cookies from consent. But you should still disclose them in your privacy policy for transparency.

Scan Your Website's Cookies

Ensure you aren't quietly dropping third-party cookies that violate the ePrivacy Directive and GDPR.

For deeper runtime checks, run the full privacy audit →