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

ba-js-cookie-banner

v3.2.3

Published

ba-js-cookie-banner is an embeddable React-based cookie consent manager. In addition to cookie management, it installs and manages Bookassist and Google analytics tracking by leveraging ba-js-tracker.

Downloads

713

Readme

ba-js-cookie-banner

ba-js-cookie-banner is an embeddable React-based cookie consent manager. In addition to cookie management, it installs and manages Bookassist and Google analytics tracking by leveraging ba-js-tracker.

Installation

# yarn
yarn add ba-js-cookie-banner

# unpkg
<script src="https://unpkg.com/ba-js-cookie-banner/dist/ba-js-cookie-banner.min.js"></script>

Documentation

The widget is auto-appended to the body as a div wrapper:

<body>
  <div id="cookie-bg-overlay">
    <div id="cookie-container">
      <!-- conditional banner content here -->
    </div>
  </div>
</body>

The banner content is displayed when the cookie-consent cookie is unset. The user can also display the banner manually by clicking on an element with a preset id value (#ba-edit-cookie) located anywhere on the page. This allows them to edit their cookie preferences.

The banner prompts the user to allow all cookies or select a subset of types they're willing to accept.

| Cookie Type | Value | Optional | | ----------- | ----- | -------- | | Necessary | 1 | No | | Preferences | 2 | Yes | | Statistics | 4 | Yes | | Marketing | 8 | Yes |

The allowed cookie type values are summed to provide the cookie-consent cookie value (e.g. a user permitting all cookie types would result in the value being set to 15).

Determining whether a given cookie type is permitted is done using a bitwise AND operation:

// are Statistics cookies permitted?
var cookieConsent = Cookies.get('cookie-consent')
if ((cookieConsent & 4) > 0) {
    // Statistics cookies are permitted
}

Script Loader

The cookie banner widget controls cookie setting indirectly by managing 3rd party script loading. On load the widget checks the current cookie-consent value, and if unset continues to listen for changes. Once the value is set the cookie banner:

  1. Loads jQuery dynamically if not already present on the page. jQuery is a dependency of the preconditions/callback script in part 3. The BA.jQueryUrl global provides the relevant jQuery url.
  2. Loads two JSON feeds:
    1. a list of 3rd party scripts to load
    2. script metadata: a classification by cookie type (according to the values from the above table), and any precondition (tests to pass prior to script load) and callback (run following script load) function metadata.
  3. Loads the inventory of precondition and callback functions.

Once the user has selected their cookie preferences, the banner dynamically loads any compliant 3rd party scripts, respecting any associated preconditions and executing any associated callbacks

Analytics

Bookassist Analytics

The cookie banner comes bundled with ba-js-tracker. ba-js-tracker contains an always-on gdpr-compliant in-house tracker (baTracker).

Google Analytics

Google Analytics is loaded conditionally as per Script Loader 3rd party scripts, except in this case the consent value is obtained from the BA.gaConsent global. Google Analytics can also be unconditionally loaded by setting the BA.gaWaitForConsent global to false. The Google Analytics tracker is instantiated with the values provided by the BA.gaAnonymiseIp, BA.gaId, and BA.gaLinker globals. On load it sends a pageview event.

Events

// these events are structured as per ba-js-tracker requirements

// pageview event (baTracker, gaTracker)
event: {
  type: 'pageView'
}

// script loading errors (baTracker)
event: {
  type: 'error',
  key: err.name,
  value: {
    message: err.message,
    stack: err.stack,
  }
}

// set/change cookie-consent value (baTracker)
event: {
  type: 'technical',
  key: 'cookieConsent',
  value,
}

// show cookie consent widget (baTracker)
event: {
  type: 'technical',
  key: 'showCookieConsentWidget',
}

// custom set cookie preferences (baTracker)
event: {
  type: 'userInteraction',
  key: 'preferences',
}

Global Variables

These values must be set before loading ba-js-cookie-banner

BA.cookiePolicyUrl // cookie banner privay policy url (string)
BA.gaAnonymiseIp // google analytics anonymizeip field (boolean)
BA.gaConsent // google analytics cookie-consent value (integer)
BA.gaId // google analytics account id (string)
BA.gaLinker // google analytics linker parameters (array)
BA.gaWaitForConsent // require user consent before loading google analytics (boolean)
BA.gdpr // gdpr policy applicable (pseudo-boolean - "yes/no")
BA.i18n // jed i18n data (json)
BA.jQueryUrl // jquery version to load (if not present) (string)
BA.showBanner // show banner (when warranted) (pseudo-boolean - "yes/no")
BA.thirdPartyScriptsClasificationUrl // 3rd party script classification mapping url (string)
BA.thirdPartyScriptsFunctionsUrl // 3rd party script preconditions and functions url (string)
BA.thirdPartyScriptsURL // 3rd party scripts to load
BA.userLanguage // i18n user language