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

klaro-gridsome

v1.0.3

Published

Wrapper for Klaro! cookie consent manager for easy use in Gridsome projects

Downloads

467

Readme

klaro-gridsome

Wrapper for Klaro! cookie consent manager for easy use in Gridsome projects.

Install

npm install klaro-gridsome

Usage

Include in plugins in gridsome.config.js

module.exports = {
  plugins: [
    {
      use: 'klaro-gridsome',
      options: {
        // your klaro configuration here
      }
    }
  ]
}

Populates klaroConfig and accepts the same configuration. See klaro's config.js for a sample configuration.

Example

module.exports = {
  plugins: [
    {
      use: 'klaro-gridsome',
      options: {
        privacyPolicy: '/privacy-policy/',
        cookieName: 'consent',
        translations: {
          en: {
            consentModal: {
              description: 'Here you can see and customize the information that we collect about you.',
            },
            googleAnalytics: {
              description: 'Website analytics powered by Google Analytics, allowing us to see how visitors use our website.'
            },
            purposes: {
              analytics: 'Analytics'
            },
          },
        },
        apps: [
          {
            name: 'googleAnalytics',
            default: true,
            title: 'Google Analytics',
            purposes: ['analytics'],
            cookies: [
              '_ga',
              '_gcl_au',
              '_gid',
              '_gat'
            ],
            required: false,
            optOut: true,
            onlyOnce: false
          }
        ]
      }
    }
  ]
}

Reading Consent

Klaro normally handles opting in/out of tracking by relying upon new page loads and by replacing the type of script elements. With a framework like Vue, this has to be handled manually.

Whenever consent is changed the consentUpdate event is fired on the document with the update. You can use this to listen to a change and respond accordingly. The event.detail object will include the app name changed, and a boolean consent property showing the current opt-in/opt-out value.

Example

export default {
  mounted() {
    document.addEventListener('consentUpdate', this.consentToggle)
  },
  beforeDestroy() {
    document.removeEventListener('consentUpdate', this.consentToggle)
  },
  methods: {
    consentToggle(event) {
      // only is app is google analytics
      if (event.detail.app === 'googleAnalytics') {
        if (event.detail.consent) {
          // if user consent is true
          this.$ga.enable()
        } else {
          // if user consent is false
          this.$ga.disable()
        }
      }
    }
  }
}

Reading consent on first load

As the consentUpdate event is only fired on a change, you will need to make sure you check Klaro consent before enabling any tracking. This can be done with window.klaro.getManager().consents, which includes the current state of all consents.

Example

Vue.use(VueAnalytics, {
  disabled: () => {
    return !window.klaro.getManager().consents.googleAnalytics
  }
})

Version History

  • v1.0.3 - Reverted process.isClient check, still seems to be required in certain cases
  • v1.0.1 - Removed redundant process.isClient check
  • v1.0.0 - Initial public release, based on Klaro v0.3.2

Credits

License

Klaro copyright and License in klaro/LICENSE.

Copyright © 2020 Alistair Shepherd. Licensed under the MPL-2.0 License.