agentref_cid) on a Stripe payment event. How you get that token into Stripe depends on which Stripe surface you use.
Choose the checkout route first
Before editing code, decide which route applies:- Route A — Hosted Stripe on the AgentRef website: Payment Link, Buy Button, or Pricing Table is on the website where AgentRef is installed.
- Route B — Website custom checkout: Buy button is on the AgentRef website and calls your backend to create Stripe Checkout.
- Route C — External app checkout: Buy button is in a Chrome extension, desktop app, mobile app, external dashboard, or another surface where AgentRef is not installed.
How getCheckoutMetadata() works
The tracking script stores a agentref_cid click token in a first-party cookie when a visitor arrives through an affiliate link. At checkout time, your code reads that token and embeds it into the Stripe session before the customer pays.
checkout.session.completed or invoice.paid, AgentRef’s webhook reads the metadata and matches the payment to the original click.
If
getCheckoutMetadata() returns an empty object, the visitor has no affiliate attribution. You can still call your checkout API – AgentRef will simply not create a conversion for that payment.Integration by Stripe surface
- Stripe Checkout (custom session)
- Stripe Payment Links
- Stripe Pricing Table
- Custom payment flow
- External app or extension
This is the most common integration – you create a Checkout Session server-side and redirect the customer to it.Step 1: Read the tracking metadata on your frontend:Step 2: Pass the metadata into the Stripe session on your backend:
Verifying attribution
After completing a test purchase, you can confirm attribution was captured correctly by checking the conversion in your AgentRef dashboard. The conversion will appear under Conversions with statuspending.
To verify programmatically, look at the Stripe session’s metadata in the Stripe dashboard – you should see agentref_cid, agentref_pid, and agentref_source fields populated for custom checkout flows. For Payment Links, Buy Buttons, and Pricing Tables, verify that Stripe received the click token via client_reference_id.
What happens without metadata
If a Stripe payment event arrives withoutagentref_cid in the metadata (and without a client_reference_id for Payment Links/Pricing Tables), AgentRef will not create a conversion for that payment. The payment is not affected – only the affiliate attribution is skipped.
Coupon-based attribution does not require metadata. If the customer uses a coupon code linked to an affiliate, a conversion is created regardless of whether tracking cookies were set.