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 useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
to prevent security vulnerabilities.
Copy Code
1import { siteProperties } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34/* Sample objectArg value:5 * {6 * advertising: true,7 * analytics: true,8 * dataToThirdParty: true,9 * essential: true,10 * functional: true11 * }12 */1314export async function myUpdateConsentPolicyFunction(consentPolicy) {15 try {16 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);17 await elevatedUpdateConsentPolicy(consentPolicy);1819 console.log('Success! Updated policy');20 return true;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25}2627/* Promise resolves to void */28
Update Consent Policy (export from backend code)
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
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';45/* Sample objectArg value:6 * {7 * advertising: true,8 * analytics: true,9 * dataToThirdParty: true,10 * essential: true,11 * functional: true12 * }13 */1415export const myUpdateConsentPolicyFunction = webMethod(Permissions.Anyone, async (consentPolicy) => {16 try {17 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);18 await elevatedUpdateConsentPolicy(consentPolicy);1920 console.log('Success! Updated policy');21 return true;22 } catch (error) {23 console.error(error);24 // Handle the error25 }26});2728/* 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';78export const myUpdateConsentPolicyFunction = webMethod(Permissions.Anyone, async (consentPolicy) => {9 try {10 const elevatedUpdateConsentPolicy = elevate(siteProperties.updateConsentPolicy);11 await elevatedUpdateConsentPolicy(consentPolicy);1213 console.log('Success! Updated policy');14 return true;15 } catch (error) {16 console.error(error);17 throw new Error(error);18 }19});202122/*************23 * Page code *24 ************/2526import { myUpdateConsentPolicyFunction } from 'backend/update-consent-policy.web';2728$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').checked36 }37 const isUpdated = await myUpdateConsentPolicyFunction(updatedPolicy);3839 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