- Installation
- Setup
- Basic Usage
- Debug Mode
- Example Usage
The Hardal SDK can be installed via Unity Package Manager:
- Add the package to your project via Package Manager
- Or add the following line to your
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
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);
}
}
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