Show visitors only the choices that apply to your site

List the categories your site uses in notice_banner_purposes_levels, and TermsFeed Free Cookie Consent hides the other optional categories, so visitors do not see switches for categories without scripts. The same option shortens the consent banner text to the purposes your site uses. Other options hide the close button of the Preferences Center and move the consent banner to the end of the page. Each change is one option in the configuration object you pass to cookieconsent.run().

How to show only the categories you use

Set notice_banner_purposes_levels to an array of the categories your tagged scripts use: strictly-necessary, functionality, tracking, or targeting. The IDs are the 4 values of data-cookie-consent, in lowercase. A site with analytics and nothing else lists strictly-necessary and tracking.

<script type="text/javascript" charset="UTF-8">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({
  "notice_banner_type": "headline",
  "consent_type": "express",
  "language": "en",
  "notice_banner_purposes_levels": ["strictly-necessary", "tracking"]
});
});
</script>

Listing categories changes what visitors see and which scripts run.

  • The Preferences Center shows a tab and a switch for each listed category. The "Strictly necessary cookies" tab always shows, listed or not, with its switch on and disabled.
  • The consent banner text names only the listed purposes, in the order you give. Leaving strictly-necessary out removes its purpose from the text.
  • The scripts of an optional category left out never run. Its tagged scripts stay blocked after a click on the "I agree" button, in implied consent, through page_load_consent_levels, and for a returning visitor whose cookie holds true for it.
  • scripts_specific_loaded never runs for a category left out. Your code in that callback never grants the consent signals of the category, and user_consent_saved reports the category as false.

Leave a category out only when no tagged script needs it. With debug on, each tagged script of a missing category prints a warning such as JavaScript script of the category "targeting" never runs: the category is not in notice_banner_purposes_levels.

The option accepts one category as a string, such as "tracking". Cookie Consent drops unknown entries, such as "analytics", with a console warning when debug is on, and a missing or empty list gives all 4 categories. Choose the right category for each script with The 4 Cookie Categories.

Adding a category later asks no one again. Visitors who answered before read false for the new category until they open the Preferences Center and accept it. Ask them again with Consent Storage and Duration.

How to hide the close button of the Preferences Center

Set preferences_center_close_button_hide to true to remove the close button from the head of the Preferences Center and turn off the Escape key. The visitor then leaves the Preferences Center only by clicking the "Save my preferences" button, and every save counts as an answer.

<script type="text/javascript" charset="UTF-8">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({
  "notice_banner_type": "headline",
  "consent_type": "express",
  "language": "en",
  "preferences_center_close_button_hide": true
});
});
</script>

A visitor who opens the Preferences Center by mistake, from the "Change my preferences" button or from your cookie settings link, has to save to get back to the page. That save stores the switches as shown. Before the first answer, the switches show on only for the categories that run on page load. Keep the close button on unless your design needs every visitor to pass through the switches.

Why the "I decline" button stays visible

In express consent, the "I decline" button stays on the consent banner because it lets visitors refuse with 1 click, as easily as they accept with the "I agree" button. Without it, a visitor who wants to refuse opens the Preferences Center, turns off any switch that shows on, and saves, which takes more clicks than accepting. In a January 2023 report of the European Data Protection Board (EDPB), most regulators in its taskforce consider a layer with an accept button and no refuse option an infringement.

Cookie Consent offers notice_banner_reject_button_hide, which removes the "I decline" button in express consent. Leave the option at false, the default. Implied consent never shows the "I decline" button. Read what "as easy" means for your consent banner in Reject All Button and Cookie Walls.

Set notice_banner_append to "beforeend" to insert the consent banner as the last element of <body> instead of the first, where the default "afterbegin" puts it. The value ignores case, and an unknown value gives the default.

<script type="text/javascript" charset="UTF-8">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({
  "notice_banner_type": "headline",
  "consent_type": "express",
  "language": "en",
  "notice_banner_append": "beforeend"
});
});
</script>

The headline bar sits in the page flow, so with "beforeend" it shows after your footer, where most visitors never scroll. Your optional tagged scripts outside page_load_consent_levels then wait for an answer that rarely comes. The simple, interstitial, and standalone layouts stay fixed on screen, so the position changes nothing visitors see with them.

Keyboard order changes too, for the headline and simple layouts. At the end of <body>, keyboard and screen reader users reach the consent banner buttons only after every link of the page. Compare the layouts with Cookie Banner Layouts.

How to check which categories and buttons show

The checks assume express consent with page_load_consent_levels left out or at the generator value ["strictly-necessary"]. A saved answer hides the consent banner, so the check needs a browser with no Cookie Consent cookies. The 5 steps take about 10 minutes.

  1. Add "debug": true to the configuration object and deploy it. Close every private window, open a new one, open Chrome DevTools, and load your site.
  2. Read the consent banner text, and confirm it names only the purposes your listed categories serve, with the "I decline" button next to the "I agree" button.
  3. Click the "Change my preferences" button, and confirm the Preferences Center shows a tab for each listed category, and no close button if you hid it.
  4. Select the Console tab, and confirm no warning reads never runs: the category is not in notice_banner_purposes_levels for a script you need.
  5. Select the Network tab and type the host of an optional tagged script in its filter box, such as googletagmanager.com for a tagged Google tag. Confirm no request to that host is listed. In the Preferences Center, select the category tab of that script and set its switch to Active. Click the "Save my preferences" button, and confirm a request to that host appears after the save. Remove "debug": true before you go live.