Unity version: 2021.3.41f1
This Unity project contains an event tracking service designed to collect and send analytics events to a server. It is designed to ensure that critical data is not lost, even in the case of application crashes or unexpected shutdowns.
- Event Queuing: Events are queued and sent in batches to minimize server requests. The service employs a cooldown mechanism to gather events over a set period before sending them to the server in one request.
- Guaranteed Delivery: Events are only removed from the queue after the server successfully processes them (
HTTP 200 OK
). If the server is unreachable, the events will remain in the queue and be resent when possible. - Persistent Storage: Events are stored locally using Unity's
Application.persistentDataPath
, ensuring that they are retained between sessions. This is especially important for WebGL, where detecting application closure is not always possible. - Simple Integration: Easily integrated into any Unity project by attaching the
EventService
MonoBehaviour to a GameObject.
- Tracking Events: Use the
TrackEvent
method to queue events for tracking.
eventService.TrackEvent("levelStart", "level:3");
- Event Types: Customize the
type
anddata
fields to match the specific analytics events you need to track. - Cooldown Mechanism: Configure the cooldown period (
cooldownBeforeSend
) to determine how often events are sent to the server.
- Add the
EventService
script to a GameObject in your scene. - Configure the
serverUrl
and other settings directly in the Unity Inspector. - The service will automatically start tracking and sending events as they occur.