Checking consent
Check if the user has given consent for a specific purpose with the has() method.
The has()
method returns a boolean
value and checks if the user has given consent for a specific purpose. It allows for simple & complex checks. This can be used to conditionally render content based on the user's consent, for example.
// Simple check
const hasAnalytics = has('measurement');
const hasMarketing = has('marketing');
// Complex check
const hasAnalyticsAndMarketing = has({
and: ['measurement', 'marketing'],
})
const hasEitherAnalyticsOrMarketing = has({
or: ['measurement', 'marketing'],
})
const doesNotHaveMarketing = has({
not: 'marketing',
})
// Nested checks
const condition = has({
and: [
'necessary',
{ or: ['measurement', 'marketing'] },
{ not: 'advertising' },
]
})