Purchase
Log a purchase event
To capture the diversity of use cases our customer base, we allow several different types of purchase events to be communicated.
Event | Meaning |
---|---|
purchase | user completed a purchase online on your website |
offline purchase | user completed a purchase in a physical store |
Query String Parameters
Requests to log any of the events need to have the following query string parameters.
Parameter | Type | Required? | Description |
---|---|---|---|
key | string | Yes | The key of the index you'd like to log events for. |
c | string | Yes | Client id. The library responsible for making the request |
i | string | Yes | User's device id. An anonymized user identification hash. |
s | integer | Yes | Session number. The counter for the session in which the behavior event occurred. We recommend to increment the session number every 30 minutes |
ui | string | No | Your internal ID for a user (if available) |
_dt | integer | No | Unix timestamp in seconds of when the event happened |
us | array of strings | No | User segment |
section | string | No | Your autosuggest and search results can have multiple sections like "Products" and "Search Suggestions". This indicates which section was searched. See your dashboard for the section names to use. |
origin_referrer | string | No | The url where the event originated. |
Purchase
To log an event make a POST
request to:
POST https://ac.cnstrc.com/v2/behavioral_action/purchase
Requests have to also include query string parameters and body of the request has to have JSON object with the necessary fields documented below. JSON parameters override query string parameters if both are passed.
- Shell
- JavaScript
- Python
- Java
- iOS
- Android
- C#
curl -X POST -H 'Content-Type: application/json' \
-u '[your token]:' \
"https://ac.cnstrc.com/v2/behavioral_action/purchase? \
section=<section used> \
&key=<your API key> \
&c=<client id> \
&i=<user id> \
&s=<session number>" \
-d '{
"items": [
{
"item_id": "shorts_1"
}
],
"order_id": "1",
"revenue": 100.0
}'
// This method is not currently supported.
# This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
info
The above command returns a 204 Success response on success.
Parameter | Type | Required? | Description |
---|---|---|---|
revenue | integer or float | No | Total revenue that would be made from the purchase |
order_id | string | No | Order ID (if exists) |
items | array of items | Yes | Array of items. Item schema is explained below in the Item schema (online) section. |
Item schema (online)
Parameter | Type | Required | Description |
---|---|---|---|
item_id | string | No | Id of purchased item. Either item_id or item_name is required to be passed. |
item_name | string | No | Name of purchased item. Either item_id or item_name is required to be passed. |
variation_id | string | No | Id of purchased variation, if applicable. Either item_id or item_name of related item must be passed along with variation_id . |
Offline purchase
This event be used to collect data about purchases in physical stores to improve personalization and KPIs.
To log an event make a POST
request to:
POST https://ac.cnstrc.com/v1/offline_behavioral_actions
Multiple purchase events can be passed in single request (up to 100). Requests have to also include query string parameters and body of the request has to have JSON object with the necessary fields documented below.
- Shell
- JavaScript
- Python
- Java
- iOS
- Android
- C#
curl -X POST -H 'Content-Type: application/json' \
-u '[your token]:' \
"http://ac.cnstrc.com/v1/offline_behavioral_actions"
-d '{
"behavioral_actions": [
{
"action": "purchase",
"data": {
"items": [
{
"item_id": <id of purchased item>,
"price": <price of purchased item>
},
{
"item_name": <name of purchased item>,
"price": <price of purchased item>,
"count": <number of purchased item>,
},
{
"item_id": <id of related item>,
"variation_id": <id of purchased variation>
},
],
"revenue": <revenue of purchase as number>,
"order_id": <unique order id>
"c": <client id>,
"i": <user id>,
"s": <session number>
}
},
{
"action": "purchase",
"data": {
"items": [
{
"item_id": <id of purchased item>,
"price": <price of purchased item>
},
],
"revenue": <revenue of purchase as number>,
"order_id": <unique order id>
"c": <client id>,
"i": <user id>,
"s": <session number>
}
}
]
}'
// This method is not currently supported.
# This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
info
The above command returns a 204 Success response on success.
An array of actions is passed under the behavioral_actions
key.
Each item of the array is an object containing action
and data
keys.
For purchase event action
must be "purchase" and the schema for data
is as below.
Parameter | Type | Required | Description |
---|---|---|---|
ui | string | Yes | Your internal ID for a user (if available) |
_dt | integer | Yes | Unix timestamp in seconds of when the event happened |
revenue | integer | No | Revenue of order. Can be passed explicitly or will be evaluated by summation of passed item prices and its counts. |
lat | string | No | Latitude of store. |
lon | string | No | Longitude of store. |
store_id | string | No | Store id. |
order_id | string | No | Order id. Can be used to merge different events into single one. |
items | array of items | Yes | Array of items. Schema for item is explained below in Item schema (offline) section. |
Item schema (offline)
Parameter | Type | Required | Description |
---|---|---|---|
item_id | string | No | Id of purchased item. Either item_id or item_name is required to be passed. |
item_name | string | No | Name of purchased item. Either item_id or item_name is required to be passed. |
variation_id | string | No | Id of purchased variation, if applicable. Either item_id or item_name of related item must be passed along with variation_id . |
price | string | No | Price of purchased item or variation. Will be used to calculate purchase revenue if order revenue is not passed. Passed as string, from which numeric value will be extracted. |
count | integer | No | Count of item purchased. Price will be multiplied by count to get purchase revenue if order revenue is not passed. |