Log Event Endpoint
The log event endpoint saves a log of a user action on the site.
Endpoint Details
Path: /split-test/log-event
Method: POST
Payload:
- type: [string] - The slug for the event type that occurred.
- value: [number] - The value to assign the user action. When logging a simple event rate, this value is typically
1, but for an event like a purchase, you may want to put the purchase total or number of products purchased. - data: [object] - A plain object with details about the user. This will be appended to the user session.
Return Values
| Status | Data Type | Reason |
|---|---|---|
| 204 | (Empty) | There was no error but no event was logged due to filters or ome other reason |
| 201 | {
event_id: string;
session_id: string;
} | The event was successfully logged |
| 400 | {
statusCode: number;
error: string;
reason?: string;
} | There was a problem with the payload you sent to the endpoint |
| 500 | {
statusCode: number;
error: string;
reason?: string;
} | There was a problem on the server or an unknown error occured |
Example Request
js
// We will use fetch for the example
// Make the request to the participate endpoint
const response = await fetch('https://mysplittytest.com/split-test/participate', {
method: 'POST',
headers: {
'Authorization': 'API-Key YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
section_id: 'cta_button',
data: {
day_part: 'weekday'
}
});
});
// Parse the response
if (response.ok) {
throw new Error('Unable to get test data!');
}
const { variation } = await response.json();
// Apply the variation data where needed...
const cta_button = document.getElementById('cta-button');
if (cta_button && variation.data.label) {
cta_button.textContent = variation.data.label;
}