npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@barnardos/customisable-consent-banner

v0.3.3

Published

Customisable version of Barnardo's consent banner.

Readme

Barnardo's consent banner

Usage

Option 1: npm install / yarn add

Run npm install @barnardoswebteam/customisable-consent-banner or yarn add @barnardoswebteam/customisable-consent-banner.

For the standard consent banner, in your code add the following:

const consentBanner = require("@barnardoswebteam/consent-banner");
consentBanner();

And add the GTM container ID in .env or as a config variable as GTM_CODE.

You can customise the standard consent banner by passing options, either in .env in block-caps snake case, or as camelCase config variables in an options hash.

  • PRIVACY_URL: URL for your privacy policy. Defaults to https://www.barnardos.org.uk/privacy-notice.
  • COOKIE_URL: URL for your cookie policy. Defaults to https://www.barnardos.org.uk/cookie-notice.
  • BANNER_HEADING: Heading text for the consent banner. Defaults to "Cookie tracking preferences".
  • BANNER_CONTENT: Custom text content (but not buttons)
  • CLOSE_BUTTON_CONTENT: Custom text or an svg for the close button. Defaults to "✕".
  • ADDITIONAL_SCRIPTS: An array of additional tracking scripts to be ran when the consent banner is accepted. If you have other scripts to use instead, GTM_CODE is optional and omitting it will prevent the banner attempting to load GTM scripts. Scripts are described by JSON objects with the properties name (arbitrary, for your reference), script (a function to execute), and args (an array of arguments to pass when the script is accepted). Defaults to none.
  • RESTRICT_DOMAIN: defaults to '.barnardos.org.uk' but you can use this to set another domain, or if set to the string * it will allow the banner to be shown on any domain.
  • RELOAD_ON_ACCEPT: set this to true to set the cookie and then reload the page if you have scripts which cannot be provided above for architectural reasons, and which have loaded with defaults that cannot be easily toggled at run time. Defaults to false.
  • STYLE_CONTENT: Custom styles for the consent banner. Defaults to those outlined in consent-banner.template.css in the package. You can copy this template to help you customise the styles.
  • USE_EXTERNAL_STYLESHEET: use this instead of STYLE_CONTENT to link to an external stylesheet provied by your application. You can copy the template above to your own stylesheet to help you customise the styles.
  • BUTTON_ELEMENT: If you are using your own stylesheet you may prefer to use a different element for the accept/reject buttons. Defaults to "button".
  • BUTTON_CONTENT: Use this to add HTML content such as an SVG icon after the Accept/Reject button text. Defaults to none.
  • BUTTON_CLASS: If you are using your own stylesheet you may prefer your own class name for the button styling. Defaults to "_barnardos-consent-banner__button".
  • CLOSE_BUTTON_ELEMENT: If you are using your own stylesheet you may prefer to use a different element for the close button. Defaults to "button".
  • CLOSE_BUTTON_CLASS: If you are using your own stylesheet you may prefer your own class name for the close button styling. Defaults to "_barnardos-cookie-close".

If you have extensively customised the styles and the banner content, you can reduce the size of your JavaScript by bypassing the ConsentBanner wrapper (barnardosConsent if using es5) and calling ConsentBanner.Custom (or barnardosCustomConsent if using es5) directly to avoid loading the redundant default styles and content.

Option 2: ESM

For the standard consent banner, in your HTML add the following:

<script type="module" src="main.js"></script>

and in main.js:

import consentBanner from "./path/to/consent-banner.esm.js";
consentBanner();

And add the GTM container ID in .env or as a config variable as GTM_CODE.

You can customise the standard consent banner by passing options, either in .env in block-caps snake case, or as camelCase config variables in an options hash. See Option 1 above for option syntax.

Option 3: script element in HTML

For the standard consent banner, put the following near the end of the body element, replacing GTM-XXXXXX with the correct ID.

<script src="path/to/consent-banner.es5.js"></script>
<script>
  BarnardosConsent({ gtmCode: "GTM-XXXXXX" });
</script>

Self hosting is recommended ~~but if it's not possible you can use:~~

~~```html


You can customise the standard consent banner by passing camelCase config variables in an options hash. See Option 1 above for option syntax. For example:

```html
<script>
BarnardosConsent(
  {
    'gtmCode': 'GTM-XXXXXX',
    'privacyURL': 'https://your-domain/privacy-policy',
    'cookieURL': 'https://your-domain/cookie-policy',
    'bannerHeading': 'Your custom heading',
    'useExternalStylesheet': true
  }
);
</script>

Updating

Cloning this repo as a git submodule is recommended if not using NPM or Yarn. Watch this repository and run git pull from inside the submodule directory when there are changes. Otherwise watch this repository and perform manual updates.

Steps for creating a git submodule:

  1. cd to the directory the submodule will live.
  2. Type git submodule add -b main [email protected]:barnardos/consent-banner.git and press enter to add the submodule.
  3. Type git submodule init and press enter.
  4. cd out of the submodule into the parent repository.
  5. Add and commit the new files to the parent repository.

Safari and Firefox

Safari and Firefox now both delete scripted storage fairly quickly. In Safari's case it can be 24 hours. Therefore the consent banner is shown on repeat visits, which is making the banner even more annoying than it already is.

Therefore it's recommended re-setting the appropriate cookies with the server-side language of your choice, with a 1 year expiration. This has been cleared by the Barnardo's Head of Information Governance and Data Protection Officer.