Setting Consent

Save, stage, and reset consent preferences using the store API.

saveConsents(type)

Batch-save consent preferences. This is the primary way users grant or deny consent.

TypeBehavior
'all'Sets all configured categories (those in consentCategories) to true and saves
'necessary'Sets only necessary to true, all others to false, and saves
'custom'Saves the current selectedConsents as the final consents

After saving, the store syncs with the backend (in c15t or custom mode), stores the consent in a cookie, and triggers the onConsentSet callback.

setConsent(name, value)

Set a single category and immediately save. This is a shortcut for setting one category without staging.

setSelectedConsent(name, value)

Stage a consent toggle without saving. This is useful for building a preference dialog where the user can toggle multiple categories before confirming.

The selectedConsents state lets you render toggle states in a preference dialog without modifying the actual consent until the user confirms.

resetConsents()

Reset all consent preferences to their defaults. This clears stored consent and returns the user to an unconsented state.

Full Preference Dialog Flow

Here's a typical flow for a preference dialog: