JavaScript Events
Various events are provided for interaction with other functionalities of the website.
This offers the possibility to control the popup or functionalities of the popup without interaction from the user, or to request status queries for consent.
Basically, all layouts offer the same events. This means that the same basic functionality is available regardless of whether TCF mode is activated or not.
After initialization of the script by the browser, the following methods are available via the window object. For some layouts, it is also possible to call the methods via the window.legalweb.popup object (without the “lw” prefix).
Event with consent or change of consent
lw-optinout
A custom event “lw-optinout” is dispatched for an opt-in or opt-out. The following details are transferred to the event
- integrationId: the Id of the service (google-analytics, matomo-analytics, …)
- integrationCategory: the category into which the service falls
- integrationCode: the JS code Base64 encoded which is executed at opt-in
- mode: ‘optin’ or ‘optout’
- time: new Date()
- sourceType: ‘placeholder’ or empty if it is the popup
- sourceParentNode: if sourceType ‘placeholder’ then the parent of the placeholder, otherwise null
- sourceNode: if sourceType ‘placeholder’ then the placeholder, otherwise null
Example of a binding
window.addEventListener('lw-optinout', function (e) { console.log('optinout', e.detail); });
lw-popup-closed
When the popup is closed, the lw-popup-closed event is dispatched. Closing can be triggered by clicking on one of the buttons, on the close icon or on the overlay. The following is passed to the event as e.datails.data
- cmpAction: the action that preceded the closing. The following values are possible: dismissAll, acceptAll, acceptSelection, none
- source: the control that triggered the closing. The following values are possible: overlay, btnClose, btnAcceptAll, btnAcceptNothing, btnAcceptSelection, method
Example of a binding
window.addEventListener('lw-popup-closed', function (e) { console.log('closed', e.detail); });
Events before and after the popup/notice is displayed
lw-beforeshowpopup and lw-beforeshownotice
Before the popup or notice is displayed, the corresponding event is triggered. The following code can be used to bind to the event:
window.addEventListener('lw-beforeshowpopup', function (e) { console.log('lw-beforeshowpopup', e.detail); });
Events before and after initializing the popup
lw-frontendinit-start and lw-frontendinit-complete
To find out at what point everything is initialized, this event is fired before the start and after the end of initialization.
In addition window.lwFrontendInitCompleted can be checked for true/false.
Events to be able to react to actions in the popup
Subsequent events are always fired when a visitor clicks one of the buttons for consent or non-consent.
For each event there is a start and a complete event
- lw-popupaction-accept-all-start
- lw-popupaction-accept-all-complete
- lw-popupaction-accept-selected-start
- lw-popupaction-accept-selected-complete
- lw-popupaction-dismiss-all-start
- lw-popupaction-dismiss-all-complete
- lw-overlay-clicked-start
- lw-overlay-clicked-complete
- lw-close-clicked-start
- lw-close-clicked-complete
window.addEventListener(''lw-popupaction-accept-selected-complete', function (e) { console.log('lw-popupaction-accept-selected-complete'); });