---
title: "Delete raw events on a schedule · Agent Wranglers"
url: https://agentwranglers.se/playbook/analytics/privacy-and-consent/analytics-retention
id: ANA-10
level: Recommended
applies: eu-users
updated: 2026-10-27
build: a2a6bdfed830
tokens: 977
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Delete raw events on a schedule

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Privacy and consent](https://agentwranglers.se/playbook/analytics/privacy-and-consent.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: ANA-10
- Level: Recommended
- Chapter: [Privacy and consent](https://agentwranglers.se/playbook/analytics/privacy-and-consent.md)
- Rule: Keep raw events with an analytics ID for a fixed time only, such as 14 months. Then delete them or roll them up into counts without IDs.
- Check: A query finds no raw event older than the stated period. The aggregate table still has rows from before it, and none of them hold an ID.
- Applies when: The project has users in the EU.
- How: Set the period in the privacy policy and in one setting. Hosted tools have a setting for it, such as Google Analytics 4's choice of 2 or 14 months. For your own store, drop old partitions as [Expire warehouse data by partition](https://agentwranglers.se/playbook/data-engineering/personal-data-in-the-warehouse/warehouse-retention.md) describes. Build daily aggregates without IDs first, so long-term charts keep working. Include experiment exposure logs and the rejects table. The general rule is [delete old data automatically](https://agentwranglers.se/playbook/data/personal-data/retention-jobs.md). Record the period in [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### SQL example

```sql
-- PostgreSQL: events partitioned by month; the job detaches and drops partitions past the limit
ALTER TABLE events DETACH PARTITION events_2025_07;
DROP TABLE events_2025_07;
```

### JavaScript example

```js
const RETENTION_MONTHS = 14;
export async function dropExpiredPartitions(now = new Date()) {
  const cutoff = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - RETENTION_MONTHS, 1));
  for (const partition of await db.eventPartitionsBefore(cutoff)) await db.dropPartition(partition);
}
```

### Python example

```python
from datetime import date

RETENTION_MONTHS = 14

def drop_expired_partitions(today: date):
    months = today.year * 12 + today.month - 1 - RETENTION_MONTHS
    cutoff = date(months // 12, months % 12 + 1, 1)
    for partition in db.event_partitions_before(cutoff):
        db.drop_partition(partition)
```

## Sources

- [GDPR Article 5 on principles of processing](https://eur-lex.europa.eu/eli/reg/2016/679/oj)

## Related rules

- DEN-26 [Expire warehouse data by partition](https://agentwranglers.se/playbook/data-engineering/personal-data-in-the-warehouse/warehouse-retention.md) in Data engineering
- DAT-31 [Delete old data automatically](https://agentwranglers.se/playbook/data/personal-data/retention-jobs.md) in Data and databases
- CMP-11 [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md) in Compliance and governance

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/analytics/privacy-and-consent/analytics-retention">Agent Wranglers product analytics and experiments playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Hide personal data from session recordings](https://agentwranglers.se/playbook/analytics/privacy-and-consent/session-recording-privacy.md)
- [Privacy and consent](https://agentwranglers.se/playbook/analytics/privacy-and-consent.md)
