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

# How tracking works

> Send events, then build conversion goals on top of them

pagent tracking has two layers:

1. **Events** are facts your website reports: `purchase`, `signup`, `add_to_cart`. An event is just a label, with optional revenue and properties. Nothing has to be configured in pagent before you send one.
2. **Conversion goals** decide which events count as success. You create them in the dashboard on top of events that already arrive, and attach them to tests.

Keeping the two apart means your code only describes what happened on your site. Deciding what to measure happens in pagent, and you can change it without touching your site again.

```javascript theme={"dark"}
// On your site: report what happened
window._pgnt = window._pgnt || [];
window._pgnt.push({ kind: "event", label: "purchase", revenue: 2499 });
```

Then, in pagent, open **Tracking**, click **New goal**, choose **Event goal**, and pick `purchase`. That's the whole setup.

## Why events

* **Retroactive.** An event goal is computed over every event already recorded with that label. Create a goal today on an event you have been sending for a month, and it counts from day one.
* **No coupling to the dashboard.** Events are sent by label. Renaming a goal, adding a new one or archiving an old one never requires a code change on your site.
* **One event, many goals.** The same `purchase` event can back a conversion goal, a revenue goal and a funnel step.
* **Counted in every test arm.** Events are recorded for control and variants alike, so any test can measure them.

## Ways to get events into pagent

| Source | When to use it | Guide |
| - | - | - |
| `window._pgnt.push({ kind: "event" })` | You can add a line of code where the action happens. | [Sending events](/docs/guides/tracking/events) |
| dataLayer pushes and window events | Your site already pushes to a Google Tag Manager dataLayer or dispatches custom events. pagent listens for them, no code change needed. | [Instrumentation](/docs/guides/tracking/instrumentation) |
| Triggers | A condition on the page (for example a non-empty cart) should count as an event. | [Instrumentation](/docs/guides/tracking/instrumentation#triggers-as-events) |
| Instrumentation scripts | The action is only visible with a small script (a form submit, a third-party widget callback). | [Instrumentation](/docs/guides/tracking/instrumentation#instrumentation-scripts) |
| REST API | The action happens on your backend: payment confirmations, CRM updates, webhooks. | [Server-side events](/docs/guides/tracking/server-side-events) |

Click goals and page view goals need no events at all. See [Conversion goals](/docs/guides/tracking/conversion-goals).

## Deprecated: sending conversions directly

<Warning>
  Sending conversions for a specific goal from your code is deprecated. This covers `window._pgnt.push({ kind: "conversion" })`, `window.pagent.track()`, **Programmatic goals** in the dashboard, and the `/v1/conversions` and `/v2/conversions` server endpoints. They keep working, but new integrations should send events and build event goals on top of them.
</Warning>

The old flow required a Programmatic goal with a matching label to exist and be published before any conversion counted, and only counted from that point on. Events remove that ordering problem. See [Migrating from programmatic goals](/docs/guides/tracking/conversion-goals#migrating-from-programmatic-goals) for the switch.
