$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
ƒ() denotes a function.
Variables and methods overview
| Name | Return type | Description |
|---|---|---|
id | string | Returns the ID of the current session. |
referer | string | Returns the external page through which the user reached the shop (e.g. Google, Facebook). |
userReferer | string | 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. |
isInvalid | bool | true if the session is invalid, otherwise false. |
isLocked | bool | true if the session is locked (payment process), otherwise false. |
set() | - | Sets a session variable. |
get() | string | Returns the value of a session variable previously stored with set(). |
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 namedws_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. Returnstrue if the session is invalid.
$wsSession.isLocked
Returnstrue 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
| Name | Type | Required | Description |
|---|---|---|---|
key | string | yes | Name of the session variable. |
value | string | yes | Value of the session variable. |
$wsSession.get()
Returns the value of a session variable previously stored withset(). Returns an empty string if the variable does not exist.
Signature$wsSession.get(key)
Return valuestring - Value of the session variable.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
key | string | yes | Name of the session variable. |
Actions
Actions for this module are documented separately in the actions chapter: SessionExamples
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.
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 parameterpromoCode 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.
