Consent Actions
Metodi per scrivere il consenso (programmaticamente, oppure come reazione a UI custom esterne al banner).
| Method | Tier | Since |
|---|---|---|
acceptAll(options?) | 1 | 3.0 |
rejectAll(options?) | 1 | 3.0 |
updateConsent(patches) | 1 | 3.0 |
triggerConsent(payload) | 1 | 3.0 |
Per leggere il consenso vedi Consent query. Per cambiare lingua durante una sessione vedi
changeLanguage.
Tutte le chiamate via window.Avacy.* stampano screen: 'api' nel payload audit del core (vedi ConsentScreen sotto). Il banner UI e il CPC restano 'first' / 'second'.
acceptAll
Zucchero per accettare tutti i purposes e vendors di tutti i framework configurati. Equivalente a triggerConsent({ type: 'AcceptAll', screen: 'api' }).
Accetta opzionalmente except per escludere selettivamente alcuni elementi (utile per casi tipo "accetta tutto tranne questo vendor", senza dover costruire un Personalized da zero).
window.Avacy.acceptAll(options?: { except?: PrivacySelector[] }): Promise<void>
type PrivacySelector = `${'tcf' | 'gcm' | 'custom' | 'acm'}:${'purpose' | 'vendor' | 'specialFeature' | 'customPurpose'}:${number}`;
Parameters
| Name | Type | Description |
|---|---|---|
options.except | PrivacySelector[] (opzionale) | Lista di selettori framework:type:id da escludere dall'accept. Se omesso o vuoto, equivalente a chiamata senza argomenti. |
Returns
Promise<void> — risolta quando il consenso è scritto nello store e i framework hanno propagato (TCString aggiornato, __tcfapi ping consentente, Google CMode default→update, etc.).
Examples
<button onclick="window.Avacy.acceptAll()">Accetta tutto</button>
// Accetta tutto tranne TCF vendor 79 (Meta) e GCM purpose 4:
await window.Avacy.acceptAll({
except: ['tcf:vendor:79', 'gcm:purpose:4'],
});
// Identità: except vuoto = nessuna eccezione
await window.Avacy.acceptAll({ except: [] });
await window.Avacy.acceptAll();
Side effects
- Senza
except(o conexcept: []): emetteavacy:consent-saved { type: 'AcceptAll', timestamp }. - Con
exceptnon vuoto: emetteavacy:consent-saved { type: 'Personalized', timestamp }— il consenso prodotto non è un AcceptAll vero, quindi il tipo riflette la realtà.
rejectAll
Speculare a acceptAll. Rifiuta tutti i purposes e vendors di tutti i framework configurati, con opzionale except per consentire selettivamente.
window.Avacy.rejectAll(options?: { except?: PrivacySelector[] }): Promise<void>
Examples
<button onclick="window.Avacy.rejectAll()">Rifiuta tutto</button>
// Rifiuta tutto tranne TCF purpose 1 (cookie tecnici):
await window.Avacy.rejectAll({
except: ['tcf:purpose:1'],
});
Side effects
- Senza
except: emetteavacy:consent-saved { type: 'RejectAll', timestamp }. - Con
exceptnon vuoto: emetteavacy:consent-saved { type: 'Personalized', timestamp }.
Comportamento legitimate interest: il default (
objectLegIntOnReject: true) cancella i LI su purposes/vendors quando si rifiuta. Per preservarli vedi config TCF/Custom frameworkobjectLegIntOnReject: false. Lo stesso comportamento si applica agli elementi non inexceptquando si usarejectAll({ except }).
updateConsent
Patch puntuale del consenso corrente: flippa solo i selettori elencati, gli altri restano allo stato corrente. Risolve sempre in un consenso Personalized.
window.Avacy.updateConsent(patches: ConsentPatches): Promise<void>
type ConsentPatches = Partial<Record<PrivacySelector, boolean>>;
Parameters
| Name | Type | Description |
|---|---|---|
patches | Record<PrivacySelector, boolean> | Mappa framework:type:id → next hasConsent. Stessa sintassi del campo except di acceptAll / rejectAll. Selettori malformati vengono droppati silenziosamente. Patch vuota è un no-op (nessun consent write dispatcato). |
Examples
// Toggle puntuale di 1-2 selettori senza modificare il resto del consenso corrente.
await window.Avacy.updateConsent({
'tcf:vendor:32': true,
'tcf:purpose:1': false,
});
// Caso d'uso: UI custom con switch per singolo vendor.
toggleEl.addEventListener('change', (e) => {
window.Avacy.updateConsent({
[`tcf:vendor:${vendorId}`]: e.target.checked,
});
});
// Patch vuota = no-op (nessun consent write, nessun avacy:consent-saved).
await window.Avacy.updateConsent({});
Side effects
Emette avacy:consent-saved { type: 'Personalized', timestamp } quando almeno un selettore valido è presente nei patches.
Garanzia di preservazione: il payload viene costruito a partire da
consent.choicescorrente. Per i framework che ricostruiscono le choices a partire dal templatecustomization.privacySettings(es. TCF), i selettori che non sono nel template potrebbero non essere preservati a runtime — è un comportamento del core TCF adapter, tracciato fuori da questa preview. Per i casi di test l'asserzione minimale è "il selettore patchato è applicato + consent.type passa a Personalized".
See also
acceptAll({ except })/rejectAll({ except })— sugar per "tutto sì/no tranne X"triggerConsent— passaggio raw del payload completo
triggerConsent
API raw per scrivere un payload di consenso arbitrario. Espone tutti i tipi disponibili e permette consensi custom (Personalized, CloseBanner).
window.Avacy.triggerConsent(payload: OnConsentPayload): Promise<void>
Parameters
| Name | Type | Description |
|---|---|---|
payload | OnConsentPayload | Payload tipizzato. Forma dipende dal type (AcceptAll, RejectAll, Personalized, CloseBanner). |
Payload variants
Il type agisce da discriminator. Le shape:
type ConsentScreen = 'first' | 'second' | 'api';
type OnConsentPayload =
| { type: 'AcceptAll'; screen: ConsentScreen }
| { type: 'RejectAll'; screen: ConsentScreen }
| { type: 'CloseBanner'; screen: ConsentScreen }
| { type: 'Personalized'; screen: ConsentScreen; privacyChoices: PrivacyChoice[] };
PrivacyChoice — vedi Tier 2.
Example: AcceptAll
await window.Avacy.triggerConsent({ type: 'AcceptAll', screen: 'api' });
Example: Personalized
await window.Avacy.triggerConsent({
type: 'Personalized',
screen: 'api',
privacyChoices: [
{ framework: 'tcf', type: 'purpose', id: 1, hasConsent: true, hasLegitimateInterest: false },
{ framework: 'tcf', type: 'purpose', id: 2, hasConsent: false, hasLegitimateInterest: true },
{ framework: 'tcf', type: 'vendor', id: 755, hasConsent: true, hasLegitimateInterest: false },
],
});
Example: CloseBanner
// utente chiude il banner senza scegliere — funzionalmente equivalente a RejectAll,
// ma distinto a livello di analytics/reporting
await window.Avacy.triggerConsent({ type: 'CloseBanner', screen: 'api' });
Side effects
Emette avacy:consent-saved { type, timestamp } (con type = quello passato nel payload).
ConsentScreen
Audit field stampato su ogni consent write, drive consentScreen nel TCString:
| Valore | Significato | TCString consentScreen |
|---|---|---|
'first' | Banner UI / first layer | '1' |
'second' | Preference Center / second layer | '2' |
'api' | Programmatic via window.Avacy.* | '2' (mappato a second nel TCF adapter) |
Banner e CPC components passano direttamente 'first' / 'second' al core. Tutta la public surface window.Avacy.* (incluso acceptAll, rejectAll, updateConsent, triggerConsent) stampa 'api' di default — l'integratore che chiama triggerConsent può comunque passare qualunque dei tre valori.
See also
acceptAll,rejectAll,updateConsent— sugar per i casi più comuniOnConsentPayload— shape completa dei payloadPrivacyChoice— elemento dell'arrayprivacyChoicesinPersonalized