Table of Contents

User Attributes

VERSION

com.homagames.sdk-core 4.1.0

User Attributes provide a way to associate specific attributes with a user. These attributes enable segmentation of users into different groups based on defined characteristics.

Setting User Attributes

The HomaBelly class provides methods to set user attributes either individually or in bulk. When attributes are set for the first time during a session, a server synchronization is triggered via an HTTP request approximately 20 milliseconds later. Subsequent attribute updates are automatically batched and synchronized with the server at intervals of up to one minute.

Defining User Attributes in Homa Lab

To use the User Attributes API, you must first define the attribute schema within Homa Lab. Only attributes that are predefined in the schema will be accepted when set via the API.

Supported data types include integer, float, boolean and string. For example:

{
  "GameDifficulty": {
    "type": "string",
    "title": "Game Difficulty",
    "description": "How hard the game is"
  },
  "SubscriptionStatus": {
    "type": "string",
    "title": "Subscription Status",
    "description": "Current subscription the player is subscribed to"
  },
  "CompletedTutorial": {
    "type": "boolean",
    "title": "Completed Tutorial",
    "description": "If the user has completed the tutorial or not"
  },
  "Level": {
    "type": "integer",
    "title": "Current Player Level",
    "description": "The current level player is in"
  }
}

Setting Multiple Attributes

The SetUserAttributes method assigns multiple attributes to a user using key-value pairs.

var attributes = new Dictionary<string, object>
{
    {"GameDifficulty", "Hard"},
    {"SubscriptionStatus", "Premium"},
    {"CompletedTutorial", true}
};
HomaBelly.Instance.SetUserAttributes(attributes);

Setting a Single Attribute

The SetUserAttribute method assigns a single attribute to a user by specifying the key and its corresponding value.

HomaBelly.Instance.SetUserAttribute("Level", 10);

Refreshing Remote Config After Setting User Attributes

After the User Attributes API successfully synchronizes with the server, a new subset of remotely configured values may be returned. These updated values can be accessed and used to dynamically adjust gameplay or other app behavior in response to the latest user context. See LiveOps to learn how to listen to these updates.

See also