JavaScript SDK
Identifying the Visitor
Identifying the visitor
There are several ways to identify the visitor on Upscope.
Providing identity information
Regardless of whether you have the identity information at page load or later on, we encourage you to callĀ Upscope('init');
Ā as soon as possible so there is no delay in the continuation of an active session.
You can provide the details right with theĀ Upscope('init');
Ā function if you have them from your backend.
// Rest of the installation code...
Upscope('init', {
identities: ['John Smith', 'acme.com'],
uniqueId: '00032'
})
You can callĀ Upscope('init');
Ā first, then provide the identity information withĀ Upscope('updateConnection');
.
// Rest of the installation code...
Upscope('init');
// getVisitorInfo is a made up function you might have in your code that gives you visitor information
getVisitorInfo().then(visitor => {
Upscope('updateConnection', {
identities: [visitor.name],
uniqueId: visitor.id
})
});
You can provide the following bits of visitor information:
Key | Type | Description |
---|---|---|
| String[] | An array of strings with whatever identifying information you want to send us. |
| String | A string with a unique id of the visitor fromĀ your database. This could be the visitor's email address. |
| String[], each matchingĀ | An array of hashtags to filter visitors by. |
| String[], each matchingĀ | An array of strings representing an integration name an an integration id. For example if your app is calledĀ acmechat, and theĀ acmechat. ID for the visitor isĀ |
Removing pieces of identification
Any piece of identification set toĀ undefined
Ā will be ignored, meaning that if you identify visitors on theĀ /login
Ā page, and they navigate to another area of your site that doesn't have identification, we will keep the data we already have.
If you want to remove any piece of data, you'll need to set it toĀ null
.
Example
First page load on login screenā¦
Upscope('init', { identities: null });
// Visitor's identities will be null
Second pageload, visitor is now authenticatedā¦
Upscope('init', { identities: ['John'] });
// Visitor's identities will be ['John']
Third pageload to area that doesn't require authenticationā¦
Upscope('init');
// Visitor's identities will be ['John']
Fourth pageload after clicking logoutā¦
Upscope('init', { identities: null });
// Visitor's identities will be null
If you set aĀ uniqueId
Ā to null
Ā or to a different value after it was already set, Upscope will reset the connection and create a new visitor as we'll assume that they are now a different person. This will not happen if a session is currently ongoing.
Logging the visitor out
You can log the visitor out by callingĀ Upscope('reset');
. This will also reset the connection and create a new visitor with a new ID.
Using the watch link
The most reliable way to identify a visitor is to use the watch link. This is a unique link to the particular browser the visitor is using, generated for each visitor.
Browser or visitor?
Although we use the concept of "visitor" throughout the docs, we really meanĀ visitor's session.
If the same person logs in on two different browsers, and you initiate UserView each time with the sameĀ uniqueId, you'll end up with two separate visitors in UserView.
Each watch link looks like thisĀ https://upscope.io/w/SHORT_ID
.
We automatically add the watch link to most of our built-in integrations, but if you are building your own, you can retrieve the id by using the following
Upscope('getWatchLink', link => {
console.log(link);
});
Authentication
The watch link is not meant to be secret. You can freely share it around, as it will still require the agent to authenticate on UserView's dashboard to be used.
If you want to use the link without authentication (or without the agent having an UserView account, you'll need to exchange it with a secure one through the REST API.)
Need only the Short ID?
If you only need the Upscope Short ID for an integration, you can retrieve that by doing:
Upscope('getShortId', shortId => {
console.log(shortId);
});
Using the lookup code
Learn more about the lookup code on theĀ dedicated page.