Skip to main content
Some actions only happen on your backend: payment confirmations, form submissions processed server-side, CRM updates, webhook callbacks. Send them to pagent as events with the REST API. They are linked to the visitor’s browser session, so they count in the tests that visitor saw. Like events from the browser, server events are sent by label. No goal has to exist first. Once events arrive, build an event goal on them.

How it works

  1. Create an API key in pagent under Settings → API Keys.
  2. Capture the session in the browser with window._pgnt.variables().
  3. Pass it to your backend with your existing request.
  4. Send the event from your backend to POST /v2/events.
Important: session_data.session_id links the event to the visitor’s session and tests. Without it, the event is recorded but cannot be attributed to a test.

Prerequisites


1. Create an API key

  1. Navigate to Settings → API Keys in pagent.
  2. Click Create API Key.
  3. Give it a descriptive name, for example “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. Keys expire after one year by default.

2. Capture the session in the browser

window._pgnt.variables() returns the identifiers of the current visitor:
Send the whole object to your backend with the request that triggers the action:
/v2/events accepts it as session_data as is. Fields it doesn’t need are ignored. See Variables for everything the method returns.

3. Send events

Single event

Bulk

Send up to 100 events in one request to POST https://ingest.pagent.ai/v2/events/bulk. Events can belong to different visitors, which suits webhooks and background jobs.

Responses

Rejection reasons are empty and invalid_charset (the label breaks the label rules) and label_limit_reached (the website already has 200 distinct event labels).

Code examples

cURL

Node.js

Python

Server events appear under Tracking → Sources → Events with the source Server.

Revenue

Revenue follows the same format as in the browser: integers in cents, not dollars. See Tracking revenue.
  • Correct: "revenue": 999 is $9.99
  • Incorrect: "revenue": 9.99 is rejected with 400

Best practices

  1. Store API keys securely. Use environment variables and never commit keys to source control.
  2. Send the real time. If the event is sent later than it happened, set time to when it actually happened.
  3. Check the session. Make sure session_id is not empty before you rely on the event for a test.
  4. Batch when possible. Group events into one bulk request to reduce overhead.
  5. Retry carefully. Retry 500 responses. Do not retry 400, 401 or 422.
  6. Send cents. Convert amounts to integer cents before sending.

Troubleshooting

Events not appearing

  • Check the response: a 422 lists the rejected labels and why.
  • Check the label follows the label rules.
  • Confirm the API key has not expired.

Events appear but don’t count in a test

  • Make sure session_data.session_id comes from _pgnt.variables() in the visitor’s browser.
  • Make sure an event goal on the label is added to the test.

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 under Settings → API Keys.
  • Make sure there are no extra spaces or newlines in the key value.

Need help?

Reach out at support@pagent.ai.

Deprecated: Conversions API

/v1/conversions, /v2/conversions and /v2/conversions/bulk are deprecated. They keep working, but they only count for Programmatic goals and need the goal’s conversion_id from _pgnt.variables("goal_label"). For new integrations use /v2/events and an event goal.To migrate, send the same label and revenue to /v2/events instead, and follow Migrating from programmatic goals. The request bodies are almost identical: /v2/events takes the same session_data, label, revenue, properties and time fields and doesn’t need conversion_id.
The reference below is kept for existing integrations. Both use the same API key as /v2/events.

Capturing the goal ID

The Conversions API needs the UUID of a Programmatic goal. Pass the goal label to variables():
conversion_id is null when the label matches no Programmatic goal published to your site.

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.

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):