Channel

UaSDK. Channel

Your user's channel

Constructor

new Channel()

Example
// You will access this through the sdk
const sdk = await UA
// get the current channel id; this may be null if not yet resolved
const channelId = await sdk.channel.id()
// if you must be notified of the id once available, add a listener
sdk.channel.addEventListener('channel', (ev) => {
  const {id} = ev.detail
  console.log('Channel ID: %s', id)
})

Members

subscriptions :SubscriptionListManager

The subscription manager for this channel.

Type:
Example
// subscribe the channel to a list
await sdk.channel.subscriptions()
  .subscribe('cool-list')
  .apply()

Methods

editAttributes() → {AttributeEditor}

Create an attribute editor for the current channel.

Returns:
Type:
AttributeEditor

an attribute editor

Example
const editor = channel.editAttributes()
await editor
  .set("my_attribute", "some_value")
  .remove("other_attribute")
  .apply()

editTags() → {TagEditor}

Create a tag editor for the current channel.

Returns:
Type:
TagEditor

a tag editor

Example
const editor = channel.editTags()
await editor
  .add("device", ["tag1", "tag2"])
  .remove("my_group", ["grouped-tag"])
  .apply()

(async) id() → {Promise.<(string|null)>}

Retrieve the channel ID for the browser, if available.

Returns:
Type:
Promise.<(string|null)>

a promise which resolves to the channel ID if available, otherwise null

Example
const channelId = await sdk.channel.id()
if (!channelId) {
  await sdk.create()
}

(async) optedIn() → {Promise.<boolean>}

Get the browser channel's current push notification opt-in status.

Returns:
Type:
Promise.<boolean>

the current opt-in status

Example
const optedIn = await sdk.channel.optedIn()
if (!optedIn) {
  // prompt for opt-in
}

(async) optOut() → {Promise.<boolean>}

Opt this channel out of push notifications. In order to opt back in you need to call UaSDK#register again.

Returns:
Type:
Promise.<boolean>

Resolves to true if successful

Example
await sdk.channel.optOut()