Add Required Code

In order to send a push notification, you need to do two things in your game’s code:

  • Tell Teak who the player is with identifyUser.

  • Ask the player for permission to send them push notifications.

Identify User

Teak’s functionality depends on knowing when a user plays and on what device they play.

At every game launch, send the player’s ID to Teak using Teak.Instance.IdentifyUser().

What Player ID should you use?

Your game probably has a user ID to store progress, coin balances, and other useful data. Use that ID with Teak too.

  • It should be uniquely identify the current user.

  • Ideally the same ID that is used in your game’s backend.

  • Send it as early as possible in the game’s lifecycle.

Having a consistent ID between your game makes customer support easier, and makes life easier for your analytics team.

In our game script, as soon as we know the id for our current player, we’ll add our call.

Example
// ...
Teak.UserConfiguration userConfiguration = new Teak.UserConfiguration {};
Teak.Instance.IdentifyUser(YOUR_USER_ID, userConfiguration);
1 We create an empty userConfiguration object for now. We’ll add data to that in the next step.
2 Your YOUR_USER_ID string must be unique to the player. Again, we highly recommend using the same user id you use in your game’s backend.

This is enough to begin tracking and reporting of a session and tracking a daily active user.

Sending Additional Data

Next we’ll add some data to our UserConfiguration.

In SDK 5, Teak will no longer automatically collect Facebook Access Tokens or Emails from Facebook, instead you must pass the Facebook User Id in the UserConfiguration.

Here’s how we would add an email address and their Facebook ID. This will enable sending emails and templating a player’s real name into our notification and email content.

Data Example
// ...
Teak.UserConfiguration userConfiguration = new Teak.UserConfiguration {
  Email = YOUR_USER_EMAIL,
  FacebookId = YOUR_USER_FACEBOOK_ID
};
Teak.Instance.IdentifyUser(YOUR_PLAYER_ID, userConfiguration);
  • Null and empty strings will be ignored. Any previously set email address or Facebook ID for the player will remain set.

  • If you want to update player data during a session, call IdentifyUser again with the new data. This will update player data without starting a new session.

  • You can also use UserConfiguration to opt-out of some types of data collection.

Opting Out of Tracking

If the user has opted out of data collection completely, do not call IdentifyUser, and Teak will not track the user at all.

If the user has opted out of specific data collection, set the corresponding opt-out to true in the UserConfiguration.

See the UserConfiguration Docs for the available options.

Ask the Player for Push Permissions

On iOS and Android 13 and greater you are required to ask the user if you can send them notifications. Do that with the Teak.Instance.RegisterForNotifications() call.

In the long term, you can increase your notification opt-in rates by being strategic about when you ask for permission. Ideally, you would ask for these permissions at a time that makes sense for your game.

For the purpose of getting up and running fast, let’s put the permissions request right at game launch, for now.

Permissions Example
// ...
StartCoroutine(Teak.Instance.RegisterForNotifications(granted => {
  Debug.Log("Player " + (granted ? "granted" : "denied") + " notification permissions.");
});

Now your game will ask for push permissions when you launch the game. Make sure to approve them on your test device, so that we can send our notification at the end of this tutorial.

Testing Your Teak Installation

To confirm the successful installation of the Teak package, you should observe the following message in the console when Teak is first called.

Console Output when Teak initializes
[Teak] Unity SDK Version: 4.3
[Teak] IdentifyUser(): YOUR_PLAYER_ID

Note that this will only show up in the Unity Editor if you are running the part of the your game where you call Teak.Instance.IdentifyUser() and if Teak trace logging is enabled.

More in depth logging can be enable using Log Events.

Build Your Game

At this point, Teak is ready to to be tested on device.

  • Build your game and get it running on your test device.

  • Teak.Instance.RegisterForNotifications() will pop an alert asking for push permissions. Allow notifications, or you won’t be able to receive notifications on your device in the next step.

See Your Active User

  • Open the Teak Dashboard and navigate to your game.

    • If the Teak integration is working and identifyUser is being called, you will see yourself in the active user chart on the dashboard.

activeuser
Figure 1. The lone tester, playing the game.

If you’ve got an active user showing here, you are ready to test notification sends.