How It Works
- Create an API key in your pagent dashboard under Settings > API Keys
- Capture session variables on the frontend using
window._pgnt.variables("goal_label") - Pass the variables to your backend (e.g., in a form submission or AJAX request)
- Send a conversion event from your backend via
POST /v1/conversions
Important: Thesession_idlinks each server-side event to the visitor’s browser session and active experiments. Without a validsession_id, the conversion cannot be attributed to an experiment.
Prerequisites
- The pagent SDK installed on your website
- At least one goal configured in the Tracking section of your dashboard (see Tracking Revenue for setup instructions)
1. Create an API Key
- Navigate to Settings > API Keys in your pagent dashboard
- Click “Create API Key”
- Give it a descriptive name (e.g., “Production Backend”)
- Copy the API key immediately
Important: The API key is displayed only once at creation. Store it securely as an environment variable. If you lose the key, delete it and create a new one.
2. Capture Variables from the SDK
Usewindow._pgnt.variables() to get the session identifiers and goal UUID you need for the API call. Pass the goal label as a string argument:
| Property | Description |
|---|---|
session_id | The current browser session identifier |
user_id | The visitor’s persistent user identifier |
visit_id | The current page view identifier |
conversion_id | UUID of the goal matching the label, or null if no match |
Note: Ifconversion_idisnull, the label does not match any configured goal. Double-check the goal label in your Tracking settings.
Passing Variables to Your Backend
Send the captured variables alongside your existing request data:3. Send Conversion Events
Endpoint
| URL | https://ingest.pagent.ai/v1/conversions |
| Method | POST |
| Authorization | Bearer <API_KEY> |
| Content-Type | application/json |
Request Body
The request body contains anevents array with 1 to 100 conversion events:
| Field | Type | Required | Description |
|---|---|---|---|
session_id | string | Yes | From _pgnt.variables() |
user_id | string | Yes | From _pgnt.variables() |
conversion_id | string | Yes | Goal UUID from _pgnt.variables() |
label | string | No | Human-readable goal tag (useful for debugging) |
revenue | integer | No | Value in cents (e.g., 999 = $9.99) |
properties | object or array | No | Custom metadata about the conversion |
time | number | No | Unix timestamp in milliseconds (defaults to current time) |
Response
| Status | Body | Description |
|---|---|---|
200 | { "accepted": 1 } | Events accepted successfully |
400 | { "error": "..." } | Invalid request body |
401 | { "error": "..." } | Missing, invalid, or expired API key |
429 | Rate limit exceeded |
Code Examples
cURL
Node.js
Python
Tracking Revenue
Revenue values follow the same format as client-side tracking: integers representing cents, not dollars.- ✅ Correct:
"revenue": 999(represents $9.99) - ❌ Incorrect:
"revenue": 9.99(will be treated as 9 cents)
| Dollar Amount | Revenue Value |
|---|---|
| $1.00 | 100 |
| $9.99 | 999 |
| $25.50 | 2550 |
| $100.00 | 10000 |
Batch Events
You can send up to 100 events in a single request. Events can belong to different sessions and users, making this ideal for processing webhooks or background jobs:Custom Properties
Attach custom metadata to your conversion events for additional context:properties field accepts an object or an array of objects.
Best Practices
- Store API keys securely — use environment variables, never commit keys to source control
- Send events promptly — if there is a delay between the conversion and the API call, use the
timefield to record the actual conversion time - Validate before sending — check that
conversion_idis notnullbefore passing variables to your backend - Batch when possible — group events into a single request to reduce HTTP overhead
- Handle errors gracefully — retry on
500responses, do not retry on400or401 - Revenue in cents — always convert dollar amounts to integer cents before sending
Troubleshooting
Conversions Not Appearing
- Verify
session_idis from an active session captured by the SDK - Check that the goal exists in your Tracking settings and
conversion_idis correct - Confirm the API key has not expired (keys expire after 1 year by default)
401 Unauthorized
- Confirm the
Authorization: Bearer <key>header is present and correctly formatted - The API key may be expired or deleted — create a new one in Settings > API Keys
- Make sure there are no extra spaces or newlines in the key value
400 Bad Request
- The
eventsarray must contain 1 to 100 items session_id,user_id, andconversion_idare all required for each eventrevenuemust be an integer, not a decimal (e.g.,999not9.99)