Skip to main content
A user property is a string attribute stored on a user, for example plan or location. The dashboard filters and groups users by it, and remote configuration reads it to pick a value for the user. Analytics Web sets it with setProperty. Grain Tag has no method for user properties.

Set a property

The SDK sends the properties for the effective user ID: the ID from identify or login, or the anonymous ID. The properties stay on the user until a later call overwrites them. Read Identify users. Set a property when a user signs up and when the value changes.

Values

Every value becomes a string before the SDK sends it. Compare a property as a string when you read it.

Set properties for another user

The userId option sends the properties to a user other than the current one.
With JWT authentication, the userId option must equal the subject of the token. The API rejects a call for another user. Grain also rate-limits a source that sets properties for many distinct user IDs. Read Security.

Properties in remote configuration

Remote configuration segments a user by properties. Pass the same properties in the properties option of getConfigAsync, and the response holds the value for that segment.
Read Remote configuration and Personalization.

Limits

To store more than four properties, make more than one call.

Failures

setProperty returns a promise. The promise resolves after the request, and it does not reject on a failure. The SDK logs the failure on the console instead.

React

useGrainAnalytics returns the client. Call setProperty on it.
Read React hooks.

Rules for the client

  1. Identify the user before you set properties. Otherwise the properties go to the anonymous ID.
  2. Set a property when its value changes, not on every page load.
  3. Use the same key in setProperty and in the properties option of remote configuration. The segment matches on the key.
  4. Send only properties that the user consented to. Read Privacy and consent.