Contents
On this page
Record Events - Plugixa Chat
POST /plugixa-chat/v1/events
Record views, opens and clicks, as the widget does when a visitor leaves a page.
Public: no login. The request needs the page token for events (see Public routes) and is limited to 60 per visitor every five minutes.
Note. Events are not checked against your widgets: a widget id that does not exist is counted all the same. Invalid events are skipped without an error.
Request
POST https://your-site.example/wp-json/plugixa-chat/v1/events
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
events |
array |
Yes | The events. Only the first 200 are read. |
events[].w |
integer |
Yes | The widget’s id. |
events[].c |
string |
No | The channel slug. Empty for view and open. |
events[].t |
string |
Yes | view, open or click. Anything else skips the event. |
token |
string |
No | The page token, when it is not sent in the X-Plugixa-Chat-Token header. The widget sends it here because a beacon cannot set headers. |
Identical events in one request are added together. Anything else in an event is ignored.
{
"token": "YOUR_EVENTS_TOKEN",
"events": [
{
"w": 2,
"c": "",
"t": "view"
},
{
"w": 2,
"c": "",
"t": "open"
},
{
"w": 2,
"c": "whatsapp",
"t": "click"
}
]
}
Responses
204 No Content. The events were recorded. There is no body.
Errors
| Status | Code | When |
|---|---|---|
403 |
plugixa_chat_missing_token |
No page token was sent. |
403 |
plugixa_chat_stale_token |
The token has expired. Fetch a fresh one from Get Context. |
403 |
plugixa_chat_bad_origin |
The Origin or Referer header names another site. |
429 |
plugixa_chat_rate_limited |
This visitor has used its 60 requests for the current five minutes. |
Plus the errors every endpoint can return.
Examples
curl -s -X POST "https://your-site.example/wp-json/plugixa-chat/v1/events" \
-H "X-Plugixa-Chat-Token: $PLUGIXA_CHAT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"events":[{"w":2,"c":"","t":"view"},{"w":2,"c":"","t":"open"},{"w":2,"c":"whatsapp","t":"click"}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-chat/v1/events');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-Plugixa-Chat-Token: ' . getenv('PLUGIXA_CHAT_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'events' => [
[
'w' => 2,
'c' => '',
't' => 'view',
],
[
'w' => 2,
'c' => '',
't' => 'open',
],
[
'w' => 2,
'c' => 'whatsapp',
't' => 'click',
],
],
]),
]);
curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); // 204
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-chat/v1/events', {
method: 'POST',
headers: {
'X-Plugixa-Chat-Token': process.env.PLUGIXA_CHAT_TOKEN,
'Content-Type': 'application/json',
},
body: JSON.stringify({ events: [{ w: 2, c: '', t: 'view' }, { w: 2, c: '', t: 'open' }, { w: 2, c: 'whatsapp', t: 'click' }] }),
});
const ok = response.status === 204;
Quick Links
Share