setCustomAttribute

fun setCustomAttribute(key: String, value: Any, merge: Boolean = false): Boolean

Sets a custom user attribute for the given key. Supported value types are Boolean, Int, Float, Long, Double, String, java.util.Date, JSONObject, and JSONArray.

The key is validated against the server-configured blocklist and truncated to the maximum allowed field length. The value is cleaned up according to its type: strings are truncated, dates are formatted, and JSON structures are validated against the maximum nested attribute size. Unsupported value types are rejected.

When merge is true and value is a JSONObject, the object is merged into any existing attribute for the key rather than replacing it.

Return

true if the provided data passed validation and was accepted for processing, or false if the key is blocklisted, the value type is unsupported, or value cleanup failed (e.g. JSON exceeding max size, unparseable date).

Parameters

key

The identifier of the custom attribute. Must not be blocklisted. See CustomAttributeValidationUtils.isValidCustomAttributeKey.

value

The value of the custom attribute. Must be a supported type.

merge

If true and value is a JSONObject, merges with the existing attribute instead of replacing it. Ignored for non-JSONObject values. Defaults to false.