# Affiliate attribution
Capture partner, referral, and campaign references with URL parameters, SDK metadata, and checkout events.
Source: /docs/affiliates/attribution
Last modified: 2026-06-18
Use `pf_ref` as the canonical public reference parameter for new Plandalf links.

## Capture a reference from the URL

```html
https://example.com/sales-page?pf_ref=partner_123
```

When the SDK loads, it can attach that reference to the visitor identity and later checkout calls.

## Pass explicit metadata

For affiliate platforms that expose a click ID or referral code in JavaScript, pass metadata at checkout time.

```js
await plandalf.present("pro-plan", {
  metadata: {
    affiliate_click_id: window.tolt_referral,
    source: "partner"
  }
});
```

## Lazy metadata

If an affiliate script loads after the Plandalf script, configure metadata as a function so it is evaluated when the checkout session is created.

```js
plandalf("configure", {
  metadata: {
    tolt_referral: () => window.tolt_referral
  }
});
```

## Verify after purchase

Listen for `purchase` events and confirm the resulting invoice or webhook contains the expected attribution context.

```js
const handle = plandalf.present("pro-plan");

for await (const event of handle.events) {
  if (event.type === "purchase") {
    console.log(event.invoice);
  }
}
```

## Related docs

- [Live events](/docs/sdk/events)
- [Configure the SDK](/docs/sdk/configure)
- [Webhooks](/docs/api/webhooks)