> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketflows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How events and triggers work

> How something happening in your product becomes a message sent by a business

A campaign is sent when a business decides to send it. A trigger is sent when
something happens: a customer books an appointment, abandons a cart, or has a
birthday. You tell Pocketflows that it happened by tracking an event, and each
business decides what to send in response by setting up a trigger.

To set this up, see
[Send messages when something happens in your product](https://docs.pocketflows.com/how-to/trigger-messages-from-events.md).

## Events and triggers

* An **event** is a record that something happened to one customer of one
  business, along with any data about it.
* A **trigger** belongs to a business. It names the event it listens for, an
  optional filter, and the steps to run: sending an email or SMS, waiting for a
  set time, or continuing only if a filter matches. See
  [Build segments and triggers with the API](https://docs.pocketflows.com/how-to/build-segments-and-triggers-with-the-api.md#steps).

Your platform owns the events, because only you know when something happened.
The business owns the triggers, because it decides how to respond. This split is
what lets every business on your platform automate its own marketing from the
same integration.

## Two kinds of event

**Project-defined events** are the ones you define and track, such as
`appointment.booked`. You define each one once for your whole project, with a
phrase that completes the sentence "When...", such as "a customer books an
appointment". That phrase is what businesses see when they choose what a trigger
listens for.

**Built-in events** are raised by Pocketflows itself, so you do not track them:

| Event | Raised when |
| - | - |
| Customer created | A new customer is added to the business. |
| Customer joined segment | A customer becomes part of a chosen segment. Membership is checked about every 15 minutes, so a filter based on time can add a customer as time passes. |
| Customer birthday | It is the customer's birthday. See [Automate customer birthday campaigns](https://docs.pocketflows.com/how-to/automate-birthday-campaigns.md). |
| Lead captured | A new lead is captured for the business. |

## What happens when you track an event

Tracking an event stores it and returns straight away. The rest happens in the
background:

1. Pocketflows finds the customer the event is about, using the identifier in
   the event's `data`.
2. It finds the project-defined event that matches the `event` you sent.
3. It finds the business's active triggers that listen for that event.
4. For each trigger, it checks the trigger's filter against the customer and the
   event's data.
5. For each trigger that matches, it starts running the trigger's steps for that
   customer.

An event that gets through all five steps produces one trigger execution per
matching trigger. Each tracked event is handled separately, so tracking the same
event twice runs the trigger twice. To retry a track request safely, send an
[idempotency key](https://docs.pocketflows.com/reference/idempotency-keys.md).

## Why an event can do nothing

A tracked event is always stored, but it only sends something if every step
above succeeds. It does nothing when:

* no customer in the business matches the identifier you sent,
* the `event` does not match any project-defined event in your project, or
* the business has no active trigger listening for that event.

None of these is an error, and the track request still succeeds. This is by
design: you can start tracking an event for every business before any of them
has set up a trigger for it.

## Event data

The `data` you send with an event is available to the trigger in two ways:

* **As filters**, so a trigger can run only for some events, such as bookings
  for a particular service. See
  [event filters](https://docs.pocketflows.com/concepts/segments-and-filters.md#event-filters).
* **As variables**, so a message can include details of the event, such as the
  appointment time. See
  [How personalization variables work](https://docs.pocketflows.com/concepts/personalization-variables.md).

An event can also carry a purchase amount, which Pocketflows uses to attribute
revenue to the marketing that drove it. See
[How ad attribution works](https://docs.pocketflows.com/concepts/ad-attribution.md).

## Related

* [Send messages when something happens in your product](https://docs.pocketflows.com/how-to/trigger-messages-from-events.md)
  for the steps.
* [Tracking event payload examples](https://docs.pocketflows.com/reference/tracking-event-payloads.md) for the
  request bodies.
* [Give businesses pre-built campaigns, triggers and emails](https://docs.pocketflows.com/how-to/offer-prebuilt-templates.md)
  to ship a ready-made trigger for an event.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.