> ## 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.

# Conversion goals

> Decide what counts as success and measure it in tests

A conversion goal is what a test is measured against. You manage goals in pagent under **Tracking → Goals**. Click **New goal** to create one:

| Goal type | Counts | Needs code on your site |
| - | - | - |
| **Event goal** | An event your site emits | Only to send the event, if pagent can't [observe it already](/docs/guides/tracking/instrumentation) |
| **Page view goal** | A visit to a specific page, such as `/thank-you` | No |
| **Click goal** | Clicks on a CSS selector on chosen pages | No |
| **Computed goal** | A filtered view of another goal | No |
| **Programmatic goal** | Conversions your code sends for this goal's label | Yes. **Deprecated**, use an event goal |

For anything that happens in your code or your backend, use an **event goal**.

## Create an event goal

<Steps>
  <Step title="Send the event">
    Make sure the event reaches pagent, from your [site code](/docs/guides/tracking/events), an [observed source](/docs/guides/tracking/instrumentation) or your [backend](/docs/guides/tracking/server-side-events). It is listed under **Tracking → Sources → Events** once it has arrived.
  </Step>

  <Step title="Create the goal">
    Go to **Tracking → Goals**, click **New goal** and choose **Event goal**. Select the **Event**. Events that have only been observed so far are marked `(observed)`.
  </Step>

  <Step title="Choose how to count">
    **Count conversions** sets how often one visitor can convert: **Once per session** (default), **Once per visit** or **Every time**. Optionally set a **Goal Name**; it defaults to the event label.
  </Step>

  <Step title="Save">
    Click **Add Goal**.
  </Step>
</Steps>

The goal is computed retroactively: every occurrence of the event that was already recorded counts from day one, in every arm of every test.

### Advanced settings

Open **Advanced** in the goal dialog for:

* **Measure**: **Converted** (did the visitor convert), **Count** (how many times), **Sum** (a numeric payload field such as `cart.items`) or **Revenue** (the event's `revenue`).
* **Only count users with at least N occurrences**, for Count and Sum.
* **Counting window**: count only conversions within a number of hours **After exposure** to the test (default 72), or only during the **Final days** of the test (default 14).
* **Delay**: start counting a number of hours after exposure. A negative value includes conversions from just before exposure.
* **Outlier capping** for revenue and sums: **Automatic**, **Percentile**, **Fixed** or **Off**.
* **Goal direction**: **Higher is better** or **Lower is better**, for goals like cart abandonment or error rate.

## Add goals to a test

1. Open the test in the **Editor**.
2. Under the settings icon, open **Manage conversion goals**.
3. Add the goal and choose whether it is the primary goal.

The same goal can be used in as many tests as you like.

## Migrating from programmatic goals

Programmatic goals only counted conversions sent with `kind: "conversion"` and a label matching the goal, and only once that goal had been published to your site. Moving to events takes three steps.

<Steps>
  <Step title="Send an event with the same label">
    Change `kind: "conversion"` to `kind: "event"`. Keep the label, revenue and properties as they are.

    ```javascript theme={"dark"}
    // Before (deprecated)
    window._pgnt.push({ kind: "conversion", label: "purchase", revenue: 2499 });

    // After
    window._pgnt.push({ kind: "event", label: "purchase", revenue: 2499 });
    ```

    Replace `window.pagent.track("signup")` with `window._pgnt.push({ kind: "event", label: "signup" })`. On your backend, move from `/v2/conversions` to [`/v2/events`](/docs/guides/tracking/server-side-events).
  </Step>

  <Step title="Create an event goal">
    Create an event goal on the label as described above and add it to your new tests.
  </Step>

  <Step title="Retire the programmatic goal">
    Once no running test uses the programmatic goal anymore, archive it.
  </Step>
</Steps>

<Warning>
  A running test keeps measuring the goals it started with. If a running test uses a programmatic goal, keep sending the conversion until that test ends. You can send both calls side by side during the switch:

  ```javascript theme={"dark"}
  window._pgnt.push({ kind: "event", label: "purchase", revenue: 2499 });
  window._pgnt.push({ kind: "conversion", label: "purchase", revenue: 2499 }); // remove after running tests end
  ```
</Warning>

The event goal's history starts with the first event you send, not with your older conversions.
