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): voidhandler: function ConsentPolicyChangedHandler(event: ConsentPolicyChangedEvent): void
onConsentPolicyChanged Parameters
NAME
TYPE
DESCRIPTION
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:
ConsentPolicyChangedHandler Parameters
NAME
TYPE
DESCRIPTION
The event that occurred when the consent policy changed.
Returns
This function does not return anything.
Return Type:
Was this helpful?
Run code when a visitor's consent policy changed
1import { consentPolicy } from 'wix-window-frontend';23// ...45consentPolicy.onConsentPolicyChanged((event) => {6 const policy = event.policy();7 console.log(event);8});910/* Full event object:11 * {12 * "defaultPolicy": false,13 * "policy": {14 * "functional": false,15 * "analytics": true,16 * "advertising": false,17 * "dataToThirdParty": false,18 * "essential": true19 * },20 * "createdDate": "2021-07-04T23:36:00.000Z"21 * }22 */