Bulk Tracking In-Game Events
This endpoint allows to send multiple events at once, which can be useful for batch processing events from your game. To use this feature, make a POST
request to this endpoint.
POST /v1/projects/{projectId}/track/batch
Parameters
projectId
(string, required): The ID of your project.
Request body properties
The properties field of an event object is a dictionary that can contain any key-value pairs you want to track for the event. Here are some examples of properties you might want to include for the LEVEL_UP
event:
The request body should include the following array of objects with properties:
user_id
(string): The unique identifier of the user who performed the event.name
(string): The name of the event that was performed. This should be a string that identifies the event. We recommend using a consistent naming convention to make it easy to manage and track events.properties
(object): An optional set of key-value pairs that provide additional information about the event.created_at
(integer): The UNIX timestamp (in seconds) when the event was performed.
Note that the properties field is optional and can be omitted if you don't need to track any additional information for the event.
[
{
"user_id": "7896-6548-87as-6549",
"name": "Some name",
"properties": {},
"created_at": 1683197285
}
]
Response
{
"message": "Events successfully received"
}
Example
- C#
- Node.js
- cURL
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
public class EventManager : MonoBehaviour
{
private string projectID = "YOUR_PROJECT_ID";
private string apiEndpoint = "https://api.quests-system.com/v1/projects/" + projectID + "/track/batch";
private void Start()
{
// Create a list of events to track
List<object> events = new List<object>();
// Add the first event
Dictionary<string, object> eventData1 = new Dictionary<string, object>();
eventData1.Add("user_id", "ffff-ffff-ffff-ffff");
eventData1.Add("name", "LEVEL_UP");
eventData1.Add("properties", new Dictionary<string, object>
{
{"level", 10},
{"area", "forest"},
{"time_played", 3600},
});
eventData1.Add("created_at", (int)(System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1))).TotalSeconds);
events.Add(eventData1);
// Add the second event
Dictionary<string, object> eventData2 = new Dictionary<string, object>();
eventData2.Add("user_id", "gggg-gggg-gggg-gggg");
eventData2.Add("name", "LEVEL_UP");
eventData2.Add("properties", new Dictionary<string, object>
{
{"level", 5},
{"area", "desert"},
{"time_played", 1800},
});
eventData2.Add("created_at", (int)(System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1))).TotalSeconds);
events.Add(eventData2);
// Send the events to the Quests System API
StartCoroutine(SendEventsToAPI(JsonConvert.SerializeObject(events)));
}
IEnumerator SendEventsToAPI(string data)
{
var request = new UnityEngine.Networking.UnityWebRequest(apiEndpoint, "POST");
byte[] bodyRaw = new System.Text.UTF8Encoding(true).GetBytes(data);
request.uploadHandler = (UnityEngine.Networking.UploadHandler)new UnityEngine.Networking.UploadHandlerRaw(bodyRaw);
request.downloadHandler = (UnityEngine.Networking.DownloadHandler)new UnityEngine.Networking.DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
if (request.result == UnityEngine.Networking.UnityWebRequest.Result.ConnectionError ||
request.result == UnityEngine.Networking.UnityWebRequest.Result.ProtocolError)
{
Debug.LogError("API Error: " + request.error);
}
else
{
Debug.Log("Events tracked successfully");
}
}
}
const axios = require("axios");
const projectID = "YOUR_PROJECT_ID";
const apiEndpoint = `https://api.quests-system.com/v1/projects/${projectID}/track/batch`;
function sendEventsToAPI(data) {
return axios
.post(apiEndpoint, data, {
headers: {
"Content-Type": "application/json",
},
})
.then((response) => {
console.log("Events tracked successfully");
})
.catch((error) => {
console.error("API Error:", error.message);
});
}
// Create a list of events to track
const events = [];
// Add the first event
const eventData1 = {
user_id: "ffff-ffff-ffff-ffff",
name: "LEVEL_UP",
properties: {
level: 10,
area: "forest",
time_played: 3600,
},
created_at: Math.floor(Date.now() / 1000),
};
events.push(eventData1);
// Add the second event
const eventData2 = {
user_id: "gggg-gggg-gggg-gggg",
name: "LEVEL_UP",
properties: {
level: 5,
area: "desert",
time_played: 1800,
},
created_at: Math.floor(Date.now() / 1000),
};
events.push(eventData2);
// Send the events to the Quests System API
sendEventsToAPI(JSON.stringify(events))
.then(() => {
console.log("Events sent successfully");
})
.catch((error) => {
console.error("Failed to send events:", error.message);
});
curl -X POST -H "Content-Type: application/json" -d '[
{
"user_id": "ffff-ffff-ffff-ffff",
"name": "LEVEL_UP",
"properties": {
"level": 10,
"area": "forest",
"time_played": 3600
},
"created_at": TIMESTAMP1
},
{
"user_id": "gggg-gggg-gggg-gggg",
"name": "LEVEL_UP",
"properties": {
"level": 5,
"area": "desert",
"time_played": 1800
},
"created_at": TIMESTAMP2
}
]' "https://api.quests-system.com/v1/projects/YOUR_PROJECT_ID/track/batch"