Track gameplay events such as game starts, level completions, and purchases, and send them to a configured Hardal Signal endpoint. The SDK provides a persistent HardalManager component, asynchronous event tracking, and optional debug logging.
You need Unity 2020.3 or later and a Hardal Signal endpoint. Install the package, add HardalManager to a scene, and configure the endpoint before sending events.
Clone this repository and, in Unity Package Manager, select Add package from disk and choose its package.json.
If your configured Unity package registry hosts com.hardal.signal version 1.0.0, you can also add this entry to Packages/manifest.json:
{
"dependencies": {
"com.hardal.signal": "1.0.0"
}
}- In Unity Editor, go to
GameObject > Hardal > Create Hardal Manager - This will create a new GameObject with HardalManager component
- In the Inspector, set your endpoint URL
- Optionally enable debug logs
- Create an empty GameObject in your scene
- Add the HardalManager component to it
- Configure the endpoint URL in the Inspector
- The GameObject will persist between scenes
// The SDK automatically initializes on Start()
// But you can manually initialize it with a custom endpoint:
HardalManager.Instance.InitializeHardal("https://your-custom-endpoint.com");// Track a simple event
await HardalManager.Instance.TrackEvent("game_started");
// Track event with properties
Dictionary<string, object> properties = new Dictionary<string, object> {
{ "level", 5 }, { "score", 1000 }, { "character", "warrior" }
};
await HardalManager.Instance.TrackEvent("level_completed", properties);
// Non-async version
HardalManager.Instance.TrackEventNonAsync("item_purchased", properties);Enable debug logging in the Inspector to see detailed information about:
- Initialization status
- Event tracking
- Network requests
- Errors and warnings
To enable debug mode:
- Select the HardalManager GameObject
- Check "Enable Debug Logs" in the Inspector
- View logs in the Unity Console with "[Hardal]" prefix
using UnityEngine;
using System.Collections.Generic;
using Hardal.Signal;
public class GameManager : MonoBehaviour {
private void Start() {
// Track game start
HardalManager.Instance.TrackEventNonAsync("game_started");
}
public void OnLevelComplete(int level, int score) {
var properties = new Dictionary<string, object> {
{ "level", level }, { "score", score }, { "time_spent", Time.time }
};
HardalManager.Instance.TrackEventNonAsync("level_completed", properties);
}
}using System;
using System.Collections.Generic;
using UnityEngine;
using Hardal.Signal;
public class AnalyticsManager : MonoBehaviour {
private async void TrackPurchase(string itemId, float price,
string currency) {
var properties = new Dictionary<string, object> {
{ "item_id", itemId },
{ "price", price },
{ "currency", currency },
{ "platform", Application.platform.ToString() },
{ "timestamp", DateTime.UtcNow }
};
try {
await HardalManager.Instance.TrackEvent("purchase_completed", properties);
} catch (Exception e) {
Debug.LogError($"Failed to track purchase: {e.Message}");
}
}
}- Only one instance of HardalManager should exist in your project
- The manager persists between scenes using DontDestroyOnLoad
- Always check if the SDK is initialized before tracking events
- Use try-catch blocks when working with async methods
- Enable debug logs during development for better visibility
- Initialize the SDK early in your game lifecycle
- Use meaningful event names
- Be consistent with property names
- Handle async operations properly
- Test with debug mode enabled during development
Maintained by Hardal.