One of the more interesting features of Qlik Sense is the session sharing. When you open a Qlik Sense app on your iPad that you have already open on your laptop your selections are already there. And when you make a change on the iPad, the laptop window updates. It feels a bit like magic!
Of course it isn’t magic. Qlik Sense automatically shares your sessions on different devices and rather than creating a new one when you connect from the iPad, it attaches to the one you already have on your laptop. Sessions are shared between browser tabs, browsers and devices. Sharing is made based on three factors:
- the app, of course. Sessions are app-based so the the app has to be the same for the connections to share the same sesion
- the authenticated user. sessions are not shared between users
- the URL used when connecting to the QIX engine
You might very well be using session sharing without really thinking about it. If you open the same app in more then one tab in the browser each tab has it’s own connection to the engine, and engine will connect them in just the same way as connections from different devices. Not that neither device or browser used affect the sharing, it’s just app, user and URL.
But sometimes you want to separate connections to have separate selection state. The way to do this is to make sure that the URL used to connect to QIX Engine is different. The standard URL used to connect to Engine has the format:
- wss for secure websocket (ws for Qlik Sense Desktop)
- your server hostname or ip address, optionally with a port number (4848 for desktop)
- possibly a proxy if you are on a server
- and the app id
But you can add something more at the end, to make sure you separate your connections
The Qlik Sense Client actually allows you to do this. You can add an identity to the end of the URL to separate sessions. Let’s make an experiment:
- Open an app (any app) in a browser window using the Qlik Sense client
- Open the same app in another browser window using a different device, a different browser or a different tab
- Verify that selections made in one of the windows affects the other – you have got one single session
- Now in one of the browser windows, modify the browser URL by adding ‘/identity/xxxx’ at the end and refresh
- Verify that selections made in one window does not affect the other
You have just managed to separate your connections into two different sessions! While this can be very useful to do with the standard client, for some solutions it is essential. You should really always consider this when you are building a Qlik Sense solution using the APIs.
Using the browsers developer tools you can see how this is done. Open the developer tools for the browser where you added ‘/identity/xxxx’ at the end of the URL.
Click on the network tab, and filter on Web Sockets (WS). Find the connection to QIX Engine. You will see that the client has added ‘/identity/xxxx’ to the end, probably encoded to ‘%2Fidentity%2Fxxxx’.
Check the messages received on the web socket. At the begging you will find:
which is a message from QIX Engine, saying that it has created a new session.
Now remove the ‘/identity/xxxx’ from the URL and refresh. Find the Web Socket again, now there is no ‘/identity/xxxx’ at the end. Check the messages again, and at the beginning you will find:
which means that the QIX Engine found a matching session and instead of creating a new one, attached you to the existing, so you are again sharing sessions.