Skip to main content
Use server-side tracking when the JavaScript snippet isn’t an option – custom checkout flows, mobile apps, or server-rendered pages.

When to Use

  • Custom payment flows that don’t use Stripe Checkout
  • Mobile apps or native clients
  • Server-rendered redirects where you intercept the affiliate link yourself

Workflow

1

Capture the ref parameter

When a visitor arrives with ?ref=AFFILIATE_CODE, extract the parameter server-side.
2

Record the click

Call POST /api/tracking/click to register the click and get a clickId.
3

Store the clickId

Persist the clickId in your session, database, or cookie.
4

Create the conversion

When the visitor converts, call POST /api/v1/conversions with the clickId.

Record a Click

curl -X POST https://www.agentref.co/api/tracking/click \
  -H "Content-Type: application/json" \
  -d '{
    "programId": "prg_abc123",
    "affiliateCode": "john",
    "referrerUrl": "https://blog.example.com/review",
    "landingUrl": "https://yourapp.com/?ref=john"
  }'
Response:
{
  "clickId": "clk_abc123xyz",
  "affiliateId": "aff_456",
  "programId": "prg_abc123"
}

Verify Tracking (Optional)

Confirm that a click was recorded correctly:
curl -X POST https://www.agentref.co/api/tracking/verify \
  -H "Content-Type: application/json" \
  -d '{"programId": "prg_abc123", "clickId": "clk_abc123xyz"}'

Create a Conversion

When the visitor converts, pass the stored clickId:
import AgentRef from 'agentref'

const client = new AgentRef({ apiKey: 'ak_live_YOUR_KEY' })

await client.conversions.create({
  programId: 'prg_abc123',
  clickId: 'clk_abc123xyz',
  amount: 9900,
  currency: 'usd',
  externalId: 'order_12345',
})
The click endpoint (/api/tracking/click) is unauthenticated – it’s designed to be called from browsers or your server. The conversion endpoint (/api/v1/conversions) requires a merchant API key.