# Affiliate attribution

`pf_ref` identifies a promo participant; it is not a built-in affiliate commission or payout system. Use explicit checkout metadata for affiliate click IDs, and configure the receiving affiliate platform to recognize those fields. A reference supplied by the browser is attribution context, not verified identity or authority to pay a commission.

## 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](https://plandalf.com/docs/packages/sdk/interfaces/FlowEvent)
-   [Configure the SDK](https://plandalf.com/docs/sdk)
-   [Webhooks](https://plandalf.com/docs/api/webhooks)

Source: https://plandalf.com/docs/product-guides/affiliates/attribution
