The Session API provides a mechanism for associating persisted key/value pairs with a user as they navigate between pages.
It consists of two methods exported from frontend-js-web
:
setSessionValue(key, data)
makes a request to the server to associate data
with key
in the user's session. If data
is a non-falsy object, it will be encoded with JSON.stringify()
and prefixed with a special marker, serialize://
, to flag it for deserialization on later retrieval. Otherwise, it gets transmitted as-is.
getSessionValue(key)
retrieves string data from the user's session by making a fetch request to the server at a portal/session_click
endpoint. If the retrieved data begins with the serialize://
prefix, it is stripped off and the remaining text is parsed as JSON using JSON.parse()
. Otherwise, the data string is returned as-is.