Search.../

onConsentPolicyChanged( )

Sets the function that runs when a visitor's consent policy was changed using setConsentPolicy() or reset using resetConsentPolicy().

Description

Use the onConsentPolicyChanged() function for code you want to run after the visitor's current consent policy was changed using setConsentPolicy() or reset using resetConsentPolicy().

Usually, you want to call the onConsentPolicyChanged() function in the masterpage.js file in the code editor so that the onConsentPolicyChanged() event handler runs no matter which page on your site is used to change the policy.

Syntax

function onConsentPolicyChanged(handler: ConsentPolicyChangedHandler): void
handler: function ConsentPolicyChangedHandler(event: ConsentPolicyChangedEvent): void

onConsentPolicyChanged Parameters

NAME
TYPE
DESCRIPTION
handler

The name of the function or the function expression to run when the consent policy is changed.

Returns

This function does not return anything.

Return Type:

void

ConsentPolicyChangedHandler Parameters

NAME
TYPE
DESCRIPTION
event
ConsentPolicyChangedEvent

The event that occurred when the consent policy changed.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Run code when a visitor's consent policy changed

Copy Code
1import { consentPolicy } from 'wix-window-frontend';
2
3// ...
4
5consentPolicy.onConsentPolicyChanged((event) => {
6 const policy = event.policy();
7 console.log(event);
8});
9
10/* Full event object:
11 * {
12 * "defaultPolicy": false,
13 * "policy": {
14 * "functional": false,
15 * "analytics": true,
16 * "advertising": false,
17 * "dataToThirdParty": false,
18 * "essential": true
19 * },
20 * "createdDate": "2021-07-04T23:36:00.000Z"
21 * }
22 */