Purchase Data
1 min
Reporting Single Order Data
Use this API endpoint to submit the purchase data per product.
The request should be made once for each line item purchased.
GET
https://{{ Analytics_URL }}/analytics/productTracking
Query Parameters
- klevu_apiKeystringrequiredDescription
- klevu_typestringrequiredDescription
- klevu_productIdstringrequiredDescription
- klevu_productGroupIdstringrequiredDescription
- klevu_productVariantIdstringrequiredDescription
- klevu_unitIntegerrequiredDescription
- klevu_salePriceNumberrequiredDescription
- klevu_currencystringrequiredDescription
- klevu_shopperIPstringrequiredDescription
- klevu_shopperIP_v4stringDescription
- klevu_shopperIP_v6stringDescription
- data_protectionBooleanDescription
- klevu_uuidstringDescription
- klevu_countrystringDescription
- klevu_citystringDescription
curl
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
nodejs
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP',
'headers': {
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
javascript
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP");
xhr.send();python
import requests
url = "https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
ruby
require "uri"
require "net/http"
url = URI("https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
response = https.request(request)
puts response.read_body
200
<data>
<response>SUCCESS</response>
</data>
Reporting Multiple Order Data (JSON)
The end-point is used for reporting multiple orders in batch.
POST
https://{{ Analytics_URL }}/analytics/collect
Body Parameters
- event_versionStringrequiredDescription
- eventstringrequiredDescription
- event_apikeystringrequiredDescription
- event_timestamp_msNumberDescription
- user_profileObjectrequiredDescription
- ip_addressstringrequiredDescription
- emailstringDescription
- ip_address_v4stringDescription
- ip_address_v6stringDescription
- data_protectionbooleanDescription
- klevu_uuidstringDescription
- klevu_countrystringDescription
- klevu_citystringDescription
- itemsArrayrequiredDescription
- order_idstringDescription
- order_line_idstringDescription
- item_namestringrequiredDescription
- item_idstringrequiredDescription
- item_group_idstringrequiredDescription
- item_variant_idstringrequiredDescription
- unit_priceNumberrequiredDescription
- currencystringrequiredDescription
- unitsIntegerDescription
php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://stats.ksearchnet.com/analytics/collect',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'[
{
"event": "order_purchase",
"event_apikey": "klevu-12345",
"user_profile" : {
"ip_address":"111.11.11.1",
"email":"[email protected]"
},
"event_version": "1.0.0",
"event_data": {
"items": [
{
"order_id": "1223434",
"order_line_id": "ABC-12343",
"item_name": "45RU,800x1070,N-Type,D,NoS,CM,WH,EA",
"item_id": "75882",
"item_group_id": "75882",
"item_variant_id": "75882",
"unit_price": 6033.42,
"currency": "USD",
"units": 2
},
{
"order_id": "1223435",
"order_line_id": "ABC-12344",
"item_name": "NoS,CM,WH,EA",
"item_id": "75883",
"item_group_id": "75883",
"item_variant_id": "75883",
"unit_price": 6033.42,
"currency": "US",
"units": 1
}
]
}
}
]',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;javascript
// WARNING: For POST requests, body is set to null by browsers.
var data = JSON.stringify([
{
"event": "order_purchase",
"event_apikey": "klevu-12345",
"user_profile" : {
"ip_address":"111.11.11.1",
"email":"[email protected]"
},
"event_version": "1.0.0",
"event_data": {
"items": [
{
"order_id": "1223434",
"order_line_id": "ABC-12343",
"item_name": "45RU,800x1070,N-Type,D,NoS,CM,WH,EA",
"item_id": "75882",
"item_group_id": "75882",
"item_variant_id": "75882",
"unit_price": 6033.42,
"currency": "CAD",
"units": 2
}
]
}
}
]);
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://stats.ksearchnet.com/analytics/collect");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "[\n {\n \"event\": \"order_purchase\",\n \"event_apikey\": \"klevu-12345\",\n \"event_version\": \"1.0.0\",\n \"event_data\": {\n \"items\": [\n {\n \"order_id\": \"1223434\",\n \"order_line_id\": \"ABC-12343\",\n \"item_name\": \"45RU,800x1070,N-Type,D,NoS,CM,WH,EA\",\n \"item_id\": \"75882\",\n \"item_group_id\": \"75882\",\n \"item_variant_id\": \"75882\",\n \"unit_price\": 6033.42,\n \"currency\": \"CAD\",\n \"units\": 2\n }\n ]\n }\n }\n]");
Request request = new Request.Builder()
.url("https://stats.ksearchnet.com/analytics/collect")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();nodejs
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://stats.ksearchnet.com/analytics/collect',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify([
{
"event": "order_purchase",
"event_apikey": "klevu-1234",
"user_profile" : {
"ip_address":"111.11.11.1",
"email":"[email protected]"
},
"event_version": "1.0.0",
"event_data": {
"items": [
{
"order_id": "1223434",
"order_line_id": "ABC-12343",
"item_name": "45RU,800x1070,N-Type,D,NoS,CM,WH,EA",
"item_id": "75882",
"item_group_id": "75882",
"item_variant_id": "75882",
"unit_price": 6033.42,
"currency": "CAD",
"units": 2
}
]
}
}
])
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
200