Categories, services, and purposes
How CookieBeam organizes consent into categories that gate scripts, optional per-service toggles, and US opt-out purposes for state privacy laws.
Last updated:
CookieBeam gives visitors control at three levels of granularity. Categories are the main unit: every script, cookie, and connection on your site belongs to one, and the visitor accepts or rejects whole categories. Services are an optional finer layer inside a category, letting visitors toggle individual vendors. US opt-out purposes are a separate axis that maps to specific US state privacy laws and lives alongside categories in the consent record.
Categories
A category is a named group of scripts and cookies that share a consent requirement. When a visitor accepts a category, every script tagged with it is allowed to run. When they reject it, those scripts stay blocked.
The defaults
Every banner starts with four categories:
| Id | Meaning | readOnly | enabled (opt-out) |
|---|---|---|---|
necessary | Scripts the site needs to function (session cookies, security, load balancers) | true | true |
analytics | Measurement and performance (analytics platforms, error tracking) | false | true |
marketing | Advertising and retargeting (ad networks, pixels, conversion tags) | false | true |
preferences | Personalization (language, layout, saved choices) | false | true |
You can rename the display labels in the dashboard without changing the ids. You can also add custom category ids for your own groupings; the runtime treats them the same way.
readOnly
A category with readOnly: true can't be toggled by the visitor. It's always accepted. Use it for scripts that the site can't function without. The necessary category is readOnly by default. The preferences modal still shows it, grayed out, so visitors can see what's in it.
enabled
The enabled flag sets the category's default state in opt-out mode. In opt-out, categories with enabled: true are accepted from the start; the visitor has to reject them explicitly. In opt-in mode, enabled is ignored: every non-readOnly category starts disabled until the visitor accepts it.
Custom categories
Add a category with any string id in the dashboard under Categories. The id is what you use in data-category attributes and in code that reads the consent record. Keep ids short, lowercase, and stable: changing an id after scripts are tagged with it breaks their gating.
How categories gate scripts
The blocking engine uses the data-category attribute to connect a script tag to a category:
<script data-category="analytics" type="text/plain"
data-src="https://example.com/tracker.js"></script>
The type="text/plain" prevents the browser from executing the script during HTML parsing. When manageScriptTags is on (the default), the runtime replaces the element with a live <script> once the category is accepted. If the visitor never accepts it, the script never runs. If the visitor later revokes it, the script won't run on the next page load.
A regular <script src> hardcoded in your HTML can't be intercepted this way: the browser starts fetching it while parsing, before any JavaScript runs. Always use the type="text/plain" + data-src pattern for HTML-embedded scripts. See Script blocking for the full set of gating patterns, including automatic blocking for dynamically injected scripts.
Automatic blocking works the same way: the scanner identifies scripts by vendor and assigns them a category. The runtime blocks and unblocks them without you adding attributes by hand.
Services
Services add per-vendor toggles inside a category. Without services, a visitor accepts or rejects all of marketing at once. With services, the preferences modal shows individual toggles for each vendor in that category.
A service belongs to exactly one category. It has a label (the display name the visitor sees) and optional onAccept and onReject callbacks. The service can also declare its own cookies for auto-clearing.
In the consent record, accepted services appear in the services field as a map of category id to an array of accepted service names:
{
"categories": ["necessary", "marketing"],
"services": {
"marketing": ["Google Ads", "Meta Pixel"]
}
}
A visitor might accept the marketing category but only enable two of its four services. Scripts tagged with data-category="marketing" still run (the category is accepted), but you can check the services map in your own code to decide whether to initialize a specific vendor.
When to use services
Services make sense when a category has several distinct vendors and your visitors care about which ones run. A marketing category with Google Ads, Meta Pixel, TikTok, and LinkedIn gives the visitor real choices. A necessary category with a session cookie and a CSRF token doesn't benefit from per-item toggles.
Services don't change how the blocking engine works. The engine gates on categories, not services. If you need to block one service in a category while allowing another, put them in separate categories instead.
Auto-clearing on revocation
When a visitor revokes consent for a category, CookieBeam can clean up after the scripts that ran under it. The autoClear configuration on a category lists what to remove:
- Cookies: by name (exact string or regex), with optional domain and path. The runtime deletes matching cookies by setting them to expire.
- localStorage and sessionStorage: by key name. The runtime calls
removeItemfor each listed key. - reloadPage: when
true, the page reloads after clearing. Some scripts leave state in memory that a cookie delete alone won't remove; a reload starts clean.
Auto-clearing runs when the visitor changes their choice in the preferences modal or when your code calls acceptCategory with a category the visitor previously had. It doesn't run on the first load: there's nothing to clear if the script never ran.
Services can declare their own cookies list. When a visitor deselects a service but keeps the category, the service's cookies are cleared while the category's other cookies remain.
US opt-out purposes
US state privacy laws (California's CPRA, Colorado's CPA, Virginia's VCDPA, Connecticut's CTDPA, and others) define processing purposes that visitors can opt out of. These purposes don't map one-to-one to CookieBeam's categories. A single category like marketing can involve multiple legal purposes, and a single purpose like "sale or sharing of personal information" can span multiple categories.
CookieBeam handles this with a separate purpose layer. When a US visitor opens the opt-out panel, they see purpose-level toggles:
| Purpose | Field in cookie | Laws |
|---|---|---|
| Sale or sharing of personal information | saleSharing | CPRA, CPA, VCDPA, CTDPA |
| Targeted advertising | targetedAdvertising | CPRA, CPA, VCDPA, CTDPA |
| Use of sensitive personal data | sensitiveData | CPRA |
| Profiling for decisions with legal or similar effects | profiling | CPA, VCDPA, CTDPA (reserved; no panel toggle yet) |
These choices are stored in the usOptOutChoices field of the consent record, separate from categories:
{
"categories": ["necessary", "analytics", "marketing"],
"usOptOutChoices": {
"saleSharing": true,
"targetedAdvertising": true
}
}
A true value means the visitor opted out of that purpose. The dashboard's regional rules configure which purposes appear for which states and how they interact with the category toggles.
How purposes interact with categories
The blocking engine runs on categories. When a visitor opts out of a US purpose, the runtime removes the categories associated with that right from the consent record:
| Right | Categories removed |
|---|---|
saleSharing | marketing, plus every custom category |
targetedAdvertising | analytics, marketing, plus every custom category |
sensitiveData | preferences |
A visitor who opts out of targetedAdvertising loses both analytics and marketing. Your server-side code and tag manager setup can check both layers: categories for script gating, usOptOutChoices for legal compliance with purpose-level obligations.
The consent log records both, and the purpose analytics endpoint reports opt-out rates per purpose.
How the three layers relate
| Layer | Stored in | Controls | Visitor sees |
|---|---|---|---|
| Categories | categories array | Script blocking, auto-clearing, Consent Mode mapping | Consent banner and preferences modal |
| Services | services map | Nothing directly (your code reads it) | Per-vendor toggles in preferences modal |
| US opt-out purposes | usOptOutChoices object | Removes opted-out right's categories from the consent record | US opt-out panel |
Categories are the load-bearing layer. They decide what runs and what doesn't. Services give visitors per-vendor control within a category. US opt-out purposes remove their associated categories (see the mapping above), so they do affect what the blocking engine blocks.
A minimal setup uses only categories. Add services when visitors ask for vendor-level control. Add purposes when you serve US visitors and need to comply with state opt-out laws. The three layers compose without conflicting: a visitor can accept the marketing category, enable only two of its services, and opt out of targetedAdvertising as a legal purpose, all in the same session.