Reading the consent
The banner's window.Avacy.getConsent() function returns the visitor's choice in three views of the same data.
The v2 banner does not provide window.Avacy.getConsent(). See JavaScript events (v2). If you don't know which banner your site uses, read Which banner your site is using.
Prerequisites
Before you start, check that:
- the banner is installed on the page. See HTML snippet;
- your code runs after the banner has loaded. To find out when, see Banner events.
What getConsent returns
window.Avacy.getConsent(): Consent | null
The function returns null until the banner has finished starting up. After startup it returns an object in one of these three states.
| State | When |
|---|---|
{ ready: false } | The banner has started and has not yet read the saved consent. |
{ ready: true, valid: false } | The banner has read the consent and the visitor has no usable one. |
{ ready: true, valid: true, type, timestamp, choices } | The visitor has a saved, valid consent. |
The valid state also contains these fields.
| Field | Content |
|---|---|
type | Type of saved choice: 'AcceptAll', 'RejectAll' or 'Personalized'. |
timestamp | Time of the choice, in milliseconds since 1970. |
consentId | Identifier of the consent in the consent archive. It appears only when the banner's consent archiving is on, after the archive has recorded the choice. To turn it on, see Consent archive (in Italian). |
The three views
| View | Fields | When to use it |
|---|---|---|
| Macro | type, timestamp | Find out whether the visitor accepted everything, rejected everything or chose manually. |
| Map | purposes, specialFeatures, vendors | Decide on a specific purpose or vendor. |
| List | choices | Go through all the choices. |
The purposes, specialFeatures, vendors and choices fields are always present. In the states without consent they are {}, {}, {} and [].
Map view
Each map has the shape map[framework][id] = true | false. The framework is tcf, gcm, acm or custom. A framework that is not configured has no key.
The content of the three maps:
purposescontains the purposes and the purposes of custom vendors;specialFeaturescontains the TCF special features. They have the same ids 1 and 2 as purposes 1 and 2, so they live in a separate map;vendorscontains the vendors. The id of TCF vendors is a number. The id of custom vendors is a string, for example'd116'. The dashboard shows the id in the ID column of the vendor list.
Map keys are strings: purposes.tcf[1] and purposes.tcf['1'] give the same result.
Google Consent Mode purposes have these ids.
| Id | Google permission |
|---|---|
| 1 | ad_storage |
| 2 | ad_user_data |
| 3 | ad_personalization |
| 4 | analytics_storage |
| 5 | functionality_storage |
| 6 | personalization_storage |
| 7 | security_storage |
List view
Each item in choices has this shape.
{ framework: 'tcf' | 'gcm' | 'acm' | 'custom', type: string, id: number | string, hasConsent?: boolean, hasLegitimateInterest?: boolean }
The list also contains information-only items, for example the TCF special purposes (type: 'specialPurpose'). The visitor cannot choose them, so don't use them to decide whether to start a script.
Missing, expired or rejected consent
The valid: false state means the visitor has no usable consent, not that they rejected. The banner returns it in these cases:
- the visitor has not chosen yet;
- the saved consent has expired;
- the saved consent belongs to a previous version of the policy;
- the banner cannot read the saved value.
A visitor who rejects everything has a valid consent: valid: true, type: 'RejectAll' and all maps set to false.
With valid: false, don't start the scripts that require consent and don't treat the case as a rejection.
Examples
The examples work when pasted into the browser console, with the banner loaded.
Reading the consent and telling the cases apart
function describeConsent() {
var consent = window.Avacy.getConsent();
if (!consent) return 'banner not started yet';
if (!consent.ready) return 'consent not read yet';
if (!consent.valid) return 'no valid consent (missing, expired or to be renewed)';
return 'saved choice: ' + consent.type + ', ' + new Date(consent.timestamp).toISOString();
}
console.log(describeConsent());
Deciding on a purpose or a vendor
function hasMarketingConsent() {
var consent = window.Avacy.getConsent();
if (!consent || !consent.ready || !consent.valid) return false;
// Google Consent Mode, purpose 1 (ad_storage)
var googleConsent = !!(consent.purposes.gcm && consent.purposes.gcm[1]);
// TCF, purpose 1 and vendor 52
var tcfConsent = !!(
consent.purposes.tcf && consent.purposes.tcf[1] &&
consent.vendors.tcf && consent.vendors.tcf[52]
);
return googleConsent || tcfConsent;
}
console.log(hasMarketingConsent());
The numbers 1 and 52 are placeholders. Replace them with the ids of your web space. TCF vendor ids are those of the IAB Europe Global Vendor List. The dashboard shows them in the ID column of the vendor list. Google Consent Mode ids are in the table above.
Going through all the choices
function listChoices() {
var consent = window.Avacy.getConsent();
if (!consent || !consent.ready || !consent.valid) return [];
return consent.choices.map(function (choice) {
return choice.framework + ':' + choice.type + ':' + choice.id + ' = ' + choice.hasConsent;
});
}
console.log(listChoices());
Check
- Open a page with the banner without choosing.
window.Avacy.getConsent()returnsready: trueandvalid: false. - Click Reject all, if the banner configuration shows it.
getConsent()returnsvalid: trueandtype: 'RejectAll'. - Reload the page. The response stays the same, because the banner reads the saved consent again.
Common problems
The most frequent problems:
getConsent()returnsnull: the banner has not finished starting up. Wait for theavacy:readyevent. Ifwindow.Avacydoes not exist, the snippet is missing from the page or the bundle has not loaded yet;getConsent()returnsready: false: the banner has not loaded the saved consent yet. Use theavacy:consent-loadedevent;- A purpose or a vendor is
undefined: the framework or the id is not in the banner configuration. Check withObject.keys(consent.purposes); - A TCF special feature does not appear in
purposes: special features live inspecialFeatures; consentIdis missing even with archiving on: the archive accepts only choices that come from the web space's domains. Locally, or on a test domain that is not among the web space's domains, the choice is not archived.
Last updated: 27/10/2026.