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

vue-cookie-toggler

v0.2.2

Published

GDPR cookies consent modal.

Downloads

81

Readme

# vue-cookie-toggler

Vue 2 component for GDPR cookies consent.

  • Categorize the cookies in your application
  • Block all categorized cookies until the visitor agrees with the cookie policy
  • Allow the visitor to update his/her privacy options through a modal

Currently iframe and script tags are supported.

Image from Gyazo

# npm
npm i vue-cookie-toggler

#yarn
yarn add vue-cookie-toggler

Usage

Import the component like this:

import VueCookieToggler from 'vue-cookie-toggler';

Then you can use it in your app like this (see a complete example below):

<vue-cookie-toggler :cookies-groups="cookiesGroups" title="Cookie policy title">
    Cookie policy message
</vue-cookie-toggler>

cookiesGroups example:

[
  {
    category: 'essential',
    name: 'Essential website cookies',
    description:'Lorem ipsum dolor sit amet <a href="#">cookie policy</a>.',
    active: true,
    required: true,
  },
  {
    category: 'analytics',
    name: 'Analytics and customization',
    description:'Lorem ipsum dolor sit amet.',
    active: false,
  },
  {
    category: 'social_networking',
    name: 'Social networking',
    description:'Lorem ipsum dolor sit amet.',
    active: false,
  },
]

Then in your HTML the iframes and scripts tags should be written like this:

script tag examples:

Example 1:
<script type="text/plain" data-cookie data-category="analytics" src="/path/to/file"></script>

Example 2:
<script type="text/plain" data-cookie data-category="essential">
    // .. your awesome code here
</script>

iframe tag example:

<iframe
  data-cookie
  data-category="analytics"
  data-placeholder="true"
  alt="Please accept the cookie policy to see the content"
  data-src="/path/to/file"
></iframe>

Later, if you want to modify the cookie settings, you can add a link to trigger the cookie settings modal like this:

<a href="#" data-cookie-toggler"settings">Update cookie settings</a>

cookiesGroups options:

| Name | Type | Default value | Description | | | :------------- |:-------------:|:-------------: |:-------------|:-------------:| | category | string | | This will be used in data-category | required | | name | string | | The cookie title used in Cookie Settings |required | | description | string | | The cookie description used in Cookie Settings |required | | active | boolean | | Whether to set the cookie ON or OFF by default | required | | required | boolean | false | Disable the option to toggle cookie ON/OFF from the Cookie Settings |optional|

Example with all the options:

<vue-cookie-toggler
    :cookies-groups="cookiesGroups"
    title="Cookie policy title"
    settings-title="Cookie settings title"
    settings-label="Settings button label"
    accept-label="Accept button label"
    save-label="Save button label"
    cancel-label="Cancel button label"
>
    <!-- This content will show up the main view (1st view) -->
    Cookie policy message

    <!-- (optional) use '#settingsContent' slot if you what to add content in Cookie Settings view (2nd view) -->
    <template #settingsContent> Cookie settings message </template>

    <!-- (optional) use '#mainButtons' slot if you what to change the buttons in the main view (1st view) -->
    <template #mainButtons="{ accept, settings, save, cancel }">
      <button class="vct__btn vct__btn--default" @click="settings">
        Customize settings
      </button>
      <button class="vct__btn vct__btn--primary" @click="accept">
        Accept all cookies
      </button>
    </template>

    <!-- (optional) use '#settingsButtons' slot if you what to change the buttons in Cookie Settings view (2nd view) -->
    <template #settingsButtons="{ accept, save, save, cancel }">
      <button class="vct__btn vct__btn--default" @click="accept">
        Accept all cookies
      </button>
      <button class="vct__btn vct__btn--primary" @click="save">
        Save settings
      </button>
    </template>
</vue-cookie-toggler>

How it works

Becase we have defined the script tags with type="text/plain" and the iframes with data-src, the browser will not load them.

At first load the parsers will scan the DOM for data-cookie tagged elements and categorize them.

After the visitor accepts the cookie policy, the parsers will enable all script tags and iframes categorized in the previous step.

TODO:

  • [x] make the component more flexible (props & slots)
  • [ ] improve variables names
  • [ ] move CSS to an assets folder
  • [ ] create a parser for links
  • [ ] remove lodash dependency
  • [ ] vue-js-modal issue on mobile for when the modal is to heigh
  • [ ] add some examples
  • [ ] write proper documentation