$wsAsse module, you trigger ASSE events (Asynchronous Server-Side Events) from within a template. An event sends an HTTP request in the background to an external URL defined in the configuration in order to transmit data to an external service (e.g. tracking after an order).
This page is about triggering preconfigured events from the template. How an event is set up (target URL, HTTP method, retries, success conditions) is described in the ASSE configuration.
Prerequisite
Before$wsAsse has any effect in the template, at least one event must be created in the configuration. Without a configured event, there is no event ID you could trigger, and fire() returns false.
The configuration defines which URL is called, which HTTP method is used, how often retries are performed on errors, and under what conditions a request is considered successful.
Basic concept
An ASSE event always follows the same flow: configure event → trigger in the template → request runs asynchronously in the background. You set up an event once in the configuration and give it an ID. In the template, you then trigger it viafire() using this ID and optionally pass data along. The shop then sends the HTTP request automatically in the background.
Asynchronous: return value does not equal success
fire() returns true as soon as the event is validly configured and the request has been queued. However, this does not mean that the external server has processed the request successfully. Since ASSE sends requests asynchronously, the actual execution happens with a time delay. Therefore, do not rely on the return value to verify the success of the external processing.
Triggering during page rendering
fire() is executed when the template is rendered, that is, on every call of the corresponding page. Therefore place the call only on the relevant page (e.g. the order confirmation) and keep in mind: if the customer reloads the page, the event is triggered again. For count-relevant events (e.g. tracking), make sure that triggering again does not cause any problems.
Passing data
ASSE appends the optional second parameterdata to the URL or sends it in the request body, depending on the HTTP method. Two points are important so that the data arrives correctly:
- The value is not automatically URL-encoded. If it contains special characters, encode it yourself.
- If you pass a list or an object, the value is automatically converted into a JSON object.
Module overview
Example / excerpt of$wsAsse
"ƒ()" denotes a function (method).
Variables and methods overview
| Name | Return type | Description |
|---|---|---|
asseConfigs | array | List of all configured events with their settings. |
fire() | bool | Triggers a preconfigured event. |
Variables
$wsAsse.asseConfigs
Returns a list of all configured events with their settings. Use it to check which events (and therefore which event IDs) are available before triggering one. If the list is empty ([]), no event is configured. The events are created in the configuration.
Methods
$wsAsse.fire()
Triggers a preconfigured event. In the background, an HTTP request is sent to the URL stored in the configuration. Via the second parameter, you can optionally pass data for the current operation. Depending on the HTTP method, this data is appended to the URL or sent in the request body. Signature$wsAsse.fire(eventId, data)
Return valuebool - true if the event is validly configured and has been triggered, false in case of a configuration problem, for example when the eventId does not match any configured event. Note the asynchronous behavior: true says nothing about the success of the external request.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
eventId | string | yes | ID of the event to be triggered. Must correspond to a valid ID from the configuration. |
data | string | no | Additional data to be sent with the request (see Passing data). |
myevent with the user ID:
$wsAccount.id comes from the $wsAccount module and returns the ID of the logged-in customer.
Examples
Trigger Awin tracking on the order confirmation page
A common use case is sending tracking data to an external service provider after a successful order. This example assembles the order data (order number, goods value, currency) from $wsCheckout into a parameter string and uses it to trigger theawintracking event.
Since this call fires on every page rendering (see Triggering during page rendering), it belongs exclusively on the order confirmation page.
awintracking must be created in the configuration that points to the Awin tracking URL. merchant=12345 is a placeholder and must be replaced with your Awin merchant ID.
Result After the order confirmation page has been rendered, the tracking request is sent to Awin in the background.
Related links
- ASSE configuration – defines the target URL, HTTP method, retries, and success conditions of an event. Prerequisite for
fire()to have any effect. - $wsCheckout – provides the order data passed in the tracking example.
- $wsAccount – provides the user ID used in the simple example.
$wsAsse module, you trigger ASSE events (Asynchronous Server-Side Events) from within a template. An event sends an HTTP request in the background to an external URL defined in the configuration in order to transmit data to an external service (e.g. tracking after an order).
This page is about triggering preconfigured events from the template. How an event is set up (target URL, HTTP method, retries, success conditions) is described in the ASSE configuration.
Before $wsAsse has any effect in the template, at least one event must be created in the configuration. Without a configured event, there is no event ID you could trigger, and fire() returns false.
Basic concept
An ASSE event always follows the same flow: configure event → trigger in the template → request runs asynchronously in the background. You set up an event once in the configuration and give it an ID. In the template, you then trigger it viafire() using this ID and optionally pass data along. The shop then sends the HTTP request automatically in the background.
Asynchronous: return value does not equal success
fire() returns true as soon as the event is validly configured and the request has been queued. However, this does not mean that the external server has processed the request successfully. Since ASSE sends requests asynchronously, the actual execution happens with a time delay. Therefore, do not rely on the return value to verify the success of the external processing.
Triggering during page rendering
fire() is executed when the template is rendered, that is, on every call of the corresponding page. Therefore place the call only on the relevant page (e.g. the order confirmation) and keep in mind: if the customer reloads the page, the event is triggered again. For count-relevant events (e.g. tracking), make sure that triggering again does not cause any problems.
Passing data
ASSE appends the optional second parameterdata to the URL or sends it in the request body, depending on the HTTP method. Two points are important so that the data arrives correctly:
- The value is not automatically URL-encoded. If it contains special characters, encode it yourself.
- If you pass a list or an object, the value is automatically converted into a JSON object.
Note:
"ƒ()" denotes a function (method).
| Name | Return type | Description |
|---|---|---|
asseConfigs | array | List of all configured events with their settings. |
fire() | bool | Triggers a preconfigured event. |
[]), no event is configured. The events are created in the configuration.
bool - true if the event is validly configured and has been triggered, false in case of a configuration problem, for example when the eventId does not match any configured event. Note the asynchronous behavior: true says nothing about the success of the external request.
| Name | Type | Required | Description |
|---|---|---|---|
eventId | string | yes | ID of the event to be triggered. Must correspond to a valid ID from the configuration. |
data | string | no | Additional data to be sent with the request (see Passing data). |
myevent with the user ID:
$wsAccount.id comes from the $wsAccount module and returns the ID of the logged-in customer.
awintracking event.
Since this call fires on every page rendering (see Triggering during page rendering), it belongs exclusively on the order confirmation page.
awintracking must be created in the configuration that points to the Awin tracking URL. merchant=12345 is a placeholder and must be replaced with your Awin merchant ID.
Result After the order confirmation page has been rendered, the tracking request is sent to Awin in the background.
Related links
- ASSE configuration – defines the target URL, HTTP method, retries, and success conditions of an event. Prerequisite for
fire()to have any effect. - $wsCheckout – provides the order data passed in the tracking example.
- $wsAccount – provides the user ID used in the simple example.
