Skip to main content

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.

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);
}
}
}