Search.../

updateConsentPolicy( )

Developer Preview

Updates a site's consent policy.

Description

The updateConsentPolicy() function returns a Promise that resolves when the site's consent policy is updated.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updateConsentPolicy(consentPolicy: ConsentPolicy): Promise<void>

updateConsentPolicy Parameters

NAME
TYPE
DESCRIPTION
consentPolicy
ConsentPolicy

Default consent policy defined by the site owner. Can be further limited by site visitors.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Update Consent Policy (dashboard page code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { siteProperties } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample objectArg value:
5 * {
6 * advertising: true,
7 * analytics: true,
8 * dataToThirdParty: true,
9 * essential: true,
10 * functional: true
11 * }
12 */
13
14export async function myUpdateConsentPolicyFunction(consentPolicy) {
15 try {
16 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);
17 await elevatedUpdateConsentPolicy(consentPolicy);
18
19 console.log('Success! Updated policy');
20 return true;
21 } catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25}
26
27/* Promise resolves to void */
28
Update Consent Policy (export from backend code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { siteProperties } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample objectArg value:
6 * {
7 * advertising: true,
8 * analytics: true,
9 * dataToThirdParty: true,
10 * essential: true,
11 * functional: true
12 * }
13 */
14
15export const myUpdateConsentPolicyFunction = webMethod(Permissions.Anyone, async (consentPolicy) => {
16 try {
17 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);
18 await elevatedUpdateConsentPolicy(consentPolicy);
19
20 console.log('Success! Updated policy');
21 return true;
22 } catch (error) {
23 console.error(error);
24 // Handle the error
25 }
26});
27
28/* Promise resolves to void */
29
updateConsentPolicy - Practical Example

This code is an example of a webpage where users can update the consent policy, using checkboxes to indicate the values. This page is only accessible to managers.

Copy Code
1/***********************************************
2 * Backend code - update-consent-policy.web.js *
3 **********************************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { siteProperties } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export const myUpdateConsentPolicyFunction = webMethod(Permissions.Anyone, async (consentPolicy) => {
9 try {
10 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);
11 await elevatedUpdateConsentPolicy(consentPolicy);
12
13 console.log('Success! Updated policy');
14 return true;
15 } catch (error) {
16 console.error(error);
17 throw new Error(error);
18 }
19});
20
21
22/*************
23 * Page code *
24 ************/
25
26import { myUpdateConsentPolicyFunction } from 'backend/update-consent-policy.web';
27
28$w.onReady(() => {
29 $w('#submit').onClick(async () => {
30 const updatedPolicy = {
31 advertising: $w('#advertising').checked,
32 analytics: $w('#analytics').checked,
33 dataToThirdParty: $w('#dataToThirdParty').checked,
34 essential: $w('#essential').checked,
35 functional: $w('#functional').checked
36 }
37 const isUpdated = await myUpdateConsentPolicyFunction(updatedPolicy);
38
39 if (isUpdated) {
40 console.log('Consent policy successfully updated');
41 $w('#successfulUpdateMsg').show();
42 setTimeout(() => {
43 $w('#successfulUpdateMsg').hide();
44 }, 10000);
45 }
46 });
47});
48