Mark the user present

How to use the presence API to mark a user present at a location


Overview

This API method allows you to mark the viewing user as present at the provided location.

window.CordSDK.presence.setPresent(location, options);
Copy

Usage

window.CordSDK.presence.setPresent({
  page: "https://cord.com",
  block: "id123",
}, {durable: true});
Copy

What this function returns

This function does not return anything.


Arguments this function takes


location

required
location
The location where the user will be marked as present.

options

optional
object
Miscellaneous options. See below.

The "options" argument


durable

optional
boolean
When true, this is a durable presence update; otherwise, it is an ephemeral presence update.
This value defaults to false.

absent

optional
boolean
When true, this is an absence update, meaning that the user has just left this location. If the user is currently present at that location, it is cleared; otherwise, nothing happens. This cannot be used with a durable presence update.
This value defaults to false.

exclusive_within

optional
location
Sets an "exclusivity region" for the ephemeral presence set by this update. A user can only be present at one location for a given value of exclusive_within. If the user becomes present at a different location with the same value of exclusive_within, they automatically become no longer present at all other locations with that value of exclusive_within.
This is useful to more easily track presence as a user moves among sub-locations. For example, suppose we'd like to track which specific paragraph on a page a user is present. We could make those updates like this:
window.CordSDK.presence.setPresent({
  page: pageID,
  paragraph: paragraphID,
}, {
  exclusive_within: {page: pageID}
});
As a user moves around a page, their paragraphID will change, while their pageID will remain the same. The above call to setPresent will mark them present at their specific paragraph. However, since every update uses the same exclusive_within, each time they are marked present at one paragraph they will become no longer present at their previous paragraph.
This value defaults to the value of the location argument (which effectively disables this behavior).