# GDPR compliance for analytics

A practical guide to GDPR for product analytics: lawful basis, ePrivacy cookie consent, data-subject rights and DSARs, transfers, and how self-hosting helps.

Source: https://pug.sh/learn/gdpr-analytics

The GDPR doesn’t ban analytics: it asks you to have a reason, be transparent, and stay in control of the data. Here’s the legal framework applied to product analytics: lawful basis, consent, data-subject rights, international transfers, and breach duties.

By [Praveen Kumar](https://github.com/poluruprvn), who builds Pug. Updated November 21, 2026

The [General Data Protection Regulation](https://eur-lex.europa.eu/eli/reg/2016/679/oj) (Regulation (EU) 2016/679, applied since May 2018) governs how you process the personal data of people in the EU and EEA, and its reach is extraterritorial, so a company anywhere that offers goods or services to people in the EU is in scope. It doesn’t prohibit analytics. It requires that you have a *lawful reason* to collect data, tell people what you’re doing, collect no more than you need, and honour their rights over it. This guide maps that framework onto product analytics. It is **not legal advice**: GDPR is nuanced and enforced differently across member states, so treat this as a starting point and confirm with counsel. For the principle-level practices (cookieless tracking, data minimisation, residency), see the companion [privacy-first analytics](https://pug.sh/learn/privacy-first-analytics) guide. If you also serve users in California, the [CCPA guide](https://pug.sh/learn/ccpa-analytics) covers the opt-out model there, and for India the [DPDP Act](https://pug.sh/learn/dpdp-act-analytics) guide is the parallel read.

## Who’s who under GDPR

- **Data subject**: the individual the personal data is about.
- **Controller**: whoever decides the why and how of processing. If you run the product and choose what to track, that’s you, and the accountability sits with you.
- **Processor**: anyone processing on the controller’s behalf, like a hosted analytics vendor. You need a **data-processing agreement (Article 28)** with each one.
- **Data Protection Officer**: required for some organisations (large-scale monitoring, sensitive data at scale, public authorities).

For analytics this distinction is the crux: sending events to a third-party cloud makes that vendor your processor and leaves you accountable as controller. [Self-hosting](https://pug.sh/self-hosted-analytics) keeps the whole chain in-house.

## Personal data is broader than you think

GDPR’s definition of personal data covers **online identifiers**: cookies, device IDs, advertising IDs, and in most cases IP addresses, even before anyone logs in. So the assumption that “anonymous” traffic data sits outside GDPR is usually wrong. [Product analytics](https://pug.sh/learn/product-analytics-vs-web-analytics), which ties events to a person on purpose, is squarely in scope the moment an event is linked to an identifiable user.

> The most defensible event is the one you never needed to collect. Start from the questions you must answer, then capture only what those require.

## Lawful basis: you need one before you start

Article 6 gives six lawful bases for processing: **consent, contract, legal obligation, vital interests, public task, and legitimate interests**. For behavioural analytics, two are realistic in practice: **consent** or **legitimate interests**. Which applies depends on how intrusive the tracking is and the expectations of your users. Pick the basis before you instrument, and document it.

There’s a second, separate gate that trips up a lot of teams: Article 5(3) of the [ePrivacy Directive](https://eur-lex.europa.eu/eli/dir/2002/58/oj) (2002/58/EC, the “cookie law”). It generally requires **prior consent** before storing or reading non-essential cookies or local storage on a device, regardless of which GDPR lawful basis you later rely on. Most analytics touches device storage, so most analytics needs that consent first. Cookieless, minimal setups can reduce or remove the banner, but the requirement varies by jurisdiction.

This storage gate is what [cookieless analytics](https://pug.sh/learn/cookieless-analytics) is aimed at. Pug’s Web SDK defaults to it: no identifier is stored on the device (no cookie, no `localStorage` key), and the server derives a daily-rotating hash of the request’s project, IP, and user agent instead, which becomes unlinkable to anyone once that day’s salt expires. That targets the ePrivacy gate, but it does *not* settle the GDPR one: as the section above notes, an IP address is generally personal data, so you still need a lawful basis for the processing that derives from it. Cookieless narrows the problem; it doesn’t remove it.

## Consent done properly

When you do rely on consent, GDPR sets a high bar: it must be **freely given, specific, informed, and unambiguous**, by a clear affirmative action: no pre-ticked boxes, no bundling. And it must be as easy to **withdraw** as it was to give. The practical requirement for an analytics stack is simple to state and easy to get wrong: **don’t store anything on the device until you have consent, and stop the moment it’s withdrawn.** Start denied when you want nothing to fire at all, and persist the choice so a reload doesn’t quietly reset it to your seed value:

```
init(projectId, { apiKey, trackingConsent: { initial: 'denied', persist: true } })

// only after the user agrees, via clear affirmative action:
optInTracking()
```

The Pug [Web SDK](https://pug.sh/blog/web-analytics-sdk) has three consent states, and the default is the middle one, `'cookieless'`: events flow, but no identifier is stored on the device and `identify()` is disabled, so an install that never mentions consent still stores no identifier before it has a basis to. `'granted'` turns on identity and profiles. `'denied'` attaches no listeners at all, and manual `track()`/`identify()` calls are dropped rather than quietly queued for later replay. Leaving `'granted'` tears the listeners back down and deletes the stored identity, including any queued events. Sending those after someone withdrew would be a fresh act of processing on data they refused.

## The principles you instrument around

- **Purpose limitation:** use the data only for the purpose you disclosed; don’t repurpose analytics events for ad targeting or model training.
- **Data minimisation:** collect only what the purpose needs; every extra trait is extra risk.
- **Storage limitation:** keep data only as long as needed, then erase it; set and document retention windows.
- **Accuracy, integrity & confidentiality:** keep it correct and keep it secure.
- **Accountability:** be able to show how you meet all of the above.

Auditing your tracking plan for personal and sensitive fields before they ship is a good habit. The free [PII event auditor](https://pug.sh/tools/pii-event-auditor) flags identifiers in an event schema in the browser as a fast first pass. It is a helper, not a compliance sign-off.

## Data-subject rights and DSARs

Articles 15 to 21 give individuals rights to **access, rectification, erasure** (the “right to be forgotten”), **restriction, portability, and objection**, generally answerable within a month (Article 12(3)). For analytics, access and erasure are the ones with teeth: a data-subject access request (DSAR) means you must locate a person’s data, and an erasure or objection request means you must delete or stop. That’s far easier when you own the data store: with a self-hosted setup, events live in your own database where you can query, export, and purge by identity. The SDK’s `reset()` clears identity on the client at logout, but honouring a DSAR is a server-side operation on data you hold.

## International transfers

Chapter V restricts sending personal data outside the EU/EEA unless the destination offers adequate protection, through an **adequacy decision**, **Standard Contractual Clauses (SCCs)**, or a framework like the **EU-US Data Privacy Framework**. The Court of Justice’s [*Schrems II* judgment](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:62018CJ0311) (Case C-311/18, 16 July 2020) invalidated the previous US arrangement, the Privacy Shield, and forced a hard look at transfers to US-based cloud services. noyb then filed 101 complaints against websites using Google Analytics and Facebook’s business tools, and the EDPB’s [101 Task Force report](https://www.edpb.europa.eu/system/files/2023-04/edpb_20230328_report_101task_force_en.pdf) (28 March 2023) lists decisions on them from the Austrian, Danish, Estonian, Spanish, Finnish, French, Hungarian and Italian authorities. Three of those decisions, on Google Analytics:

- **Austria:** the Datenschutzbehörde decided on 22 December 2021 (GZ 2021-0.586.257) that the site in the complaint could not use Google Analytics in line with Chapter V, on the facts it established ([DSB newsletter 2/2022](https://dsb.gv.at/sites/site0344/media/downloads/newsletter_dsb_2_2022.pdf), in German).
- **France:** the CNIL ordered a website operator in 2022 to bring its Google Analytics use into line with Article 44 onward within one month, notably by ceasing to use the tool’s current version ([the decision, as published by the EDPB](https://www.edpb.europa.eu/system/files/2022-08/fr_2022-02_decisionpublic_redacted_0.pdf)).
- **Italy:** the Garante reprimanded the publisher Caffeina Media for transfers to Google in the US without adequate safeguards, and gave it 90 days to bring them into line with the GDPR ([press release of 23 June 2022](https://www.garanteprivacy.it/home/docweb/-/docweb-display/docweb/9782874), with an English version).

The Commission’s [adequacy decision for the EU-US Data Privacy Framework](https://eur-lex.europa.eu/eli/dec_impl/2023/1795/oj) (10 July 2023) now covers transfers to US companies certified under it, which changed the picture again. The cleanest way to take the transfer question off the table is to not transfer: keep event data on infrastructure in a region you choose. This is where [self-hosting](https://pug.sh/self-hosted-analytics) earns its keep.

## Security, breaches, and penalties

Controllers must apply appropriate security measures and, on a personal-data breach, notify the supervisory authority **within 72 hours** where feasible (Article 33), and affected individuals when the risk is high (Article 34). The penalties are why GDPR has teeth: up to **€20 million or 4% of worldwide annual turnover**, whichever is higher (Article 83(5)). The practical takeaway for analytics is the same as everywhere else: the less personal data you hold and the more control you have over where it lives, the smaller your exposure.

## A practical GDPR checklist for analytics

- **Pick a lawful basis** (usually consent or legitimate interests) and document it before you instrument.
- **Get cookie consent first** where ePrivacy applies; default tracking to off.
- **Make withdrawal real:** stop collecting the instant consent is revoked.
- **Minimise:** capture only the events and traits your purpose needs; audit the plan for PII.
- **Honour rights:** be able to fulfil access, erasure, and portability requests.
- **Set retention:** keep data only as long as needed, and document why.
- **Control transfers:** avoid sending data outside the EU/EEA, or rely on a valid mechanism.
- **Sign a DPA** with every processor; plan for 72-hour breach notification.

## Where open source and self-hosting fit

Open source helps on two fronts GDPR cares about: you can *read* exactly how data is handled, and you can *self-host* so it stays on servers you control, in a region you choose. Pug is AGPL-3.0 and self-hostable for exactly this reason: events stay in your own infrastructure, the Web SDK stores no identifier on the device and ties no event to a person until consent is granted (or, started with consent denied, sends nothing at all), and you hold the data store where retention, access, and erasure happen. None of that is automatic compliance, and none of it is legal advice. But a lawful basis, consent-first collection, minimisation, and self-hosting together give you a strong, defensible foundation, the same one that helps with the [DPDP Act](https://pug.sh/learn/dpdp-act-analytics) in India.

## Common questions

### Is Google Analytics GDPR-compliant?

It is contested. After the Schrems II judgment, the Austrian authority (December 2021), the French CNIL (2022) and the Italian Garante (June 2022), among others, found that websites using Google Analytics transferred personal data to the US without adequate safeguards; the transfers section of this guide links each decision. The EU-US Data Privacy Framework changed the picture again in July 2023, but the safest way to remove transfer risk is to keep analytics data on infrastructure you control. This isn’t legal advice. Confirm your setup with counsel.

### Do I need consent for analytics under GDPR?

Two separate questions apply. The ePrivacy Directive (the “cookie law”) generally requires prior consent before storing or reading non-essential cookies or local storage, which covers most analytics. Separately, GDPR needs a lawful basis to process the resulting personal data; for behavioural analytics that’s usually consent, sometimes legitimate interests. Cookieless, minimal setups can reduce the consent burden, but requirements vary by jurisdiction.

### What’s the difference between a controller and a processor?

The controller decides why and how personal data is processed: if you run the product and choose what to track, that’s you. A processor acts on the controller’s instructions, like a hosted analytics vendor. Controllers carry the primary accountability and must have a data-processing agreement (Article 28) with each processor.

### How does self-hosting help with GDPR?

Self-hosting keeps event data inside your own infrastructure, in a region you choose, which removes most cross-border-transfer questions and gives you direct control over retention, access, and erasure. It gives you a strong foundation for compliance, though the obligation still sits with you.

### Is this legal advice?

No. This is general guidance on applying GDPR principles to product analytics. GDPR is nuanced and enforcement varies by member state. Review your specific obligations with a qualified professional.
