How it works
- Create an API key in pagent under Settings → API Keys.
- Capture the session in the browser with
window._pgnt.variables(). - Pass it to your backend with your existing request.
- 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
- The pagent SDK installed on your website.
1. Create an API key
- Navigate to Settings → API Keys in pagent.
- Click Create API Key.
- Give it a descriptive name, for example “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. Keys expire after one year by default.
2. Capture the session in the browser
window._pgnt.variables() returns the identifiers of the current visitor:
/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 toPOST 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
Revenue
Revenue follows the same format as in the browser: integers in cents, not dollars. See Tracking revenue.- Correct:
"revenue": 999is $9.99 - Incorrect:
"revenue": 9.99is rejected with400
Best practices
- Store API keys securely. Use environment variables and never commit keys to source control.
- Send the real time. If the event is sent later than it happened, set
timeto when it actually happened. - Check the session. Make sure
session_idis not empty before you rely on the event for a test. - Batch when possible. Group events into one bulk request to reduce overhead.
- Retry carefully. Retry
500responses. Do not retry400,401or422. - Send cents. Convert amounts to integer cents before sending.
Troubleshooting
Events not appearing
- Check the response: a
422lists 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_idcomes 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
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 tovariables():
conversion_id is null when the label matches no Programmatic goal published to your site.
v1 API
Endpoint
Request Body
The request body contains anevents 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. Theproperties 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 theproperties field (accepts an object or an array of objects):