Track In-Game Event
The endpoint to track In-Game based events. To use this feature, make a POST
request to this endpoint.
/v1/projects/{projectId}/track
Parameters
projectId
(string, required): The ID of your project.
Response
HTTP satus 200
{
"message": "Event 'EDIT_ARTICLE' from user 'd342dad2-9d59-11e9-a384-42010aa8003f' successfully received"
}
Request body properties example
The request body should include the following parameters:
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.
{
"user_id": "7896-6548-87as-6549",
"name": "Some name",
"properties": {},
"created_at": 1683197285
}
Example
Here's an example request that tracks an LEVEL_UP event:
To use this script, attach it to a game object in your scene and fill in the appropriate values for projectId, userId, eventName, properties, and createdAt. When the game object is instantiated, the Start method will automatically send a POST request to the Quests System API endpoint to track the event.
- C#
- Node.js
- CURL
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
public class EventTracker : MonoBehaviour
{
// Your Quests System project ID
public string projectId;
// The base URL for the Quests System API
public string apiUrl = "https://api.quests-system.com/v1/projects/";
// The unique ID of the user who performed the event
public string userId;
// The name of the event that was performed
public string eventName;
// An optional set of key-value pairs that provide additional information about the event
public Dictionary<string, string> properties = new Dictionary<string, string>();
// The UNIX timestamp (in seconds) when the event was performed
public int createdAt;
async void Start()
{
// Construct the API endpoint URL
string endpointUrl = apiUrl + projectId + "/track";
// Construct the request body as a JSON object
var requestObject = new
{
user_id = userId,
name = eventName,
properties = properties,
created_at = createdAt
};
// Convert the request body to a JSON string
string requestBody = JsonUtility.ToJson(requestObject);
// Create an HTTP client and send the POST request
using (var client = new HttpClient())
{
var content = new StringContent(requestBody, System.Text.Encoding.UTF8, "application/json");
var response = await client.PostAsync(endpointUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
Debug.Log("Event tracked: " + responseString);
}
}
}
const https = require("https");
class EventTracker {
// Your Quests System project ID
projectId;
// The base URL for the Quests System API
apiUrl = "https://api.quests-system.com/v1/projects/";
// The unique ID of the user who performed the event
userId;
// The name of the event that was performed
eventName;
// An optional set of key-value pairs that provide additional information about the event
properties = {};
// The UNIX timestamp (in seconds) when the event was performed
createdAt;
async start() {
// Construct the API endpoint URL
const endpointUrl = this.apiUrl + this.projectId + "/track";
// Construct the request body as a JSON object
const requestBody = JSON.stringify({
user_id: this.userId,
name: this.eventName,
properties: this.properties,
created_at: this.createdAt,
});
// Create the request options
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": requestBody.length,
},
};
// Create an HTTPS request and send it
const req = https.request(endpointUrl, options, (res) => {
let responseString = "";
res.on("data", (chunk) => {
responseString += chunk;
});
res.on("end", () => {
console.log("Event tracked:", responseString);
});
});
req.on("error", (error) => {
console.error("Error tracking event:", error);
});
// Send the request body
req.write(requestBody);
req.end();
}
}
// Create an instance of EventTracker and set the required properties
const tracker = new EventTracker();
tracker.projectId = "YourQuestsSystemProjectID";
tracker.apiUrl = "https://api.quests-system.com/v1/projects/";
tracker.userId = "UserID";
tracker.eventName = "EventName";
tracker.properties = { key1: "value1", key2: "value2" };
tracker.createdAt = Math.floor(Date.now() / 1000);
// Call the start method to track the event
tracker.start();
curl -X POST -H "Content-Type: application/json" -d '{
"user_id": "7896-6548-87as-6549",
"name": "Some name",
"properties": {},
"created_at": 1683197285
}' "https://api.quests-system.com/v1/projects/{projectId}/track"