Tracking data using the REST API
This guide walks you through tracking data in Prepr using the REST API instead of the tracking code.
Introduction
You can track and capture data to understand how customers engage with your content. This is an essential step when setting up personalization, A/B testing and recommendations. Even before implementing personalization, it also helps your digital teams gather useful insights for segmentation.
Setting up the tracking code is a simple way to track data in Prepr. If you're unable to embed the Prepr tracking code, for example, due to restrictions, you can record events in Prepr by using the REST API instead.
If you haven't already done so, check out the fundamentals data collection guide to understand key concepts. Once you have a good understanding, let's dive into recording events using the REST API.
Recording events using the REST API
With the REST API you can send event data to Prepr. This can be convenient for offline conversions or if you're working in a restricted environment and aren't allowed to load third-party Javascript snippets.
JSON Structure
The table below shows the fields that are supported in the REST API.
argument | type | required | description |
---|---|---|---|
label | String | Yes | Defines the event type. |
timestamp | UTC Timest. | Event timestamp (default time of request). | |
Content Item Data | |||
content_item | Array | Yes | |
content_item.id | String | Yes | Content item ID the event is recorded for. |
content_item.locale | String | Locale like en-GB . | |
Customer Data | |||
customer | Array | Yes | |
customer.id | String | ID of Prepr User | |
Metadata | |||
utm_medium | String | Campaign Medium | |
utm_source | String | Campaign Source | |
utm_campaign | String | Campaign Name | |
utm_term | String | Campaign Term | |
utm_content | String | Campaign Content | |
rl | String | Referrer location, example: https://prepr.io/ | |
sr | String | Screen resolution, example: 1680x1050 |
You need to supply a customer ID for the event to be recorded.
If the customer ID is not found in your customers list when the event gets processed, a new customer will be created.
Recording events
If you collected all the data, the JSON data object should be posted to the following endpoint:
POST https://tracking.prepr.io/events
{
"label" : "View",
"timestamp" : 1609588800, // Optional
"content_item" : {
"id" : "76a5e261-ec2a-4bd2-8195-cf7e889b0a68"
},
"customer" : {
"id" : "x-21381723243-PRP"
}
}
This endpoint requires an HTTP Authorization header with an Access Token containing the capture_publish
scope.
If the event was successfully queued the endpoint will return a status code 202 Accepted
.
The endpoint won't validate the input. Processing of the events are queued.
To validate your input, within a few seconds, you'll see the data reflected in the Prepr Segments page.
Was this article helpful?
We’d love to learn from your feedback