Attributes

Attributes

A channel's attributes

Constructor

new Attributes()

Enables attributes operations from the SDK. Currently we support only write operations: set and remove.

Example
// You will access this through the sdk
UA.then(function(sdk) { sdk.channel.attributes })

// Or using namedUser
UA.then(function(sdk) { sdk.channel.namedUser.attributes })

Methods

remove(…keys) → {Promise.<boolean>}

Remove one or more attributes from this channel

Parameters:
Name Type Attributes Description
keys Array.<string> <repeatable>

Attributes (keys) to remove from the channel

Returns:
Type:
Promise.<boolean>

Resolves to true on success and to false if no keys are passed. On error, the promise will be rejected with the associated error.

Example
// Channel
UA.then(function(sdk) {
  sdk.channel.attributes
    .remove("firstName", "age")
    .then(result => console.log("Firstname and age attributes have been removed!"))
    .catch(err => console.error("An error occured while removing 2 attributes: %s", err))
})

// Named User
UA.then(function(sdk) {
  sdk.channel.namedUser.attributes
    .remove("firstName", "age")
    .then(result => console.log("Firstname and age attributes have been removed!"))
    .catch(err => console.error("An error occured while removing 2 attributes: %s", err))
})

(async) set(attributes) → {Promise.<boolean>}

Set/update one or more attributes on this channel

Parameters:
Name Type Description
attributes object

Attributes keys/values to set or update

Returns:
Type:
Promise.<boolean>

Resolves to true on success and to false if provided attributes is an empty object. On error, the promise will be rejected with the associated error.

Example
// Channel
UA.then(function(sdk) {
   sdk.channel.attributes
     .set({firstName: "John", lastName: "Doe", birthdate: new Date('1980-01-01')})
     .then(result => console.log("Firstname, lastname and birthdate set!"))
     .catch(err => console.error("An error occured while setting attributes: %s", err))
})

// Named User
UA.then(function(sdk) {
   sdk.channel.namedUser.attributes
     .set({firstName: "John", lastName: "Doe", birthdate: new Date('1980-01-01')})
     .then(result => console.log("Firstname, lastname and birthdate set!"))
     .catch(err => console.error("An error occured while setting attributes: %s", err))
})