Tracking analytics
How it works
Tracking analytics lets you collect and aggregate user-generated events to evaluate program performance and the number of referrals. The obtained data can be used as an additional way to engage affiliate networks, as strong stats make the offer more attractive.
The following events can be processed:
- Transition to the landing page
- Transition from the landing page to the store
How to get it
To integrate tracking analytics, do the following:
- Get a JSON Web Token (JWT).
- Save tracking_id from the request parameter to your website cookies. Example of a request with tracking_id:
https://playnewz.com?utm_source=n6LI9yVu&utm_campaign=5b9bff5f9d31b&tracking_id=19e2DLjNTk2YOdXA4d8J3NReNkXNafhC
. - After a new user is created, send user_id and tracking_id via the Registration Event Sending method.
- It’s recommended to send requests asynchronously, so it doesn’t interfere with user registration while awaiting the Xsolla Tracking API response.
- Otherwise, use timeout. Note that new users won’t be tracked if awaiting the Xsolla Tracking API response takes longer than specified.
- To create and manage custom events, implement the following Tracking API methods: create, initialize and send an event.
- Implement the tracking script on your website.
Get token
HTTP REQUEST
- http
POST https://tracking-api.xsolla.com/v1/tokens
Header | Description |
---|---|
ContentType | application/json |
Authorization | The Authorization: Basic <your_authorization_basic_key> header, where <your_authorization_basic_key> is the merchant ID:API key pair, encoded according to the Base64 standard. Go to Publisher Account to find these parameters:
|
For more information about working with API keys, see the API reference.
Key recommendations:
- Save the generated API key on your side. You can view the API key in Publisher Account only once when it is created.
- Keep your API key a secret. It provides access to your personal account and your projects in Publisher Account.
- The API key must be stored on your server and never in binaries or on the frontend.
If an API call you need does not contain the project_id
path parameter, use the API key that is valid in all the company’s projects to set up authorization.
Parameter | Description |
---|---|
sourceType | Data source type. It can take the following values:
|
sourceName | Data source name. |
projectId | Project ID. |
http
- http
- php
POST https://tracking-api.xsolla.com/v1/tokens
Headers:
Content-Type: application/json
Authorization: Basic 12kj3hlk1j2hlkjhlk1j2h3lkj
Body:
{
"sourceType": "client",
"sourceName": "landing",
"projectId": 1
}
HTTP/1.1 201 Token created
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaW5rIjoiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2 g_dj1kUXc0dzlXZ1hjUSJ9.aVigY6UVY3jgoEKoBv31cZnROL3I6WKtcr5K-Z7B1du"
}
<?php
$curl = curl_init();
$merchantId = 1;
$projectId = 2;
$apiKey = '<apiKey>';
$payload = [
'sourceType' => 'server',
'sourceName' => 's1',
'projectId' => $projectId,
];
curl_setopt($curl, CURLOPT_USERPWD, $merchantId . ":" . $apiKey);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://tracking-api.xsolla.com/v1/tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
"Content-type: application/json"
],
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Response code | Description |
---|---|
201 | Token created |
400 | Query parameters are not valid |
401 | Project key is not valid |
Registration event sending
You need to first obtain a token to do this.
HTTP REQUEST
- http
POST https://tracking-api.xsolla.com/v1/events
While sending the method, the following steps are completed:
- The end user follows the tracking link they found on the traffic source (influencer’s stream, promo page, etc.). The action is given its Click ID.
- Tracking ID is formed on the Proxy page side and passed to the landing page in the parameter.
- The user visits the landing page and signs up.
- The game developer passes user User ID and Tracking ID in the parameter by sending the registration event via Tracking API.
Header | Description |
---|---|
Authorization | Previously obtained token. |
Parameter | Type | Description |
---|---|---|
type | String | Previously obtained token. |
traits | Object | User identification data:
|
context | Object | Must be empty. |
properties | Object | Must be empty. |
http
- http
- php
POST https://tracking-api.xsolla.com/v1/events
Headers:
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaW5rIjoiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_d j1kUXc0dzlXZ1hjUSJ9.aVigY6UVY3jgoEKoBv31cZnROL3I6WKtcr5K-Z7B1yU
Body:
{
"type": "registration",
"traits": {
"trackingId": "19e2DLjNTk2YOdXA4d8J3NReNkXNafhC",
"userId": "20181126"
},
"properties": {
},
"context": {
}
}'
<?php
$curl = curl_init();
$token = '<token>';
$payload = [
'type' => 'registration',
'traits' => [
'trackingId' => "19e2DLjNTk2YOdXA4d8J3NReNkXNafhC",
'userId' => "20181126",
],
'properties' => [],
'context' => [],
];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://tracking-api.xsolla.com/v1/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload,JSON_FORCE_OBJECT),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer {$token}",
"Content-type: application/json"
],
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}
Create event
You need to first obtain a token to do this.
HTTP REQUEST
- http
POST https://tracking-api.xsolla.com/v1/events
Header | Description |
---|---|
Authorization | Previously obtained token. |
Parameter | Type | Description |
---|---|---|
type | String | Event type. |
traits | Object | User identification data: phone, email, in-game ID, etc. |
context | Object | Contextual data. |
properties | Object | Event properties. |
createdAt | Date | Format: datetime per RFC 3339 or ISO 8601. |
- http
POST https://tracking-api.xsolla.com/v1/events
Headers:
Content-Type: application/json
Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaW5rIjoiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_d j1kUXc0dzlXZ1hjUSJ9.aVigY6UVY3jgoEKoBv31cZnROL3I6WKtcr5K-Z7B1yU
Body:
{
"type": "landing_visit",
"traits":{
},
"properties":{
},
"context": {
"user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", "user_locale":"ru"
}
}
EXAMPLE EVENT: TRANSITION TO PAY STATION
- http
POST https://tracking-api.xsolla.com/v1/events
Headers:
Content-Type: application/json
Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaW5rIjoiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_d j1kUXc0dzlXZ1hjUSJ9.aVigY6UVY3jgoEKoBv31cZnROL3I6WKtcr5K-Z7B1yU
Body:
{
"type": "buy_btn",
"traits":{
},
"properties":{
"pkg_type":"bronze"
},
"context": {
"user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", "user_locale":"ru"
}
}
Response code | Description |
---|---|
204 | Event added |
400 | Event is not valid |
401 | Token is not valid |
Initialize event
You need to first obtain a token to do this.
- html
xnt("init", YOUR_TOKEN);
Send event
- html
xnt("sendEvent", EVENT_TYPE, EVENT_PROPERTIES);
Parameter | Description |
---|---|
EVENT_TYPE | Event name (string). E.g., landing_visit . |
EVENT_PROPERTIES | Event properties (JS object). |
- html
xnt("sendEvent", "landing_visit");
xnt("sendEvent", "buy_btn", { pkg_type: $(this).data('id') });
EVENT PARAMETERS
Parameter | Description |
---|---|
source | Event source (paystation, landing_page, etc.). |
type | Event type (user_visit, hit, etc.). |
traits | User data (email, user_id, nickname, etc.). |
context | Event context (ip, gaClientId, etc.). |
properties | Event properties (sum, levelup, etc.). |
createdAt | Event time, as passed by the source. |
timestamp | Time of event receipt by the system. |
context
and traits
parameters, use the following methods:- html
xnt("putContext", CONTEXT_OBJECT);
xnt("putTraits", TRAITS_OBJECT);
Parameter | Description |
---|---|
CONTEXT_OBJECT | Event context (JS object). |
TRAITS_OBJECT | User data (JS object). |
userAgent
and userLocale
will be added automatically. The data added by these two methods will be combined with the event data.Implement script
Implement the following script on the landing page:
- html
<script>
(function(i,s,o,g,r,a,m){i['XsollaNetworkTrackingObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(ar guments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.inse rtBefore(a,m)})(window,document,'script','https://cdn.xsolla.net/network/xtracking-0.1.js','xnt');
xnt("init", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaW5rIjoiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_ dj1kUXc0dzlXZ1hjUSJ9.aVigY6UVY3jgoEKoBv31cZnROL3I6WKtcr5K-Z7B1du");
xnt("sendEvent", "buy_btn", { pkg_type : "gold" });
</script>
Found a typo or other text error? Select the text and press Ctrl+Enter.