---
title: "Track only after consent · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/product-analytics/analytics-consent
updated: 2026-10-20
licence: "All rights reserved"
---

# Track only after consent

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
- Rule: Send no analytics event that uses device storage or identifies a person until that person has agreed. Read the stored choice in the tracking module itself.
- How: The consent rules live in the website playbook. Follow [store nothing extra without a yes](https://agentwranglers.se/playbook/website/privacy/cookie-consent), [count visits without tracking people](https://agentwranglers.se/playbook/website/privacy/analytics-privacy) and [treat the privacy signal as a no](https://agentwranglers.se/playbook/website/privacy/global-privacy-control). In this chapter, the point is where the check sits. Put it inside the generated tracking function, so no feature can forget it. Without consent, either drop the event or send a count with no ID and no storage.
- Check: A browser test with a fresh profile clicks through sign-up and checkout without consenting. The collector receives no event with a user or device ID, and no analytics storage exists.

Example:

```js
export function track(name, properties) {
  const consent = readConsent(); // the stored choice from the consent banner
  if (!consent.analytics || navigator.globalPrivacyControl) return sendAnonymousCount(name);
  navigator.sendBeacon('/collect', JSON.stringify({ name, properties, anonymous_id: consent.analyticsId }));
}
```

```python
def track(request, name: str, properties: dict):
    consent = read_consent(request)  # the stored choice, server side
    if not consent.analytics or request.headers.get("Sec-GPC") == "1":
        return record_anonymous_count(name)
    collect({"name": name, "properties": properties, "anonymous_id": consent.analytics_id})
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/product-analytics/analytics-consent`.

- Previous: [Validate every event before you store it](https://agentwranglers.se/playbook/data/product-analytics/event-validation)
- Next: [Keep personal data out of events](https://agentwranglers.se/playbook/data/product-analytics/events-without-personal-data)
- [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
