> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # UpdateConsentPolicy # Package: siteProperties # Namespace: SitePropertiesV4 # Method link: https://dev.wix.com/docs/api-reference/business-management/site-properties/properties/update-consent-policy.md ## Permission Scopes: Manage Consent Policy: SCOPE.DC-SITEPROP.MANAGE-PROPERTIES ## Introduction Updates a site's default consent policy. Read more about [Consent Apps](https://dev.wix.com/docs/build-apps/launch-your-app/legal-and-security/about-consent-apps.md#about-consent-apps). --- ## REST API ### Schema ``` Method: updateConsentPolicy Description: Updates a site's default consent policy. Read more about [Consent Apps](https://dev.wix.com/docs/build-apps/launch-your-app/legal-and-security/about-consent-apps.md#about-consent-apps). URL: https://www.wixapis.com/site-properties/v4/properties/policy Method: POST Method parameters: param name: consentPolicy | type: ConsentPolicy - name: essential | type: boolean | description: Whether the site uses cookies that are essential to site operation. Always `true`. - name: functional | type: boolean | description: Whether the site uses cookies that affect site performance and other functional measurements. - name: analytics | type: boolean | description: Whether the site uses cookies that collect analytics about how the site is used (in order to improve it). - name: advertising | type: boolean | description: Whether the site uses cookies that collect information allowing better customization of the experience for a current visitor. - name: dataToThirdParty | type: boolean | description: CCPA compliance flag. Return type: UpdateConsentPolicyResponse EMPTY-OBJECT {} Possible Errors: HTTP Code: 401 | Status Code: UNAUTHENTICATED | Application Code: META_SITE_NOT_FOUND | Description: Couldn't find the site. HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: PERMISSION_DENIED | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions. ``` ### Examples ### Update site consent policy ```curl curl -X POST \ 'https://www.wixapis.com/site-properties/v4/properties/policy' -H 'Content-Type: application/json' \ -H 'Authorization: ' \ --data-binary '{ "consentPolicy": { "essential": true, "functional": true, "analytics": false, "advertising": true, "dataToThirdParty": true } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.siteProperties.SitePropertiesV4.updateConsentPolicy(consentPolicy) Description: Updates a site's default consent policy. Read more about [Consent Apps](https://dev.wix.com/docs/build-apps/launch-your-app/legal-and-security/about-consent-apps.md#about-consent-apps). # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: consentPolicy Method parameters: param name: consentPolicy | type: ConsentPolicy | required: true - name: essential | type: boolean | description: Whether the site uses cookies that are essential to site operation. Always `true`. - name: functional | type: boolean | description: Whether the site uses cookies that affect site performance and other functional measurements. - name: analytics | type: boolean | description: Whether the site uses cookies that collect analytics about how the site is used (in order to improve it). - name: advertising | type: boolean | description: Whether the site uses cookies that collect information allowing better customization of the experience for a current visitor. - name: dataToThirdParty | type: boolean | description: CCPA compliance flag. Return type: PROMISE EMPTY-OBJECT {} Possible Errors: HTTP Code: 401 | Status Code: UNAUTHENTICATED | Application Code: META_SITE_NOT_FOUND | Description: Couldn't find the site. HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: PERMISSION_DENIED | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions. ``` ### Examples ### updateConsentPolicy - Practical Example (with $w) 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. ```javascript /************************************************** * Backend code - update-consent-policy.web.js/ts * *************************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { siteProperties } from '@wix/business-tools'; import { auth } from '@wix/essentials'; export const myUpdateConsentPolicyFunction = webMethod(Permissions.Anyone, async (consentPolicy) => { try { const elevatedUpdateConsentPolicy = auth.elevate(siteProperties.updateConsentPolicy); await elevatedUpdateConsentPolicy(consentPolicy); console.log('Success! Updated policy'); return true; } catch (error) { console.error(error); throw new Error(error); } }); /************* * Page code * ************/ import { myUpdateConsentPolicyFunction } from 'backend/update-consent-policy.web'; $w.onReady(() => { $w('#submit').onClick(async () => { const updatedPolicy = { advertising: $w('#advertising').checked, analytics: $w('#analytics').checked, dataToThirdParty: $w('#dataToThirdParty').checked, essential: $w('#essential').checked, functional: $w('#functional').checked } const isUpdated = await myUpdateConsentPolicyFunction(updatedPolicy); if (isUpdated) { console.log('Consent policy successfully updated'); $w('#successfulUpdateMsg').show(); setTimeout(() => { $w('#successfulUpdateMsg').hide(); }, 10000); } }); }); ``` ### Update Consent Policy (with elevated permissions) @description: ```javascript import { siteProperties } from '@wix/business-tools'; import { auth } from '@wix/essentials'; /* Sample objectArg value: * { * advertising: true, * analytics: true, * dataToThirdParty: true, * essential: true, * functional: true * } */ export async function myUpdateConsentPolicyFunction(consentPolicy) { try { const elevatedUpdateConsentPolicy = auth.elevate(siteProperties.updateConsentPolicy); await elevatedUpdateConsentPolicy(consentPolicy); console.log('Success! Updated policy'); return true; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to void */ ``` ### Update Consent Policy @description: ```javascript import { siteProperties } from '@wix/business-tools'; /* Sample objectArg value: * { * advertising: true, * analytics: true, * dataToThirdParty: true, * essential: true, * functional: true * } */ export async function myUpdateConsentPolicyFunction(consentPolicy) { try { await siteProperties.updateConsentPolicy(consentPolicy); console.log('Success! Updated policy'); return true; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to void */ ``` ### updateConsentPolicy (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { siteProperties } from '@wix/business-tools'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { siteProperties }, // Include the auth strategy and host as relevant }); async function updateConsentPolicy(consentPolicy) { const response = await myWixClient.siteProperties.updateConsentPolicy(consentPolicy); }; ``` ---