window.KatlaConsent for programmatic access to consent state.
Prerequisites
- The consent widget script installed on your page
Reading consent state
hasConsent() is true for a rejection - a refusal is a choice, and it is on file.
hasGrantedConsent() asks the different question of whether anything was actually allowed,
which is what tells “nothing to withdraw” apart from “nothing chosen yet”.
getConsentRecord() returns the visitor’s receipt: the server-side record id and the moment
the choice was made, in epoch milliseconds. The preference centre shows it in its status
strip, and you can show the same thing in your own UI. Either field can be null - the id
until the tracking call returns one, and the timestamp on installs whose cookie was written
before Katla stored it.
Checking specific cookies or categories
Setting consent programmatically
acceptAll() from your own
control closes the banner and shows the settings button, exactly as pressing Accept All in
the banner does, and the same holds for rejectAll(), acceptCategories() and
optOutOfSale().
rejectAll() records a choice; withdrawConsent() takes one back. They end in the same
state - required categories only, every other cookie removed, the refusal stored against the
existing consent id - and that is deliberate. Withdrawing used to delete the _katla_consent
cookie, which meant the visitor who withdrew was re-prompted on every page load afterwards
while the one who pressed Reject was not: the same intent, and the more deliberate act got
nagged for it. Under CCPA it defers to optOutOfSale(), because there an absent cookie means
allowed and erasing it would undo the refusal.
Opening the preference center
window.katla is a small façade installed by the widget script, separate from
KatlaConsent: that one reads and writes the decision, this one shows the screen for making
it. Wire it to your own control - a footer link is the usual place:
window.katla does not exist for the first few hundred
milliseconds of a page. Guard the call if your control is in the server-rendered HTML:
Listening for changes
subscribe() hears every change, whether it came from the banner, the preference center or
this API, and any number of listeners can be registered. It was added in guard script version
2 (KatlaConsent.version).
onConsentChange still works, but it is a single slot: assigning it replaces whatever was
there, including a handler set by another integration.
Google Consent Mode
If you use Google Analytics or Google Ads and want to signal consent state via Google Consent Mode v2, usesetupGoogleConsentMode() from the SDK:
denied for all Google parameters, then automatically updates them when the visitor makes a consent choice. See the Google Consent Mode guide for full details.