Skip to main content
With the $wsSession module, you can read out the customer’s session data in the frontend and set your own session variables. This allows you to display personalized content, track user behavior, or check the session status during payment processes. In this section, you will learn how to read and write session data.

Module overview

Example / excerpt of $wsSession
JSON output
Note: ƒ() denotes a function. Variables and methods overview

Templates

The data of the $wsSession module can be accessed in all templates.

Variables

$wsSession.id

Returns the ID of the current session.

$wsSession.referer

Returns the external page through which the user reached the shop, for example a search engine or a social network. The value is automatically set on the first page view and is also included in the order data.

$wsSession.userReferer

Returns a freely definable value that the user has set in the shop. It is set via an input field named ws_user_ref in the template. Whether and how the field is used is determined by the respective template design. The value is also included in the order data.

$wsSession.isInvalid

Checks whether the session is valid. Returns true if the session is invalid.

$wsSession.isLocked

Returns true if the session is locked. A lock occurs during online payment processes (e.g. PayPal, Klarna) to prevent parallel changes to the basket.

Methods

$wsSession.set()

Sets a session variable. These values remain valid across all subsequent pages until they are overwritten or deleted. Signature
$wsSession.set(key, value)
Parameters Example that stores a category in the session.

$wsSession.get()

Returns the value of a session variable previously stored with set(). Returns an empty string if the variable does not exist. Signature
$wsSession.get(key)
Return value
string - Value of the session variable.
Parameters Example that reads out a stored category.

Actions

Actions for this module are documented separately in the actions chapter: Session

Examples

Output the current session ID

Check whether the session is locked

A session can be temporarily locked when a buyer chooses a payment method with online clearing that redirects them to an external page (e.g. PayPal, credit card, Sofortüberweisung). During the lock, no further actions are possible in the shop in order to prevent inconsistencies – for example, if the customer adds products in another tab. The lock is released as soon as the buyer completes or cancels the payment process. Should this not be possible (e.g. if the external system is unreachable or the payment window was closed), the buyer can start a new session. The basket and login are retained. If the buyer accesses the shop during a lock, a notice message can be displayed:

Unlock session

If a session is locked due to a pending payment process, the buyer can manually unlock it by starting a new session. The current basket, all previous entries, and the login are retained. This is helpful when the payment process could not be completed, e.g. due to a closed payment window or a technical problem on the external payment page.

Set and query specific session data

With the $wsSession.set function, individual values can be stored in a user’s current session. These values remain valid across all subsequent pages until they are overwritten or deleted. This can be used for various purposes, e.g. to:
  • Save user preferences (e.g. preferred language or category).
  • Control dynamic shop displays based on previous behavior.
  • Make customer-specific adjustments for a personalized shopping experience, and much more.
Suppose a customer navigates to a specific category, e.g. “Running shoes”. You can store this information in the session to use it on other pages.
This information can then be used on subsequent pages to display relevant content and product recommendations to the user:

Access to session data using the example of the referer

With $wsSession, various values stored in the session can be read out and used. One example is the referer, which indicates from which external page the user reached the shop. This can be useful to analyze whether visitors came via a search engine, an advertisement, or a partner link, for example.

Read URL parameter and set session variable

Suppose there is a URL parameter promoCode that determines whether a special advertising banner for a discount campaign should be displayed. If this parameter is present and has a specific value, a session variable is set, which is then read out on other pages.
When a page is opened, it is checked whether the promo code was passed as a URL parameter. If so, the value is stored in the session so that it can be evaluated later.
Now, on another page, it can be checked which promo code was stored in order to output an appropriate discount banner: