# Log RevenueCat subscription cancellations and expirations in D1

Keep a D1 record for each cancellation or expiration, keyed by its RevenueCat event ID.

[Use template](https://dashboard.fasthook.io/workflow/new?templateKey=revenuecat-subscription-cancellations-to-d1&templateName=Log+RevenueCat+subscription+cancellations+and+expirations+in+D1)

**Required accounts**

- RevenueCat
- Cloudflare D1

## Record RevenueCat cancellations and expirations in D1

### 1. Trigger · Any Subscription Event

**RevenueCat**. Start the Workflow when any subscription event occurs.

### 2. Filter · Only cancellations and expirations

**FastHook**. Continue only when the configured conditions match the incoming record.

### 3. Action · Insert the subscription event once

**Cloudflare D1**. Run a statement with bound values, or send a batch. Each row in the results uses the column names from your query.

## Set up your workflow

1. **Create the subscription events table** In the destination D1 database, run CREATE TABLE IF NOT EXISTS subscription\_churn (event\_id TEXT PRIMARY KEY, event\_type TEXT, customer\_id TEXT, product\_id TEXT, event\_timestamp\_ms INTEGER, cancel\_reason TEXT, environment TEXT).
2. **Connect RevenueCat and select the D1 database** Connect the RevenueCat project in the trigger. In “Insert the subscription event once”, connect Cloudflare D1 and select the database that contains subscription\_churn. The filter forwards cancellations and expirations that have a RevenueCat event ID.
3. **Check an event against a test database** Use a RevenueCat sandbox cancellation or expiration. Check the D1 row for its event ID, type and environment. Processing the same event ID again should leave one row.

## Related integrations

- [RevenueCat integrations](https://www.fasthook.io/apps/revenuecat/integrations)
- [Cloudflare D1 integrations](https://www.fasthook.io/apps/cloudflare-d1/integrations)
