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 the REST API — use
POST /v1/conversionsorPOST /v2/conversions
_pgnt.variables() directly as a session_data object, which is useful when your integration cannot destructure the variables before sending.
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. v1 API
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
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. Theproperties field accepts an object or an array of objects.
4. v2 API
v2 is useful when your integration cannot destructure_pgnt.variables() before sending — the session identifiers are grouped in a session_data object that you can pass through directly.
Single Event Endpoint
| URL | https://ingest.pagent.ai/v2/conversions |
| Method | POST |
| Authorization | Bearer <API_KEY> |
| Content-Type | application/json |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
session_data | object | Yes | Session identifiers from _pgnt.variables() |
session_data.session_id | string | Yes | The current browser session identifier |
session_data.user_id | string | Yes | The visitor’s persistent user identifier |
session_data.visit_id | string | No | The current page view identifier |
session_data.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 } | Event accepted successfully |
400 | { "error": "..." } | Invalid request body |
401 | { "error": "..." } | Missing, invalid, or expired API key |
429 | Rate limit exceeded |
Bulk Endpoint
| URL | https://ingest.pagent.ai/v2/conversions/bulk |
| Method | POST |
| Authorization | Bearer <API_KEY> |
| Content-Type | application/json |
session_data structure as the single-event endpoint:
Code Examples
cURL
Node.js
Python
Custom Properties
Attach custom metadata using theproperties field (accepts an object or an array of objects):
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 |
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
- v2:
session_datamust be an object containingsession_id,user_id, andconversion_id - v2 bulk / v1: The
eventsarray must contain 1 to 100 items - v1:
session_id,user_id, andconversion_idare all required as top-level fields on each event revenuemust be an integer, not a decimal (e.g.,999not9.99)