CookieRule

Types of Cookies Website Owners Should Know and How to Classify Them

The types of cookies a website uses are sorted three ways: by who sets them, by how long they last and by what they do. Only the last one, purpose, decides whether you need consent. This guide walks through all three and shows how to classify a cookie you have never seen before.

Matthias LöfflmannPublished · 8 min read
Cookies from a browser window sorted into category trays by who sets them, how long they last and what they do
Key takeaways The short version, before the details.
  1. Who sets a cookie (first party or third party) and how long it lasts (session or persistent) describe it. Neither one decides whether you need consent.
  2. Purpose does: necessary cookies are exempt, while preferences, statistics and marketing cookies wait for the visitor's choice.
  3. Local storage and session storage follow the same consent rules as cookies. To classify an unknown cookie, find the script that sets it.

Types of cookies website owners should know

Every cookie on your site can be described in three ways at once. A Google Analytics cookie, for example, is first party, persistent and used for statistics. Each label answers a different question:

Sorted byTypesQuestion it answersDecides consent?
Who sets itFirst party, third partyWhich domain does the cookie belong to?No
LifetimeSession, persistentIs it deleted when the browser closes, or does it stay?No
PurposeNecessary, preferences, statistics, marketingWhat is it for, and does the visitor need it?Yes

A lot of confusion comes from mixing these up. A first-party cookie is not automatically exempt, and a session cookie is not automatically harmless. Under the EU ePrivacy Directive, storing information on a visitor's device needs consent unless it is strictly necessary for a service the visitor asked for. That is a test of purpose, not of domain or lifetime.

First party vs third party cookies

The difference is the cookie's domain compared with the site in the address bar.

  • First-party cookies belong to the site the visitor is on. On example.com, a cookie set for example.com or www.example.com is first party.
  • Third-party cookies belong to another domain, usually through an embed, an ad tag or a tracking pixel that loads from that domain. A cookie set for an ad network's domain while the visitor reads your page is third party.

Browsers treat the two differently. Safari and Firefox block many third-party cookies by default. First-party cookies still work, and that is why many analytics and ad tools now set their cookies on your own domain.

Can a third-party script set first party cookies?

Yes, and it happens all the time. When you add Google Analytics, Google's script runs on your page and writes the _ga cookie for your domain. The Meta Pixel does the same with _fbp. Both are first-party cookies by domain, but they serve another company's statistics or advertising.

Domain is not ownership. When you classify a cookie, ask which script set it and why. The domain alone will not tell you whether it needs consent.

Session cookies vs persistent cookies

This split is about lifetime, and it is set by the cookie itself. The MDN guide to HTTP cookies covers the attributes in detail.

Session cookiesPersistent cookies
How it is setNo Expires or Max-Age attributeHas an Expires date or a Max-Age
When it goes awayWhen the browser session endsAt its expiry date, or when the visitor clears it
Typical useLogin session, checkout steps, load balancingRemembered language, analytics IDs, ad IDs, a saved consent choice

One catch: browsers that restore the last session on startup can keep session cookies alive for days. Never rely on "it is only a session cookie" as your reason for skipping consent. A session cookie that tracks a visitor for analytics still needs consent. A persistent cookie that keeps a visitor signed in may still be necessary. In your cookie policy, the lifetime goes in the expiry column, not the category.

Most consent tools and cookie policies use four purpose categories. These are the ones a visitor sees in the banner's settings and the ones your cookie declaration is grouped by.

CategoryWhat it is forCommon examplesConsent
NecessaryThings the site cannot work without for a service the visitor asked forLogin session, shopping cart, security tokens, the stored consent choiceNot needed
PreferencesRemembering choices and running optional featuresLanguage or region choice, chat widgetsNeeded
StatisticsMeasuring how the site is usedGoogle Analytics, Hotjar, Microsoft Clarity, Matomo CloudNeeded
MarketingAdvertising, retargeting and conversion trackingGoogle Ads, Meta Pixel, LinkedIn Insight, TikTok Pixel, YouTube embedsNeeded

Necessary cookies: the only exempt category

Keep this category small. A cookie is necessary when removing it would break something the visitor asked for, such as staying signed in or keeping items in a cart. It is not necessary just because it is useful to you. Our guide to strictly necessary cookies has a four-question test for borderline cases.

What are functional cookies?

"Functional" is a label, not a legal category, and tools use it in different ways. Usually it means preference cookies: they remember a language, a region or a layout choice, or they power an optional feature like a chat widget. Some vendors also use "functional" for cookies that are really necessary. Judge each cookie on its own. If the site works for the visitor without it, it belongs under preferences and waits for consent.

Statistics cookies

Analytics cookies count visits, sessions and returning visitors. They are almost always persistent and often first party. Under EU rules they need consent like any other non-essential cookie.

What are marketing cookies?

Marketing cookies identify a browser so ads can be targeted, measured or shown again on other sites. Conversion pixels, retargeting tags and social embeds belong here. A YouTube embed counts too, because it sets cookies as soon as it loads. These cookies carry the most risk, and in California they can also count as "sharing" under the CCPA. See CCPA cookies for the opt-out side.

Cookies vs local storage: do the same rules apply?

Technically they are different. Legally they are treated the same way.

CookiesLocal storageSession storage
Sent to the serverWith every matching requestNever, read by scripts onlyNever, read by scripts only
LifetimeSession or until expiryUntil clearedUntil the tab is closed
ScopeDomain and pathOne originOne origin, one tab
Needs consent if non-essentialYesYesYes

The ePrivacy rule covers storing or reading any information on the visitor's device, so it does not matter whether a tracker uses a cookie or a key in the Web Storage API. Many analytics and session-replay tools use both. Give storage keys the same four categories and list them in your cookie policy too.

A name like _ga is easy to place. Something like sid_v2 or hx_pref is not. Work through it in this order:

  1. Check the domain. If it belongs to another company's domain, it came from an embed, tag or pixel. Find which one loads from that domain.
  2. Look up the name. Well-known prefixes point to their vendor: _ga and _gid to Google Analytics, _gcl_au to Google Ads, _fbp to the Meta Pixel, _hj to Hotjar.
  3. Find what sets it. In your browser's developer tools, open the network panel and reload the page in a private window. A Set-Cookie header in a response shows which request set it. If no header sets it, a script did. Search your theme, plugins and tag manager for the name.
  4. Ask what breaks without it. Delete the cookie and use the site. If login, cart or checkout stops working, it is likely necessary. If nothing the visitor asked for changes, it is not.
  5. Pick the category from the purpose, then make the script that sets it wait for that category.

When in doubt, do not call it necessary. A cookie filed as necessary runs before any choice. Putting a tracker there is the classic mistake regulators look for.

How a scan classifies your cookies

A CookieRule cookie scan opens your site in a real browser and lists every cookie, local storage key, session storage key and known tracker request it finds. It visits twice: once as a new visitor and once after choosing Allow All. A cookie found only on the second visit is marked Set only after consent, which tells you its tag already waits.

Each item then shows one of these:

  • A category with "Our classification": the cookie database recognized it by name and domain and filled in the vendor, purpose and retention.
  • Yours to classify: an unknown cookie set by your own site. Only you know what it does, so set its category with the pencil button.
  • Being identified: an unknown cookie set by another company. It is added to the database once it is known, and you do not need to act.

Your own category always wins over ours and applies only to your websites. Cookies still without a category appear under Unclassified in your cookie declaration and are treated as needing consent.

Does classifying a cookie block it?

No. Classifying sets the label your visitors and your declaration see. Blocking happens per script. Once you know which script sets a cookie, tag that script with its category so it waits for consent:

<script type="text/plain" data-consent="statistics" src="https://analytics.example.com/tracker.js"></script>

Common vendors such as Google Tag Manager, the Meta Pixel and Hotjar are also held back automatically. Any other script runs as normal until you tag it. The blocking scripts guide covers inline scripts, iframes and pixels.

Ready to see which types of cookies your website sets?

  • Every cookie and storage key listed after a real browser visit
  • Vendor, purpose and retention filled in for known cookies
  • Unknown cookies from your own site marked for you to classify
Scan your website

Frequently asked questions

Cookies are sorted three ways: first party or third party by who sets them, session or persistent by lifetime, and necessary, preferences, statistics or marketing by purpose. Every cookie has one label from each group. Only the purpose decides whether you need the visitor's consent before setting it.

A first-party cookie belongs to the domain in the address bar. A third-party cookie belongs to another domain, usually through an embed or ad tag. Third-party scripts often set first-party cookies too, as Google Analytics does with _ga. So the domain alone does not tell you whether consent is needed.

A session cookie has no expiry date and is deleted when the browser session ends. A persistent cookie has an Expires date or Max-Age and stays until then, unless the visitor clears it. Lifetime goes in your cookie policy's expiry column. It does not decide consent: a session cookie used for tracking still needs it.

Functional cookies usually means preference cookies. They remember a visitor's language or region, or they run optional features like chat widgets. The term is not a legal category, and some tools use it for necessary cookies too. If the site works without the cookie, treat it as preferences and wait for consent.

Check its domain, look up its name, then find what sets it with your browser's network panel or by searching your code and tag manager. Delete it and see if anything the visitor asked for breaks. Pick the category from its purpose, then tag the script that sets it so it waits for consent.