Documentation

Did you find this helpful?

PlayStream Events

As the name implies, automatic event is an event that occurs automatically with a normal API method call. Most existing API methods will generate PlayStream events.

Sometimes, however, you will need to capture events that are very specific for your game and are not provided by PlayFab out of the box. For that purpose, consider using Custom Event (see next section).

Example

If email and password pair is valid, The following API call will sign in player with email and password:

PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest() {
    Email = "my@email.com",
    Password = "qwerty"
}, 
result=> Debug.Log(result.PlayFabId), 
error=> Debug.LogError(error.GenerateErrorReport()));

As a side effect, PlayFab will record player_logged_in event. Consider using Event History to test described behavior:

Custom Event Overview

While PlayFab records a lot of events automatically, sometimes you need events that are very specific for your game. The concept of custom events allows you to post events with arbitrary type and name. Similar to automatic events, custom events are fully reflected through real-time analytics tools. Unlike automatic events, you need a little bit of custom code to post custom events.

Custom events can be classified by "entity". Custom event can be bound to Player, Character or Title. Event entity reference is specified using two fields: EntityType and EntityID

Relevant API Calls

WritePlayerEventWriteCharacterEventWriteTitleEvent

Example: Post your own Custom Event

You want to aggregate information about players opening various chests. Along with standard event information, you want to record ChestType and LevelID. Unfortunately, PlayFab does not provide corresponding automatic event out of the box. Use custom player event to solve the problem.

Prerequisites

Your player is already logged in. In your code, you have a callback OnChestOpenLevelID and chest type are passed into that callback.

Solution

Once executed, the following code will post custom player event

private void OnChestOpened(string chestType, int levelId) {
    PlayFabClientAPI.WritePlayerEvent(new WriteClientPlayerEventRequest() {
        Body = new Dictionary<string, object>() {
            { "ChestType", chestType },
            { "LevelId", levelId }
        },
        EventName = "player_chest_opened"
    },
    result => Debug.Log("Success"),
    error => Debug.LogError(error.GenerateErrorReport()));
}

  1. Method receives chest type and level id.
  2. Use WritePlayerEvent API call for posting custom event bound to a player
  3. Provide body, specific for your event and your needs. In this case we provide chest_type and level_id fields
  4. Provide event name identifying your custom event. In this case we use "player_chest_opened" event type name

Testing

Once solution code is executed, consider using Event History to check that your event has been successfully registered:

  1. Filter using event name
  2. Ensure "player_chest_opened" events are in the list
  3. Ensure you have custom body fields recorded: "ChestType" and "LevelId"



Did you find this helpful?