Skip to main content

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.

EventMeaning
purchaseuser completed a purchase online on your website
offline purchaseuser 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.

ParameterTypeRequired?Description
keystringYesThe key of the index you'd like to log events for.
cstringYesClient id. The library responsible for making the request
istringYesUser's device id. An anonymized user identification hash.
sintegerYesSession number. The counter for the session in which the behavior event occurred. We recommend to increment the session number every 30 minutes
uistringNoYour internal ID for a user (if available)
_dtintegerNoUnix timestamp in seconds of when the event happened
usarray of stringsNoUser segment
sectionstringNoYour 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_referrerstringNoThe 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.

Log an event
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
}'
info

The above command returns a 204 Success response on success.

ParameterTypeRequired?Description
revenueinteger or floatNoTotal revenue that would be made from the purchase
order_idstringNoOrder ID (if exists)
itemsarray of itemsYesArray of items. Item schema is explained below in the Item schema (online) section.

Item schema (online)

ParameterTypeRequiredDescription
item_idstringNoId of purchased item. Either item_id or item_name is required to be passed.
item_namestringNoName of purchased item. Either item_id or item_name is required to be passed.
variation_idstringNoId 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.

Log an event
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>
}
}
]
}'
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.

ParameterTypeRequiredDescription
uistringYesYour internal ID for a user (if available)
_dtintegerYesUnix timestamp in seconds of when the event happened
revenueintegerNoRevenue of order. Can be passed explicitly or will be evaluated by summation of passed item prices and its counts.
latstringNoLatitude of store.
lonstringNoLongitude of store.
store_idstringNoStore id.
order_idstringNoOrder id. Can be used to merge different events into single one.
itemsarray of itemsYesArray of items. Schema for item is explained below in Item schema (offline) section.

Item schema (offline)

ParameterTypeRequiredDescription
item_idstringNoId of purchased item. Either item_id or item_name is required to be passed.
item_namestringNoName of purchased item. Either item_id or item_name is required to be passed.
variation_idstringNoId of purchased variation, if applicable. Either item_id or item_name of related item must be passed along with variation_id.
pricestringNoPrice 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.
countintegerNoCount of item purchased. Price will be multiplied by count to get purchase revenue if order revenue is not passed.