# Goals & conversions

This is the markdown version of https://statlark.com/docs/goals-conversions. Every docs and Learn page has one: add .md to its address. Index: https://statlark.com/llms.txt

A goal is any conversion you care about — `signup`, `purchase`, `pro_upgrade`. Fire it from your site and Statlark ranks your sources, pages, and revenue by it. Nothing to configure in the dashboard first — goals appear the moment they fire.

## Fire a goal

Call `goal()` the moment the conversion happens, or use a `data-statlark-goal` attribute to fire one on click with no JavaScript.

```js
// Fire a goal the moment a conversion happens — e.g. right after signup.
// The script is deferred, so guard for it.
window.statlark?.goal("signup");

// Attach properties to segment it later (e.g. by plan).
window.statlark?.goal("pro_upgrade", { plan: "pro" });
```

```html
<!-- Or fire one on click, no JavaScript required. -->
<button data-statlark-goal="signup">Create account</button>

<!-- With properties, as a JSON attribute. -->
<button data-statlark-goal="pro_upgrade" data-statlark-props='{"plan":"pro"}'>
  Upgrade
</button>
```

In TypeScript, `window.statlark` needs a declaration. Add this once, for example as `statlark.d.ts`:

```ts
// The script tag's global. Optional, because the script may be blocked or
// not loaded yet; that's what the ?. guards are for.
declare global {
  interface Window {
    statlark?: {
      goal(name: string, props?: Record<string, unknown>): void;
      event(name: string, props?: Record<string, unknown>): void;
      identify(data: Record<string, unknown>): void;
      reset?(): void;
      getVisitorId(): string | null;
    };
  }
}

export {};
```

The first time a goal fires it shows up on the Goals card with its conversion rate, top sources, and entry pages — and, once Stripe is connected, the revenue it drove.

## <a id="properties"></a>Segment by property

Attach properties to a goal to break it down later — say `plan` or `product`. Pass them as the second argument to `goal()`, or declaratively with `data-statlark-goal-*` attributes (a `data-statlark-props` JSON blob works too).

```js
// Pass properties as the second argument to segment the goal later.
window.statlark?.goal("pro_upgrade", { plan: "pro", seats: 5 });
```

```html
<!-- Declaratively: one attribute per property (kebab-case → snake_case). -->
<button data-statlark-goal="pro_upgrade" data-statlark-goal-plan="pro">
  Upgrade
</button>
```

Keep properties small: up to **20 per goal**, keys up to 64 characters, values up to 500. Values should be strings, numbers, or `true`/`false` — anything else is dropped.

On the Goals card, the **Conversion by property** section lets you pick a property and see conversions split across its values — how many `pro_upgrade`s came from each `plan`, say.

## Custom events

Not everything is a conversion. Record anything else you want to count with `window.statlark?.event(name, props)`: a video play, a copied snippet, a downloaded PDF. The `?.` guards it the same way as a goal, since the script is deferred. Clicks on outbound links are recorded on their own as `outbound_click`, with the destination in a `domain` property.

The **Events** tab of the Goals card lists your events with how many times each fired and how many visitors fired it, and splits the event you pick by one of its properties. Properties follow the same limits as goals. Custom events are never billed.

A custom event isn’t a conversion: it has no conversion rate, revenue or alerts. When something should count as one, fire a goal instead.

## <a id="ai-prompt"></a>Hand this to your AI

For AI tools: this is the prompt a customer pastes in to start this task. If you are already following it, don’t start again: use the rest of this page as the guide.

Paste this into Claude Code, Cursor or another AI coding tool, in your project. It never needs your API key.

```
Track this project's conversions as Statlark goals.

Follow this guide for the exact code: https://statlark.com/docs/goals-conversions.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.

1. Check how the site loads Statlark: the script tag, consent.js, @statlark/web or a first-party proxy. If you can't find it in this code, stop and ask me how it's added, for example through Google Tag Manager. Don't install it as part of this.
2. Find the conversions in this code, such as signup, checkout or upgrade. List them with the goal name you'd give each, such as signup or pro_upgrade, and ask me to confirm before you change anything. If I've already named the goals, use those. If something worth counting isn't a conversion, such as a video play, suggest a custom event.
3. Fire each goal once, in browser code, when the conversion has actually happened, such as after the signup request succeeds. Use a data-statlark-goal attribute only where the click itself is the conversion. If the only sign of a conversion is a page loading, such as a thank-you page, ask me first, because a call made before the script loads is skipped. If a conversion only completes on the server, such as in a payment webhook, ask me first too: a goal sent from the server needs an API key, and a retried call counts it twice.
4. Use the guide's guarded goal call, window.statlark?.goal("signup"), and guard a custom event the same way, as in window.statlark?.event("video_play"). If the project uses @statlark/web, call them on its handle instead. If the project uses TypeScript and window.statlark doesn't type-check, add the guide's declaration once: that's the only other change allowed.
5. Don't use the names payment, subscription_started or subscription_renewed. Statlark creates those itself, but only for Stripe payments it can credit to a visitor. Don't tell me checkout is covered unless the checkout code already carries the Statlark visitor ID, or the site calls identify with the customer's email (user_email) and it matches the email Stripe gets.
6. Properties are optional. Keep them short, such as plan, and never put emails, names or other personal details in them.
7. Don't change anything else. Finish by telling me which goals you added and where. Remind me to trigger each one on the live site and look for it on the Goals card, because visits from localhost aren't counted by default.
```

## Pick your #1 KPI

One goal can be your north-star metric. Set it under [Settings → Your #1 KPI](https://statlark.com/settings). The Goals card then opens on that goal, and the Pages card’s conversion rate uses it — handy when signups, not dollars, are what you’re optimising today.

## <a id="targets"></a>Set a target

Under [Settings → Targets](https://statlark.com/settings), give a number a monthly or quarterly target: revenue (net of refunds, in the site’s currency), unique visitors, or the conversions of one goal. Each metric has one target — save another for the same metric and it replaces the old one. Only workspace owners and admins can change targets.

Months and quarters are calendar periods in the site’s time zone. Progress always covers the *current* period so far, whatever range the Overview is showing, and it’s site-wide — so the meters hide while a filter is on. Revenue and Visitors targets show under those numbers at the top of the Overview; a goal’s target shows on the Goals card when that goal is selected.

Once 10% of the period has passed, the meter adds **on pace for X%**: where you’d finish if the rest of the period goes like the part so far. The small tick on the bar marks where an even pace would put you today, so a fill short of the tick means you’re behind. Hover the meter for the exact numbers.

## Reserved Stripe goals

Once you [connect Stripe](https://statlark.com/docs/revenue-attribution.md) and your payments are credited to visitors, by stamping the visitor ID at checkout or by calling `identify` with the customer’s email, Statlark turns those payments into goals, with no extra code:

- `payment` — every successful payment (one-time or subscription).
- `subscription_started` — the first invoice of a new subscription.
- `subscription_renewed` — each renewal invoice.

They behave like any other goal — rank them by source, chart them over time, and set one as your #1 KPI or alert on it. A payment with no visitor to credit when it arrives still counts as revenue, but doesn’t become a goal, even if the person identifies later. When a credit moves to an earlier visit by the same person, its goals [move with it](https://statlark.com/docs/revenue-attribution.md#resolution).

Because they come from payments, these goals [never count toward your plan’s event allowance](https://statlark.com/docs/billing.md). Goals you send yourself always count, even one named `payment`.

## Conversion alerts

Get an email the moment a goal fires — your own cha-ching. Under [Settings → Conversion alerts](https://statlark.com/settings), pick a goal, enter where to send it, and you’re done. It works for goals you fire and the reserved Stripe goals alike, so you can be emailed on every `payment` without writing any code.

Last reviewed 25 November 2026
