Skip to content

Privacy consent

Every public page defines window.CapellPrivacy before any theme or widget script runs. Ask it before you load an embed, set a cookie or send an analytics or marketing signal. A site without a consent manager gets Capell’s default runtime; a consent manager such as Privacy Center replaces it with one that records visitors’ choices. Your code works the same with either.

CapellPrivacy.allows(name) takes a category or a named purpose and returns:

ValueMeaningWhat to do
trueThe visitor, or the site’s default, grants itLoad or send.
falseRefused, or refused by an opt-out signalDo not load or send.
nullNobody has decided, or the name is unknownDo not send analytics or marketing signals.

The categories are essential, functional, preferences, analytics and marketing. Essential is always true.

if (window.CapellPrivacy?.allows('analytics') === true) {
sendPageView()
}

Treat null as refused for anything that tracks a visitor. Only true sends a signal.

The stable API is these four members, which every runtime provides:

MemberReturns
allows(name)true, false or null, as above.
consent()The visitor’s choice as { id, version, granted }, or null before they choose.
choose(categories)A promise of true once the granted categories are recorded, or false if they were not.
open()Nothing; it shows the consent manager’s choices, and does nothing without a consent manager.

Any other property you find on window.CapellPrivacy is internal to that runtime and can change without notice.

When a choice changes, the runtime dispatches capell:privacy-consent-changed on document with the new consent() value as detail. The default runtime keeps a choose() choice for the current page only: it stores nothing, so the next page starts from the site’s defaults.

Mark a script or frame with data-capell-consent and the runtime loads it once its purpose is granted:

<script
type="text/plain"
data-capell-consent="analytics"
data-type="module"
src="/analytics.js"
></script>
<iframe
data-capell-consent="youtube"
data-src="https://www.youtube-nocookie.com/embed/VIDEO"
title="Product tour"
></iframe>

The script keeps its attributes and nonce; data-type becomes its type. Content added later is activated when it dispatches capell:content-ready, and gated content is activated again after a choice. A frame loads only an http or https address. Until it loads, the runtime hides the empty frame and shows a short notice before it ([data-capell-consent-placeholder], role="note", in the page’s language); when a consent manager is installed the notice also carries a button that opens its choices panel.

Section titled “Defaults when no consent manager is installed”

The default runtime records nothing and sets no cookie. Configure it in config/capell.php:

'privacy' => [
'first_party_counter' => env('CAPELL_PRIVACY_FIRST_PARTY_COUNTER', true),
'consent' => [
'runtime' => env('CAPELL_PRIVACY_CONSENT_RUNTIME', true),
'defaults' => [
'functional' => 'undecided',
'preferences' => 'undecided',
'analytics' => 'undecided',
'marketing' => 'undecided',
],
'opt_out_signal_categories' => ['analytics', 'marketing'],
'purposes' => ['youtube' => 'marketing'],
],
],

Nobody has been asked, so every optional category starts undecided and its gated scripts and frames stay off. Set a category to granted only where the site does not need a visitor’s consent for it. Each default is granted, denied or undecided; anything else is undecided. A Global Privacy Control (Sec-GPC: 1, navigator.globalPrivacyControl) or Do Not Track (DNT: 1) signal refuses the opt-out categories whatever their default. Map each named purpose your package asks about to its category; an unmapped purpose is null.

A package declares the purposes it asks about in its capell.json, so a site needs no configuration for them:

"privacy": {
"purposes": { "youtube": "marketing" }
}

Each purpose maps to functional, preferences, analytics or marketing. The manifest validator refuses essential (a purpose that never asks), category names and malformed keys. Only enabled packages count. Where two packages map one purpose differently, the stricter category wins, and capell.privacy.consent.purposes overrides any package declaration.

A purpose’s category decides when it loads. A purpose mapped to functional loads without asking wherever the site sets capell.privacy.consent.defaults.functional to granted, so map an embed that sets cookies or shares visitor data with a third party to preferences, analytics or marketing. Override a package’s mapping in capell.privacy.consent.purposes if the site needs stricter handling.

Config keyEnvironment variableDefault
capell.privacy.first_party_counterCAPELL_PRIVACY_FIRST_PARTY_COUNTERtrue
capell.privacy.consent.runtimeCAPELL_PRIVACY_CONSENT_RUNTIMEtrue
capell.privacy.consent.defaults.functionalCAPELL_PRIVACY_CONSENT_FUNCTIONALundecided
capell.privacy.consent.defaults.preferencesCAPELL_PRIVACY_CONSENT_PREFERENCESundecided
capell.privacy.consent.defaults.analyticsCAPELL_PRIVACY_CONSENT_ANALYTICSundecided
capell.privacy.consent.defaults.marketingCAPELL_PRIVACY_CONSENT_MARKETINGundecided
capell.privacy.consent.opt_out_signal_categoriesNone['analytics', 'marketing']
capell.privacy.consent.purposesNone[]

Setting runtime to false removes the default runtime from every page; widgets then find no window.CapellPrivacy unless a consent manager defines it.

The counter records two things: an aggregate page-view count per page in five-minute buckets (each row is stamped with its bucket start, never the moment of a visit), and a daily visitor marker (a truncated HMAC of site, address and user agent that rotates each day). It sets no cookie. The marker is a pseudonymous visitor identifier, so it is recorded only when analytics is granted. The aggregate count holds no identifier, so capell.privacy.first_party_counter (on by default) lets it count while analytics is undecided.

Analytics decisionPage-view countVisitor marker
GrantedYesYes
UndecidedOnly with the first-party counterNo
Refused, Global Privacy Control or Do Not TrackNoNo
Unreadable: no runtime, or the provider failsNoNo

The browser and the collection endpoint each apply this table, so a forged beacon still gets no visitor marker without granted analytics. Both treat a Global Privacy Control or Do Not Track signal as a refusal even when a consent manager reports analytics as granted.

The default runtime is a same-origin script without a nonce, because cached HTML cannot carry a per-request one. A policy that allows 'self' scripts runs it. A nonce-only policy (for example script-src 'nonce-…' 'strict-dynamic') blocks it: window.CapellPrivacy is then undefined, gated scripts and frames stay off, and the page-view counter sends nothing because it cannot read consent. Add 'self', or a consent manager whose runtime your policy allows.

Resolve Capell\Core\Contracts\Privacy\ConsentDecisionProvider and call decide($purposeOrCategory, $request). It returns a ConsentDecision (Granted, Denied or Undecided); send a signal only for Granted.

The server decision reads the request, so use it only in responses that are never cached, such as a tracking endpoint. Public HTML is cached and shared between visitors: never vary page output on a consent decision. Let the browser runtime decide instead.

Queued work, such as a server-side analytics send, has no request to read. Store the visitor’s consent subject from Capell\Core\Contracts\Privacy\IdentifiesConsentSubject when you queue the work. Immediately before the work acts, resolve Capell\Core\Contracts\Privacy\ConsentDecisionLookup and call decisionFor($subject, $category, $siteId) with the site the work belongs to. Act only on Granted. Without a consent manager, Core’s lookup answers Undecided for every subject, so the work does nothing.

A consent manager that records decisions binds its own lookup. It answers from that site’s stored records and treats a decision made under an older version of that site’s consent policy as Undecided. A consent cookie can be shared by several sites on one host, so a decision recorded on one site never answers for another.

A consent manager binds its own ConsentDecisionProvider in its service provider and renders its own window.CapellPrivacy runtime at RenderHookLocation::HeadOpen with a priority below 5. The default runtime then sees the existing object and leaves it in place. Its provider and runtime should refuse the categories in capell.privacy.consent.opt_out_signal_categories under a Global Privacy Control or Do Not Track signal and treat an undecided category as not granted, as Core’s do.

The runtime fragment is cached with the page. Keep it free of request state: render the configuration as JSON in a <script type="application/json"> element and load the code from a same-origin, versioned script URL. The configuration element is data, which a Content Security Policy does not block. Set no consent cookie on a page response. A cookie the consent manager sets from its own endpoint must stay host-only unless the site configures a domain for it. Build that cookie with Symfony\Component\HttpFoundation\Cookie::create() and a null domain rather than cookie(): Laravel’s cookie jar substitutes config('session.domain') for a null domain, which shares the cookie with every subdomain.