There are also two different ways to modify user attributes and channel attributes. You can use the manager interface (IBMMobilePush.Attribute.AttributeManager), which is preferred because it deals with error handling on its own, or you can use the direct client method. Both methods are the same; however, the manager interface method is not asynchronous and status must be derived from the delegate methods IBMMobilePush.SDK.AttributesSent and IBMMobilePush.SDK.AttributeKeysSent, which is then sent to IBMMobilePush.Attribute.AttributeManager.instance instead. The client interface is an asynchronous method and may also throw exceptions.

The manager class queues up the changes into a database and then tries to send them to the server. If they fail to send, they are automatically retried later.

A user attribute is an attribute that applies to all the devices one person owns. The system records attributes about a user and uses those values for segmentation. Any key can be set as a user attribute. There are no methods for retrieving values that are already set. If a user attribute has a corresponding column in the Watson Campaign Automation database, the attribute is updated in the Watson Campaign Automation database by using the user attribute setting call.

A channel attribute is an attribute that applies to a single device. If you set an attribute, it replaces all the attributes with the new set specified. Anything that is not included is deleted. If you update an attribute, it leaves all the previous attributes set for that user or channel in place.

There are eight different options for the attribute value class: string, int, bool, double, decimal, long, short, and DateTimeOffset. Only these eight options are accepted.

Modifying user attributes

You use the following code to set, update, or delete a user attribute.

To set user attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.SetUserAttributes(new List(){ new ApiAttribute("Name", "Value") }, true);
  • Or you can use the direct client:
    AttributeClient.SetUserAttributesAsync(new JsonArray(){ new ApiAttribute("Name", "Value").ToJson() });

To update user attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.UpdateUserAttributes(new List(){ new ApiAttribute("Name", "Value") }, true);
  • Or you can use the direct client:
    AttributeClient.UpdateUserAttributesAsync(new JsonArray(){ new ApiAttribute("Name", "Value").ToJson() });

To delete user attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.DeleteUserAttributes(new List(){ "Name" }, true);
  • Or you can use the direct client:
    AttributeClient.DeleteUserAttributesAsync(new JsonArray() { JsonValue.CreateStringValue("Name") });

Modifying channel attributes

You use the following code to update, set, or delete channel attributes.

To set channel attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.UpdateChannelAttributes(new List(){ new ApiAttribute("Name", "Value") }, true);
  • Or you can use the direct client:
    AttributeClient.UpdateChannelAttributesAsync(new JsonArray(){ new ApiAttribute("Name", "Value").ToJson() }); 

To update channel attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.SetChannelAttributes(new List(){ new ApiAttribute("Name", "Value") }, true);
  • Or you can use the direct client:
    AttributeClient.SetChannelAttributesAsync(new JsonArray(){ new ApiAttribute("Name", "Value").ToJson() }); 

To delete channel attributes, use either method by adding the following code.

  • You can use the manager interface:
    AttributeManager.Instance.DeleteChannelAttributes(new List(){ "Name" }, true);
  • Or you can use the direct client:
    AttributeClient.DeleteChannelAttributesAsync(new JsonArray() { JsonValue.CreateStringValue("Name") }); 

Go Back to the Mobile App Messaging home page.

Join The Discussion

Your email address will not be published. Required fields are marked *