Written by The Jahia Team
 
Developers
Sysadmins
   Estimated reading time:

Overview

After jExperience loads the initial page the user is viewing, it contacts the context server, using wem.js, to retrieve default context information automatically from the context.json endpoint. This results in a cxs object being injected in the global javascript variable space, thus making it available to any javascript code running on the page:

cxs = {
    profileId: <identifier of the current user's profile>,
    sessionId: <identifier of the current user's session>,
    profileProperties: <optional, mapping profile property names to their values>,
    sessionProperties: <optional, mapping session property names to their values>,
    profileSegments: <optional array of segments the user matches>,
    filteringResults: <optional array of filtering results>,
    trackedConditions: <optional array of tracked conditions>
}

Technically, the cxs object is the result of a GET request to jCustomer context.json endpoint.

Context load callback

Since the window.cxs object is only created after the first call to jCustomer context, the wem.js library includes a function allowing callback functions to be registered to trigger actions on the collected data.

window.wem._registerCallback(() => {
    console.log('Context loaded')
})

Multiple callback functions can be added via wem.js and will all be called after every call to the jCustomer context.

More details about wem.js can be found on this page.