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).

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'); });

Similar posts

Google Consent Mode

Google Consent Mode & Advanced Consent Mode This article is an introduction to the Theme Consent Mode, as well as ... Weiterlesen ...

Measuring consent rates with Matomo

Measuring consent rates with Matomo To be able to measure the consent rate using Matomo, only 1 line of JavaScript ... Weiterlesen ...

Quickstart

Quickstart/quick guide To log in, you will need the email address and password you entered when you purchased one of ... Weiterlesen ...

Piwik Pro: convert anonymous tracking to advanced tracking

Load as technically necessary and collect more visitor data after consent In our article https://legalweb.io/news/matomo-piwik-pro-rechtskonform-einbinden/ on Piwik Pro, both variants ... Weiterlesen ...
Privacy
The controller (legal web GmbH, Austria) would like to use the following services in order to process your personal data. Technologies such as cookies, localStorage, etc. can be used for personalization. This is not necessary for the use of the website, but allows us to interact with you more closely. If you wish, you can adjust or revoke your consent at any time via our privacy policy.