Skip to main content
Server-side conversion tracking lets you record conversions that happen on your backend — payment confirmations, form submissions, CRM updates, or webhook-triggered events. These events are automatically attributed to the visitor’s browser session and any active experiments, with no extra analytics configuration needed.

How It Works

  1. Create an API key in your pagent dashboard under Settings > API Keys
  2. Capture session variables on the frontend using window._pgnt.variables("goal_label")
  3. Pass the variables to your backend (e.g., in a form submission or AJAX request)
  4. Send a conversion event from your backend via the REST API — use POST /v1/conversions or POST /v2/conversions
Both v1 and v2 are fully supported. v2 accepts the output of _pgnt.variables() directly as a session_data object, which is useful when your integration cannot destructure the variables before sending.
Important: The session_id links each server-side event to the visitor’s browser session and active experiments. Without a valid session_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

  1. Navigate to Settings > API Keys in your pagent dashboard
  2. Click “Create API Key”
  3. Give it a descriptive name (e.g., “Production Backend”)
  4. 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

Use window._pgnt.variables() to get the session identifiers and goal UUID you need for the API call. Pass the goal label as a string argument:
Note: If conversion_id is null, the label does not match any configured goal. Double-check the goal label in your Tracking settings.
See Variables for the complete list of fields the method returns, including experiment identifiers.

Passing Variables to Your Backend

Send the captured variables alongside your existing request data:

3. v1 API

Endpoint

Request Body

The request body contains an events array with 1 to 100 conversion events:

Response

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. The properties 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

Request Body

Response

Bulk Endpoint

Send up to 100 events in a single request. Each event uses the same session_data structure as the single-event endpoint:

Code Examples

cURL

Node.js

Python

Custom Properties

Attach custom metadata using the properties 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)

Best Practices

  1. Store API keys securely — use environment variables, never commit keys to source control
  2. Send events promptly — if there is a delay between the conversion and the API call, use the time field to record the actual conversion time
  3. Validate before sending — check that conversion_id is not null before passing variables to your backend
  4. Batch when possible — group events into a single request to reduce HTTP overhead
  5. Handle errors gracefully — retry on 500 responses, do not retry on 400 or 401
  6. Revenue in cents — always convert dollar amounts to integer cents before sending

Troubleshooting

Conversions Not Appearing

  • Verify session_id is from an active session captured by the SDK
  • Check that the goal exists in your Tracking settings and conversion_id is 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_data must be an object containing session_id, user_id, and conversion_id
  • v2 bulk / v1: The events array must contain 1 to 100 items
  • v1: session_id, user_id, and conversion_id are all required as top-level fields on each event
  • revenue must be an integer, not a decimal (e.g., 999 not 9.99)

Need Help?

Reach out at support@pagent.ai.