---
name: kimaai_lead_erased
type: action
since: 1.6.0
tier: free
feature: lead-capture
area: leads-customer-centre
summary: Fires when a lead's details were erased on a personal data erasure request, or the lead was deleted.
parameters:
  - name: lead_id
    type: int
    description: The lead's ID. After an erasure the row stays, with the status erased and without the details; after a deletion it is gone.
---

# kimaai_lead_erased

## When it fires

Once for every lead that leaves KimaAI:

- Tools > Erase Personal Data: for every lead with the person's email address. KimaAI has deleted the lead's conversation, with its feedback and ratings, and removed the details from the lead before it fires; only the ID, the session, the status and the dates stay on the row, so the visitor is not asked again. A lead whose details could not be removed does not fire it.
- The Leads page: after a lead was deleted, alone or with others; the conversation stays in the chat history.
- The "Keep leads" period of the lead settings: after the daily job deleted a lead older than the period.

After a deletion the row is gone. A lead erased before is not announced again when it is deleted, so the action fires once per lead.

KimaAI hooks it itself: Insights deletes the conversions of the lead (after an erasure also those of its conversation), and with Pro the lead webhook gets a `lead.erased` event. The CRMs KimaAI sends leads to keep their copy.

## Example

```php
add_action(
  'kimaai_lead_erased',
  function (int $lead_id): void {
    // Your own follow-up notes, kept per lead ID, go with the lead.
    $notes = get_option('my_theme_lead_notes', []);
    if (isset($notes[$lead_id])) {
      unset($notes[$lead_id]);
      update_option('my_theme_lead_notes', $notes, false);
    }
  }
);
```

The details are gone when the action fires, and after a deletion the whole row, so find your own records by the lead ID: store it with them when the lead comes in (`kimaai_lead_saved`).

## Related

- `kimaai_lead_saved`: fires when the lead was stored, with its ID.
