0.2.3 β€’ Published 3 years ago

vue-cookiefy v0.2.3

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

:warning: Note This project is in status: work in progress

:warning: Note This documentation is in the making

Cookiefy for Vue

A minimal Cookie Managenent UI for Vue.js

Navigation

Features

  • 🎨 Cookie banner overlay UI
  • 🎨 Information overlay UI
  • πŸ‘¨β€βš–οΈ GDPR compliant:
    • βœ… Opt-in
    • βœ… Easy to deny
  • 🧠 Cookiefy remembers if it has been accepted and won't popup every reload
    • βœ… Sets a COOKIEFY_SEEN Cookie to true
    • βœ… Is an essential Cookie and is also GDPR compliant
  • 🎨 Customizable fields for cookies & privacy
  • 🎨 Customizable color
  • ✨ You let Cookiefy handle the UI - you just handle the results

Vuex

Cookiefy uses Vuex Store to handle state. Vuex has to be installed or Cookiefy wont work. For Vue.js you can use the Vue CLI to add Vuex with one command:

vue add vuex

Installation

npm install vue-cookiefy

Usage

Vue.js

First go to your main.js file and register Cookiefy

// main.js
import Vue from 'vue'
import Cookiefy from 'vue-cookiefy'

Vue.use(Cookiefy)

Then you can add Cookiefy in any of your components

// YourComponent.vue
<template>
  <div>
    <Cookiefy 
      v-model="cookiefy" 
    />
  </div>
</template>
<script>

export default {
  name: 'YourComponent',
  
  data() {
    return {
      cookiefy: true,
    }
  },
}
</script>

Nuxt.js

For Nuxt.js we will create a simple plugin to inject the Cookiefy component into your app. First create a file named cookiefy.js in your @/plugins folder.

// @/plugins/cookiefy.js
import Vue from 'vue'
import Cookiefy from 'vue-cookiefy'

Vue.use(Cookiefy)

Then register the plugin in your Nuxt.js configuration file nuxt.config.js

// nuxt.config.js 
export default {
  // ...
  plugins: [
    '@/plugins/cookiefy.js'
  ],
  // ...
}

Now you can use <Cookiefy /> in any of your components.

Props

PropTypeDefaultDescription
cookieFieldArray[]Containing the fields to select showed in the cookie overlay
privacyDataArray[]Contains the title and fields showed in the privacy overlay
innerTextStringPlaceholderSet the user information about the cookie usage on your app
colorString#ff3d17Primary color of the elements
langObjectEnglishLanguage of elements - see here

Custom fields

You can easily define your cookies and privacy text as fields using the cookieFields & privacyFields props.

// YourComponent.vue
<template>
  <div>
    <Cookiefy 
      v-model="cookiefy"
      :cookieFields="cookieFields"
      :privacyFields="privacyFields"
    />
  </div>
</template>
<script>
  export default {
    name: 'YourComponent',
    
    data() {
      return {
        cookiefy: true,
        cookieFields: [
          {
            text: 'Essential Cookies',
            checked: true,
            readonly: true,
          },
          {
            text: 'Google Analytics',
            checked: true,
            readonly: true,
          },
        ],
        privacyFields: [
          {
            title: 'Essential Cookies',
            text:
              'Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio id sed quas corporis...',
          },
          {
            title: 'Google Analytics',
            text:
              'Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio id sed quas corporis...',
          },
        ],
      }
    },
  }
</script>

Events

EventDescriptionReturn
@acceptOn user clicks acceptReturns an Array which contains all fields and results of the user selection
<template>
  <div>
    <Cookiefy 
      // ...
      @accept="onAccept" 
    />
  </div>
</template>

<script>
  export default {
    name: 'YourComponent',

    // ...
    
    methods: {
      // this method is called when the user accepts 
      onAccept(fields) {
        // handle response here
      }
    },
  }
</script>

Response Structure

The @accept event returns all defined fields as an Array.

// The returned Array of fields is structured like this
[
  {
    text: 'Essential Cookies', 
    checked: true,
  },
  {
    text: 'Google Analytics', 
    checked: true
  },
  // ...
]

Now after you got the user response you can set your Cookies safely.

Custom Language

You can easily change the language/text of the elements by using the lang prop.

<template>
  <div>
    <Cookiefy 
      // ...
      :lang="lang"
    />
  </div>
</template>

<script>
  export default {
    name: 'YourComponent',
    
    data() {
      return {
        // ...
        lang: {
          acceptAll: 'Alle akzeptieren',
          asSelected: 'Wie Auswahl',
          info: 'Mehr',
          close: 'Schließen',
          infoTitle: 'Informationen',
        },
      },
    }
</script>

The prop lang has following changable fields: | Field | Type | Description | Default | | :------------- | :----- | :----------- | :------------ | | acceptAll | String | Button text | "Accept all" | | asSelected | String | Button text | "As selected" | | info | String | Button text | "More" | | close | String | Button text | "Close" | | infoTitle | String | Dialog title | "Information" |

0.2.1

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago