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 🙏

© 2025 – Pkg Stats / Ryan Hefner

google-cmp-addon

v0.0.2

Published

Adds the missing functionality for google consent purpose management

Readme

🏠 Homepage

About

If you use google adsense and the new google "Privacy & Message" CMP feature and need to add custom purposes - This is for you. This library adds the missing functionality to en- and disable custom services (Google maps, analytics, ...) according to the user selected purposes. It works just like any other CMP. Configure and match the purpose and let the library do the rest

NOTE: This library is still BETA and experimental since Google is changing the way their CMP works - Besides its still full of bugs!

Getting started

Javascript usage

To use the widget on your website, simply embed the js as well as a valid config.

```html
<!-- make sure the config gets after the libary code -->
<script defer type="text/javascript" src="/path/to/js"></script>
<script defer type="text/javascript" src="/path/to/config.js"></script>

The config file should be in the format:

window.gcmp.init({
  debug: true,
  reloadAfterUserAction: true,
  onLoad: function () {
  },
  onUi: function () {
  },
  purposes: [{
    purpose: 2,
    selectors: '[data-consent="affiliate-ad"]',
    cookies: [/^UI$/i, /^PI$/i, /^BT$/i]
  }, {
    purpose: 10,
    selectors: '[data-name="analytics"],[data-consent="analytics"]',
    cookies: [/^ga/i, /^_ga/i, /^_gid/i],
  }, {
    purpose: 7,
    selectors: '[data-name="externalmedia"],[data-consent="externalmedia"]',
  }, {
    purpose: 7,
    selectors: '[data-name="security"],[data-consent="security"]',
  }]
});

React usage

npm install google-cmp-addon
yarn install google-cmp-addon

Use with react provider

import React from 'react';
import {GcmpProvider} from "google-cmp-addon";

export const App = () => {
  const config = {
    // your config here - see above´s javascript usage
  }
  return (<GcmpProvider config={config}>
    Hello React
  </GcmpProvider>)
}

See all the options and configurations here. Please also consult the IAB official documentation: IAB And the google JavaScript API https://developers.google.com/funding-choices/fc-api-docs.

property | type | default | Description -----------------------|----------------------------|-------------|-------------------------------------------------------------------------------------------------------- debug | Boolean | false | Enable debug mode tcfVersion | Number | 2.2 | The TCF version to use waitForDom | Boolean | false | Waits for the DOM to be fully loaded to run initWithGoogle | Boolean | true | Run when goggle has issued ready event (default) root | Document | Element; | Document | Define the root element from where to look for placeholders purposes | Purposes[] | [] | Requires the purpose object (see below) embedOptions | EmbedOptions | undefined | Optional options for embedded objects elementOptions | ElementOptions | undefined | Optional options for elements reloadAfterUserAction | boolean | false | Hard reload after user has confirmed purpose choices in google UI onInit | (app: App) => void | undefined | Fires when the google CONSENT_DATA_READY and IAB window.__tcfapi.addEventListener() has been fired onLoad | (app: App) => void | undefined | Fires when the google CONSENT_DATA_READY and IAB window.__tcfapi.addEventListener() has been fired onUi | (app: App) => void | undefined | Fires when the google UI is mounted in the parent DOM onAdStatus | (status: number) => void | undefined | Fires when the google AD_BLOCK_DATA_READY has fired

The purpose object has the following configurations:

property | type | default | Description ----------------|------------------------------------------------------------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------- purpose | Number | | Expects the a number between 1-11 - according to the google IAB purposes mode | "hide" | "remove" | "disable" | undefined | The mode to use on elements where "hide" hides the element, "remove" removes it from DOM and "disable" tries to disable it tags | String[] | undefined | A list of allowed html tag names selectors | String | | Expects the HTML selectors to target cookies | RegExp[] | undefined | Array of regexp expression for cookie names to remove localStorage | RegExp[] | undefined | Array of regexp expression to remove entries from local storage sessionStorage | RegExp[] | undefined | Array of regexp expression to remove entries from session storage onRender | onRender?: (consent: boolean, nodes: NodeListOf,app: App,) => void | false | undefined | Hook in custom render function for this purpose


<script type="text/plain"
        data-type="text/javascript"
        data-consent="optimizely"
        data-src="https://cdn.optimizely.com/js/10196010078.js">
</script>

The same method also works for images, stylesheets and other elements with a src or type attribute.

Configure

Install

yarn install

Usage

yarn run dev

Run tests

yarn run test

Author

👤 Frank Mueller [email protected]

  • Website: http://set.cooki.me
  • Github: @setcooki

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2024 Frank Mueller [email protected]. This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator