# Track conversions with JavaScript and give goals a value

You'll count conversions your site's code knows about, like a completed checkout, and see the value each campaign or test version brings in.

Available on the Scale and Pro plans.

Count the conversions only your site's code knows about, like a completed checkout, a booked call or a signup inside your app, and see how much value each campaign and test version brings in. One line of JavaScript reports the conversion. RightMessage handles which campaign and version gets the credit.

Use a **JavaScript event** goal when a page view, click or form submission can't tell you the conversion really happened. You'll need someone who can add code to your site.

## 1. Create a JavaScript event goal

1. Open **Conversion Goals** under **Personalize** and choose **New goal**.
2. Under **What should count as a conversion?**, choose **JavaScript event** ("Your site's code reports a conversion, like a completed checkout.").
3. Enter an **Event key**, such as `purchase`. It starts with a lowercase letter and uses only lowercase letters, digits and underscores, up to 40 characters.
4. Under **Which pages?**, leave the default to count it on every page, or narrow it to the pages where the code runs.
5. Optionally, enter a **Value per conversion**, such as your average order value.
6. Name the goal, add it to the campaigns that should measure it, and choose **Create goal**.

![New conversion goal with the JavaScript event type selected, the event key purchase and a value per conversion](https://rightmessage.com/help/screens/goal-javascript-event.light.webp)

JavaScript events can't be checked against past visits. Conversions start counting once you create the goal and add the code to your site.

## 2. Report the conversion from your site

Add this where your code knows the conversion happened, using your goal's event key:

```javascript
window.RM = window.RM || [];
window.RM.push(['conversion', 'purchase']);
```

To record what this conversion was worth, and to make it safe to repeat, pass a `value` and an `id`:

```javascript
window.RM.push(['conversion', 'purchase', { value: 129.5, id: 'order_1042' }]);
```

- `value` overrides the goal's **Value per conversion** for this conversion. It's a number from 0 to 1,000,000,000, rounded to 2 decimals, with no currency.
- `id` is your own reference, such as an order number: up to 64 letters, digits, `_`, `.`, `:` or `-`. If a visitor reloads the thank-you page, the same `id` doesn't count the conversion twice. Without an `id`, each goal counts once per page view.

The call is safe to make before RightMessage loads: it waits and is recorded once RightMessage runs. It never throws. An unknown key is ignored, and the browser console shows `[RightMessage] Ignored conversion: unknown or invalid key "<key>"`. An invalid value or id logs a warning, and the conversion still records.

Nothing is recorded for an [excluded browser](https://rightmessage.com/help/exclude-test-visitors), before cookie consent when the project [waits for consent](https://rightmessage.com/help/use-rightmessage-with-a-cookie-banner), or in a dashboard preview. The [debugger](https://rightmessage.com/help/using-the-rightmessage-debugger) shows the conversion it would have sent. See the [JavaScript command reference](https://rightmessage.com/help/javascript-hooks) for every detail.

## 3. Read the value in your results

Wherever the goal's results appear, a line beside them shows **Conversion value** (the total) and **Value per visitor**, such as "Conversion value 1,240.50 · Value per visitor 3.10".

Value is "Shown next to results. It never decides a winner." A/B test verdicts always come from how many visitors converted. Use value to judge whether a winner is worth keeping, for example when a version gets fewer but larger orders.

## Check that it's working

1. Open the page where the code runs in a browser that isn't excluded, and complete a test conversion.
2. Check the goal's overview for the new conversion.
3. If it doesn't appear, check the browser console for an `Ignored conversion` message, the goal's pages, and that the event key matches exactly. Keys are case-sensitive.

For other goal types, see [create and manage conversion goals](https://rightmessage.com/help/goals-and-conversion-tracking).
