Use Consent Manager

Checking Consent

has(condition)

The has() method evaluates whether the current consent state satisfies a condition. It supports simple category checks and complex logical expressions.

Simple Check

const { has } = useConsentManager();

if (has('measurement')) {
  // User has granted measurement consent
}

AND Logic

All conditions must be true:

has({ and: ['measurement', 'marketing'] })
// true only if BOTH measurement AND marketing are granted

OR Logic

At least one condition must be true:

has({ or: ['measurement', 'marketing'] })
// true if EITHER measurement OR marketing is granted

NOT Logic

Negates a condition:

has({ not: 'marketing' })
// true if marketing consent is NOT granted

Nested Conditions

Combine operators for complex logic:

has({
  and: [
    'necessary',
    { or: ['measurement', 'marketing'] },
    { not: 'functionality' },
  ],
})
// true if: necessary AND (measurement OR marketing) AND NOT functionality

HasCondition Type

type HasCondition<CategoryType> =
  | CategoryType                                    // "measurement"
  | { and: HasCondition[] | HasCondition }          // { and: ["a", "b"] }
  | { or: HasCondition[] | HasCondition }           // { or: ["a", "b"] }
  | { not: HasCondition }                           // { not: "a" }

hasConsented()

Returns true if the user has made any consent choice (accepted, rejected, or customized). Returns false if no consent has been recorded yet.

const { hasConsented } = useConsentManager();

if (hasConsented()) {
  // User has previously made a consent choice
} else {
  // First visit — no consent recorded
}

getDisplayedConsents()

Returns the consent types that should be displayed in the UI (based on active consentCategories and each type's display property):

const { getDisplayedConsents } = useConsentManager();

const visibleCategories = getDisplayedConsents();
// Returns ConsentType[] with name, description, defaultValue, etc.