Attributes

Batch's User module allows you to give more information about your users.
In addition of overriding the language/region or setting a custom user ID, you can now assign tags and attributes to your users, allowing you to improve your Push targeting.

Custom attributes

IMPORTANT
- User IDs (email address, username, etc) must be managed using our custom user ID implementation.
- Region/language data must be managed using our custom region/language implementation.
- Never use an existing tagging plan. Read our guide on custom data before tagging your app.
- Newly tracked attributes and tags are hidden by default. You will need to manually display them from the dashboard settings > "Custom data" tab.

Managing attributes

Before we get started on how to implement attributes, here are some rules you should know.

Naming

Attribute names are strings. They should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 30 characters (e.g. has_premium).

Values

Values must be any of the following types:

  • string

Must not be longer than 64 characters and can be empty. For better results, you should make them upper/lowercase and trim the whitespaces.

  • long
  • double
  • bool
  • DateTimeOffset

Methods

The custom attribute API is simple, and has only three methods:

using BatchSDK;

Batch.User.GetEditor()
    .SetAttribute("age", 26) // Set an attribute
    .RemoveAttribute("age") // Remove it
    .ClearAttributes() // Removes all attributes
    .Save(); // Don't forget to save the changes!

Changes made to a editor happen transactionally and won't be persisted until you call save.

Please test your implementation using our debug tool before releasing your app on the store. Make sure you're unwrapping your optionals!

Managing tags

You can attach multiple tags to different collections. Collections names can't be longer than 30 characters (e.g. favorite_categories).

Tags have some limitations:

  • They are strings.
  • Their size can't be greater than 64 characters and they can't be empty.

Collection names have the same limitations as attribute names.

Here are the available methods:

using BatchSDK;

Batch.User.GetEditor()
    .AddTag("actions", "has_bought") // Add a tag to the "actions" collection
    .RemoveTag("actions", "has_bought") // Remove it
    .ClearTagCollection("actions") // Removes all tags from that collection
    .Save(); // Don't forget to save the changes!