Skip to main content
AgentRef resolves conversions by finding the click token (agentref_cid) on a Stripe payment event. How you get that token into Stripe depends on which Stripe surface you use.

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.
// Returns { agentref_cid, agentref_pid, agentref_source }
// Returns {} if no active attribution exists (visitor came directly)
const meta = window.AgentRef.getCheckoutMetadata();
When Stripe fires 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

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:
window.AgentRef.ready(async function() {
  const trackingMeta = window.AgentRef.getCheckoutMetadata();

  const response = await fetch('/api/create-checkout', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      priceId: 'price_xxx',
      agentrefMeta: trackingMeta,
    }),
  });

  const { url } = await response.json();
  window.location.href = url;
});
Step 2: Pass the metadata into the Stripe session on your backend:
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

app.post('/api/create-checkout', async (req, res) => {
  const { priceId, agentrefMeta } = req.body;

  const session = await stripe.checkout.sessions.create({
    mode: 'subscription',
    line_items: [{ price: priceId, quantity: 1 }],
    success_url: 'https://yoursite.com/success',
    cancel_url: 'https://yoursite.com/pricing',
    // Pass AgentRef metadata – this is what the webhook reads
    metadata: {
      ...agentrefMeta,
    },
  });

  res.json({ url: session.url });
});

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 status pending. 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.
Use Debug Mode to inspect cookies and confirm agentref_cid is set before triggering a test checkout.

What happens without metadata

If a Stripe payment event arrives without agentref_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.