Set Individual Attributes

Attributes are key-value pairs that you can use to segment your audience and personalize your messages. Examples of attributes include first name, last name, loyalty level, channel preference, signup date, birthday, ZIP code, or a unique identifier.

Manage Attributes in the Mobile App Messaging SDK for Android 

This code example shows how to set, clear, and retrieve attributes in the Mobile App Messaging SDK for Android.

1SFMCSdk.requestSdk { sfmcSdk ->
2      // Set/Update values in identity
3      sfmcSdk.identity.edit {
4          // add/update attributes to identity
5          attributes.put("key", "value")
6          attributes.putAll(mapOf("key1".to("value1"), "key2".to("value2")))
7
8          // set/replace attributes in identity
9          attributes.set("key3", "value3")
10          attributes.set(mapOf("key1".to("value1"), "key2".to("value2")))
11
12          // clearing attributes in identity
13          attributes.clear("key")
14          attributes.clear("key", "key1")
15          attributes.clearAll()
16      }
17
18      // Read values from Identity
19      val attributes = sfmcSdk.identity.attributes
20  }

Manage Attributes in the Mobile App Messaging SDK for iOS 

This code example shows how to set, clear, and retrieve attributes in the Mobile App Messaging SDK for iOS.

1// Set a single attribute
2SFMCSdk.identity.edit { [self] model in
3  model.addAttribute(key: "FavoriteTeamName", value: "favoriteTeamName")
4  return model
5}
6
7// Set multiple attributes
8SFMCSdk.identity.edit { [self] model in
9  model.addAttributes(attributes: ["FavoriteTeamName": "favoriteTeamName"])
10  return model
11}
12
13// Clear a single attribute
14SFMCSdk.identity.edit { [self] model in
15  model.clearAttribute(key: "AttributeKey")
16  return model
17}
18
19// Clear multiple attributes
20SFMCSdk.identity.edit { [self] model in
21  model.clearAttributes(attributes: ["AttributeKey1", "AttributeKey2"])
22  return model
23}
24
25// Get all attributes
26let attributes = SFMCSdk.identity.get()?.attributes