Jimo Knowledge Base
Ask or search…
⌃K

[Deprecated] Session Continuity

Let's see how to make sure a session can recover its session
This guide has been marked as deprecated. Please check our Identify users guide instead.
​
If your app shows Jimo to authenticated users, you might want to make sure that the Jimo session associated to that user stays the same.
To do so, we offer a feature called Session Continuity. Basically, when a user sign in your app, you will attach a private and secure arbitrary value (ex: user ID) that is known to your system, and sent when you inject Jimo in the page. Each user must be associated to a different token.

Before setup

  • Make sure your token is unique and not guessable (ex. UUID, NanoId, CUID, etc.);
  • In some companies, customer support team / admins log in to their end-users accounts, for customer / debugging purposes. In this specific case, we advise to either disable the Session Continuity feature (do not set the token), or to not load Jimo at all, to prevent unexpected behavior.

How to set a session token

To set a session token, you have to set the JIMO_SESSION_TOKEN variable.
<script>
window.jimo = [];
(function(j,i,m,o) {
var s = document.createElement("script");
​
s.type = "text/javascript";
s.async = true;
s.src = "https://undercity.usejimo.com/jimo-invader.js";
j['JIMO_PROJECT_ID'] = "my-project-id";
j['JIMO_SESSION_TOKEN'] = "my-unique-token"; // Change this
​
document.getElementsByTagName("head")[0].appendChild(s);
})(window);
</script>
If your app retrieve user data after the page is built (example: single page application), you can do the following :
function fetchUserData() {
// fetch user data
window.jimo.push(['do', 'session:reset', [user.id]]) // will set the session token to the user id
}
If you are performing actions, through our SDK, to set user properties like setting id or email, make sure to perform them in the callback function to ensure it get applied to the correct session
function fetchUserData() {
// fetch user data and call a function afterward to set user id
window.jimo.push(['do', 'session:reset', [
user.id,
() => {
window.jimo.push([ "set", "user:id", ["8d64a44f-5e94-4ad6-8732-91a37f8d0ab0"] ])
}
]])
}
!!! Make sure the token you pass is unique and not guessable by others.

Advanced use cases

Segment.io integration

If you have setup the Jimo Segment.io integration, you might want to make sure Jimo is using the user created by Segment and vice versa.
For that, you will have to set the JIMO_SESSION_TOKEN with the same id you passed to Segment.identify methods.
function fetchUserData() {
// fetch user data
​
// call Segment.identify
analytics.identify(user.id);
​
// set JIMO_SESSION_TOKEN
window.jimo.push(['do', 'session:reset', [user.id]])
}
Last modified 1mo ago