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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@smg-automotive/cookie-consent-pkg

v1.3.58

Published

A boilerplate package setup

Downloads

1,340

Readme

cookie-consent-pkg

CircleCI semantic-release

Usage

npm install @smg-automotive/cookie-consent-pkg

Loading OneTrust banner

OneTrustCookieConsentBanner adds the required script tags to the document head and preloads the script so that it loads as early as possible. only loads a 3KB script. All subsequent scripts load async.

import { OneTrustCookieConsentBanner } from '@smg-automotive/cookie-consent-pkg';

// loads using JavaScript. You may gain more performance by adding it manually to the server HTML
<OneTrustCookieConsentBanner domainScript="yourScriptID" enabled={true} />;

Alternatively, if you are serving an HTML from the server, consider adding it manually inside the document head.

<script
    src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
    data-domain-script="yourScriptID"
    data-document-language="true"
/>

CookieConsentProvider

You should wrap your application with the CookieConsentProvider. It places listeners on the current cookie consent and enables you to react on changes (e.g. block certain third party scripts).

<CookieConsentProvider
  enabled={true}
  onConsentChanged={(newConsent) => console.log(newConsent)}
  onOneTrustLoaded={(initialConsent, hideBanner) => console.log(initialConsent)}
>
  <div>your app..</div>
</CookieConsentProvider>

onConsentChanged is optional and allows you to fire events when the user changed the consent in the preference center. onOneTrustLoaded is optional and is called after OneTrust has been loaded. hideBanner is true if the banner has been shown in a previous session.

CookieConsentContext

You can get the current consent and other properties related to cookie consent in your component using useCookieConsent hook.

import { useCookieConsent } from '@smg-automotive/cookie-consent-pkg';

const { consent, openPreferenceCenter, isLoaded, hasInteracted } =
  useCookieConsent;

| property | type | description | | -------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | consent | Category[] | Array of the current consent. If the user uses a script blocker or you disabled OneTrust in the Provider, only the stricly necessary category is set. | | openPreferenceCenter | Function | Opens the OneTrust preference center. | | isLoaded | boolean | True if OneTrust has been successfully loaded and invoked. | | hasInteracted | boolean | True if the user has interacted with the banner at some point. |

Development

npm run build

You can link your local npm package to integrate it with any local project:

cd cookie-consent-pkg
npm run build

cd <project directory>
npm link ../cookie-consent-pkg

Release a new version

New versions are released on the ci using semantic-release as soon as you merge into master. Please make sure your merge commit message adheres to the corresponding conventions and your branch name does not contain forward slashes /.