Appearance
Unity SDK
Deliver sponsored push notifications in your Unity game on Android. The SDK wraps the native Android push library — all registration, notification display, and event tracking happens automatically.
Prerequisites
- Unity 2021.3 or later
- Firebase Unity SDK installed and configured (
google-services.jsonin your project) - Android build target
Install
- Download the SDK package — either from your dlserve dashboard via the per-channel Get SDK action, or directly: dlserve-unity-latest.unitypackage
- In Unity: Assets → Import Package → Custom Package → select the file.
Quick start
Add this to your first scene's script:
csharp
using DlserveSDK;
using Firebase.Messaging;
public class GameManager : MonoBehaviour
{
void Start()
{
// Initialize with your app ID from the dlserve dashboard.
Dlserve.Init("your-app-id");
// Optional: listen for notification events.
Dlserve.OnNotification += evt =>
Debug.Log($"dlserve: {evt.Type} — {evt.Title}");
// Wire up Firebase message routing.
FirebaseMessaging.TokenReceived += (s, e) =>
Dlserve.OnNewToken(e.Token);
FirebaseMessaging.MessageReceived += (s, e) =>
{
string json = MiniJson.Serialize(e.Message.Data);
if (Dlserve.HandleMessageIfDlserve(json)) return;
// Your own push handling here.
};
}
}That's it. The SDK handles device registration, notification display (with a visible "Sponsored" label), click tracking, and display pixel firing.
User identity & tags
Associate devices with your own user IDs and attach targeting tags:
csharp
Dlserve.Login("user-123");
Dlserve.SetTags(new Dictionary<string, string>
{
{ "plan", "premium" },
{ "level", "42" },
});
// Remove a tag by key.
Dlserve.RemoveTags("level");
// Clear user association.
Dlserve.Logout();API reference
| Method | Description |
|---|---|
Dlserve.Init(string appId) | Initialize the SDK. Call once, early. |
Dlserve.Login(string externalId) | Associate a user ID (max 256 chars). |
Dlserve.Logout() | Clear user association (local-only). |
Dlserve.SetTags(Dictionary<string, string>) | Set targeting tags (max 20, key ≤64, value ≤128 chars). |
Dlserve.RemoveTags(params string[]) | Delete tags by key. |
Dlserve.OnNewToken(string) | Forward FCM token rotations. |
Dlserve.HandleMessageIfDlserve(string) | Route FCM message; true = handled by dlserve. |
Dlserve.OnNotification | Event for displayed and opened lifecycle. |
How it works
- Push notifications arrive via Firebase Cloud Messaging (FCM).
- The SDK checks each message for the dlserve marker. Non-dlserve messages are ignored — your own push handling runs normally.
- Ad notifications display with a "Sponsored" label in a dedicated notification channel that users can independently disable.
- Tapping a notification opens the link in the device's default browser.
Notification events
Subscribe to Dlserve.OnNotification to react when notifications are displayed or tapped:
csharp
Dlserve.OnNotification += (DlserveNotificationEvent evt) =>
{
// evt.Type is "displayed" or "opened"
// evt.Title, evt.Body — notification content
// evt.ClickUrl — destination URL (only on "opened")
};