Overview
The consent panel is a bottom Panel on every page. It has three views. The Notice view holds Accept, Reject and Manage. The Manage view holds one switch for each cookie category. The Done view confirms the choice. You add no markup: the script builds the panel when it is first needed. A trigger button with data-cookies-toggle opens it again at any time.
Pick another component when:
Markup
<!-- Nothing to add: the panel is built on every page -->
<!-- Optional: opens the panel again -->
<button type="button" class="nds-btn nds-secondary-outline" data-cookies-toggle>
<i class="nds-icon nds-hgi-cookie" aria-hidden="true"></i>
<span class="nds-label">Cookie settings</span>
</button>
Variants
Both structures end with an optional trigger button. The Manual template holds the panel that the script builds, with the English text.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Auto (default) | — | — | Add nothing. The script builds the panel on every page, with the text of the page’s language |
| Structure | Manual (hint: Your own text, links or categories) | canon #cookies-manual |
— | Your own text, links or categories. A #nds-cookies-panel in a <template class="nds-panel-template"> replaces the built one. Keep data-cookies-view, data-cookies-action and data-cookies-category |
Behavior
Auto-open
When no choice is stored, the panel opens on the Notice view after six seconds. It does not move focus, so a keyboard user keeps their place. If another panel is open, it waits until that panel closes. If the user opens a panel while the Notice shows, the Notice hides and comes back when that panel closes.
data-cookies-no-auto-open on <html> turns the auto-open off for that page, and the page then loads no panel script until a trigger is pressed. A trigger still opens the panel.
Views
Accept allows every category. Reject and Reject All allow only the necessary cookies. Manage opens the Manage view, where the switches show the stored choice. With no stored choice, every optional switch is off. After a choice, the Done view confirms it and closes itself after 5 seconds, with a countdown ring on the close button. Moving to it with the keyboard pauses the countdown, and a click in the panel keeps it open. Undo goes back to the Notice view, and the stored choice stays until the visitor makes a new one.
Close
The close button stores no choice. The panel then does not open by itself for 30 minutes. An outside click does not close the panel. When it closes, focus goes back to the trigger that opened it.
Built-in Features
-
Loaded on Demand
The panel script loads only for a visitor with no stored choice, or on the first trigger press. A returning visitor downloads none of it.
-
Localized Text
The built panel takes its text from the
cookiessection of the page language's pack, such asassets/i18n/ar.json. The text loads before the panel shows, so an Arabic page never shows English first. -
Consent Signals
Each choice sends
gtag('consent', 'update', …)for every mapped category, so Google tags react without a page reload. -
Denied Until Chosen
On every page load, NDS denies each category the visitor did not allow. A visitor who has not chosen yet counts as declined.
-
Tracker Cleanup
When a category is denied, NDS clears its common trackers on this host and every parent domain. Performance also disables each registered Google Analytics ID.
-
Consent Persistence
The choice is saved for 365 days with
SameSite=Lax. On afile://URL, it is saved in localStorage.
Best Practices
- Keep the “Cookie settings” trigger in the footer’s policy row: the Footer canon has it. Visitors expect to change their choice later.
- Set gtag’s consent default to
deniedin<head>, before gtag.js loads. NDS only sends signals and cannot block a tracker. Its scripts run later, so that default is what stops the first page view from tracking. - Register each Google Analytics ID with
window.GA_TRACKING_IDordata-ga-tracking-id, before the NDS scripts. Without it, a denial clears the cookies but Google Analytics keeps running. - Listen for
nds:cookies:consentto start or stop a tool that NDS does not know, such as a vendor pixel. - Do not add a second cookie banner. The consent panel is already on every page.
- On a page that nobody interacts with, such as a kiosk or a TV display, write
data-cookies-no-auto-openon<html>. With no choice stored, NDS counts every optional category as declined there. - To change the links or categories, use the Manual structure and edit the whole panel. Keep
data-cookies-view,data-cookies-actionanddata-cookies-category. - To change only the text, set
window.NDS_I18N.cookies. The built panel then keeps up with future releases.
API
Classes
| Class | Element | Effect |
|---|---|---|
nds-cookies-view |
a div in the panel |
One view of the panel: it holds that view’s header and body. The script shows one at a time |
nds-cookies |
.nds-panel |
Marks the consent panel. It has no style of its own |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-cookies-no-auto-open |
<html> |
The panel does not open by itself on this page. On when present; false, 0, no or off keeps it off. A trigger still opens it |
data-cookies-toggle |
any button outside the panel | Opens the panel. ="manage" opens it on the Manage view |
data-cookies-view |
.nds-cookies-view |
notice, manage or done. The script shows one view at a time |
data-cookies-action |
a button in the panel | accept, reject and save store the choice and show the Done view. manage shows the Manage view. undo goes back to the Notice view |
data-cookies-category |
a switch input in the Manage view | The category the switch allows. necessary is always allowed |
data-ga-tracking-id |
any element | A Google Analytics ID to disable while performance cookies are denied |
data-panel-static |
#nds-cookies-panel |
An outside click does not close the panel. Keep it on your own panel |
Text
The built panel reads its English from the script and its Arabic from the cookies section of assets/i18n/ar.json. To change some of it, set window.NDS_I18N.cookies before the NDS scripts: each key you set replaces that text, and the rest keep the pack’s text. A Manual panel ignores both. See Internationalization.
Consent Mode Mapping
| Category | gtag keys | Cookies cleared when denied |
|---|---|---|
necessary |
— (always allowed) | — |
performance |
analytics_storage |
Every name that starts with _ga, _gid or _gat (GA4’s _ga_<id> too), and window['ga-disable-<id>'] is set |
functional |
functionality_storage, personalization_storage |
— |
targeting |
ad_storage, ad_user_data, ad_personalization |
Every name that starts with _gcl, _fbp or _fbc |
A category that is not in this table reaches only isAllowed() and the event.
JavaScript
The NDS.Cookies script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.
| Method | Effect |
|---|---|
NDS.Cookies.open(view, opener) |
Opens the panel on 'notice' (default) or 'manage'. Focus goes back to opener when it closes |
NDS.Cookies.close() |
Closes the panel |
NDS.consent.get() |
'accepted', 'declined', 'custom' (some categories) or null (no choice yet) |
NDS.consent.isAllowed(category) |
true when the visitor allowed the category. 'necessary' is always true |
NDS.consent.set(choice) |
Stores true (all), false (none) or an array of categories, applies it and fires the event. Use it from your own consent UI |
NDS.cookie.set(name, value, days) |
Writes a cookie with path=/ and SameSite=Lax. It does not check consent, so use it for necessary values only |
NDS.cookie.get(name) |
Reads a cookie, or null |
NDS.cookie.delete(name) |
Removes a cookie on this host and every parent domain |
| Event | Fired on | Detail |
|---|---|---|
nds:cookies:consent |
document |
{ consent, categories }. consent is the NDS.consent.get() value. categories maps each category to true or false. Closing the panel is not a choice, so it fires no event |
The choice is stored in the nds-consent cookie as accepted, declined or the allowed categories joined with commas. The close button writes nds-cookies-dismissed for 30 minutes, which is never read as consent. To ask again, call NDS.cookie.delete('nds-consent'), then NDS.Cookies.open().
Put this script in <head>, before the gtag.js tag and the NDS scripts:
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
analytics_storage: 'denied',
functionality_storage: 'denied',
personalization_storage: 'denied',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
window.GA_TRACKING_ID = 'G-XXXXXXXXXX'; // or an array of ids
// Apply a stored choice now: gtag.js can send a hit before the NDS scripts run.
(function () {
var match = document.cookie.match(/(?:^|; )nds-consent=([^;]+)/);
var stored = match ? match[1] : '';
function state(category) {
return stored === 'accepted' || stored.split(',').indexOf(category) > -1 ? 'granted' : 'denied';
}
[].concat(window.GA_TRACKING_ID).forEach(function (id) {
window['ga-disable-' + id] = state('performance') === 'denied';
});
if (stored && stored !== 'declined') {
gtag('consent', 'update', {
analytics_storage: state('performance'),
functionality_storage: state('functional'),
personalization_storage: state('functional'),
ad_storage: state('targeting'),
ad_user_data: state('targeting'),
ad_personalization: state('targeting')
});
}
})();
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
Start a tool that NDS does not know only when its category is allowed. Put this in a defer script after the NDS scripts:
if (NDS.consent.isAllowed('performance')) startClarity();
document.addEventListener('nds:cookies:consent', function (e) {
if (e.detail.categories.performance) {
startClarity();
} else {
NDS.cookie.delete('_clck');
NDS.cookie.delete('_clsk');
}
});
The full API is in the banners of _js/nds-cookies.js (the panel), _js/nds-consent.js (the stored choice) and _js/nds-core.js (NDS.cookie).