🔔️ NotificationsKit

Notify your players of different events that occur in your game

What is NotificationsKit?

NotificationsKit allows you to send notifications to your players, informing them of different events in your game. It functions very similarly to how mobile notifications work, albeit in the browser.
Unlike on mobile, notifications on Trail are not opt-in by default. A player has to opt-in to get notifications. This can be done through an in-game request that you show to the player or through their profile settings.

🚧

User Experience

Notifications is a tricky feature and can be misused. We, at Trail, care a lot about the user experience, which is why using notifications requires activation before you can use it. It is also limited to static content at the moment.
You'll need to reach out to us on {Discord](https://discord.com/invite/trail) with your use case.

A sample of a notification displayed to players.A sample of a notification displayed to players.

A sample of a notification displayed to players.

Screenshot showing where a player may opt-out or in to get notifications for a certain game.Screenshot showing where a player may opt-out or in to get notifications for a certain game.

Screenshot showing where a player may opt-out or in to get notifications for a certain game.

Using NotificationsKit

First, you'll want to ask the player to subscribe for notifications:

// Remember to initialize the SDK first

private void CheckNotificationsPermissions()
{
  // Request the permissions status from Trail. We add a callback to check its result
  SDK.NotificationsKit.GetPermissionStatus(CheckPermissionStatus);
}

// Callback for checking the permission status.
private void CheckPermissionStatus(Result result, bool allowed)
{
  // If the result of the process is not an error.
  if(result.IsOK()) {
    
    // If the player accepts subscribing to notifications.
    if(allowed) {
      
      // We create a KeyValueList to identify which notifications we want to add them to
      KeyValueList notificationsValues = new KeyValueList();
      notificationsValues.Add(new KeyValue("MatchAvailable", "true"));
      
      // We then send to Trail the request permission to display that for the user and add a callback to see the result of the request
      SDK.NotificationsKit.RequestPermission(notificationsValues, CheckRequestStatus);
    }
  }
  else {
    Debug.Log("An error occurred while getting permission: " + result);
  }
}

private void CheckRequestStatus(Result result, bool allowed)
{
  if(result.IsOk()) {
    if(allowed) {
      
      // Send to our backend the user information and them to the list of players to notify whenever we need to.
      MyBackend.Add(user, userinfo);
      MyBackend.PushNotification(user, myNotificationType);
    }
  }
  else {
    Debug.Log("An error occurred while requesting permission: " + result);
  }
}

📘

Note that notifications are currently locked to trigger every 180 minutes to prevent spamming the user.

In your backend, you can send an HTTP request using cURL with the below content:

curl -X POST \
  https://json.api.beta.trail.gg/v2/notifications-kit/broadcast \
  -H 'Authorization: Bearer your-api-token' \
  -H 'Content-Type: application/json' \
  -d '{
    "game_id": "0000-0000-0000-0000",
    "type": "match_available",
    "target": {
      "region": "eu",
      "has_purchased: "true",
    }
  }'

🚧

Notifications Type

If you plan to use NotificationsKit, we recommend that you use the event type match_available for your tests. However, if you require a custom event type (say for a seasonal event) that you reach to us on Discord

Updated 4 months ago

🔔️ NotificationsKit


Notify your players of different events that occur in your game

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.