• Stars
    star
    250
  • Rank 162,397 (Top 4 %)
  • Language Svelte
  • License
    MIT License
  • Created over 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GDPR compliant cookie consent banner implementation




GDPR Cookie Consent banner

js-standard-style actions SvelteKit Svelte v3

What is it?

Svelte implementation of a compliant GDPR banner. It allows the user granular opt-in and out of four different cookie categories.

It now works with SvelteKit without any workarounds!

What are its features?

  • Small, discrete, and non-intrusive
  • GDPR Compliant
  • Responsive
  • Offers four categories
  • Runs any function on opting-in
  • Runs opted-in functions on each visit
  • Changing the choices requires the user to opt-in again.
  • Svelte Ready
  • No dependencies
  • Choices expire yearly
  • Optional CSS (with BEM) to bootstrap your cookie message right away
  • Modifiable labels and messages

How do I install it?

Via NPM

Simply install the node module into your codebase.

npm install --save-dev @beyonk/gdpr-cookie-consent-banner

Usage

Svelte

Just use it as a regular svelte component:

<GdprBanner cookieName="foo" description="bar" on:analytics={initAnalytics} />

<script>
  import '@beyonk/gdpr-cookie-consent-banner/style.css' // optional, you can also define your own styles
  import { Banner as GdprBanner } from '@beyonk/gdpr-cookie-consent-banner'

  function initAnalytics () {
    // do something with segment.io or google analytics etc
  }
</script>

Methods

You can re-call the cookie banner from an external link by binding the component instance and calling show() on it.

<GdprBanner bind:this={gdprBanner} cookieName="foo" description="bar" on:analytics={initAnalytics} />

<script>
  import { GdprBanner } from '@beyonk/gdpr-cookie-consent-banner'

  let gdprBanner

  gdprBanner.show()
</script>

Props

The defaults are shown below.

It is not possible to opt-out of 'necessary' cookies.

const props = {
  /**
   * You must set the cookie name.
   **/
  cookieName: 'beyonk_gdpr',

  /**
   * The cookie configuration, such as domain and path.
   **/
  cookieConfig: {
    domain: 'example.com',
    path: '/'
  },

  /**
   * These are the top two lines of text on the banner
   * The 'description' field can include html such as links
   **/
  heading: 'GDPR Notice',
  description: 'We use cookies to offer a better browsing experience, analyze site traffic, personalize content, and serve targeted advertisements. Please review our <a href="/privacy-policy">privacy policy page</a>. By clicking accept, you consent to our privacy policy & use of cookies.',

  /**
   * All the button labels and aria-label content.
   **/
  acceptLabel: 'Confirm all',
  rejectLabel: 'Reject all',
  settingsLabel: 'Preferences',
  closeLabel: 'Close window',
  editLabel: 'Edit settings',

  /**
   * These are the default opt-ins and their descriptions.
   * When value is set to true, the option will automatically be checked on load.
   *
   * If you want to hide a category, simply set it to false, e.g. 'marketing: false'
   **/
  choices: {
      necessary: {
          label: "Necessary cookies",
          description: "Used for cookie control. Can't be turned off.",
          value: true
      },
      tracking: {
          label: "Tracking cookies",
          description: "Used for advertising purposes.",
          value: true
      },
      analytics: {
          label: "Analytics cookies",
          description: "Used to control Google Analytics, a 3rd party tool offered by Google to track user behavior.",
          value: true
      },
      marketing: {
          label: "Marketing cookies",
          description: "Used for marketing data.",
          value: true
      }
  },

  /**
   * Show an icon to edit cookies later, when banner is closed.
  **/
  showEditIcon: true,

  /**
   * These are the functions which are run if a user opts-in to that category.
   * You should drop your cookies here (or set a variable to control the later dropping of cookies.
   *
   * If you are using svelte, you can use events instead - see the Svelte section below.
   **/
  categories: {
    analytics: function() {
      console.log('No analytics cookies specified')
    },
    tracking: function() {
      console.log('No tracking cookies specified')
    },
    marketing: function() {
      console.log('No marketing cookies specified')
    },
    necessary: function() {
      console.log('No necessary cookies specified')
    }
  }
}

More Repositories

1

svelte-mapbox

MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
Svelte
342
star
2

svelte-notifications

Svelte toast notifications component that can be used in any JS application
Svelte
309
star
3

svelte-carousel

A super lightweight, super simple Carousel for Svelte 3
Svelte
213
star
4

svelte-social-auth

Social Auth for Svelte v3
Svelte
169
star
5

svelte-datepicker

A lightweight datepicker written in Svelte
Svelte
141
star
6

sapper-rbac

RBAC for Sapper
JavaScript
81
star
7

svelte-googlemaps

Svelte Google Maps Components
Svelte
79
star
8

svelte-google-analytics

Google Analytics component for Svelte
JavaScript
77
star
9

http

An isomorphic http client for Svelte applications
JavaScript
45
star
10

svelte-scrollspy

Scroll Spy component for Svelte
JavaScript
38
star
11

now-sapper-demo

Now v2 (Serverless) Sapper Application
JavaScript
23
star
12

svelte-facebook-pixel

A facebook pixel module for Svelte / SvelteKit
Svelte
22
star
13

svelte-toggle

Toggle component for Svelte
Svelte
22
star
14

async-script-loader

Asynchronous script loading for SPAs
JavaScript
17
star
15

svelte-steps

Progress Steps component for Svelte
Svelte
17
star
16

svelte-component-livereload-template

Svelte component template with LiveReload and Jest unit testing
JavaScript
14
star
17

svelte-simple-icons

Simple Brand Icons for Svelte
JavaScript
13
star
18

svelte-tag-input

A super simple, extremely lightweight tag input for Svelte and Vanilla JS
CSS
8
star
19

reorient

Transforms json from one format into another
JavaScript
7
star
20

now-v2-ghost

Experiment trying to get ghost to run on now's v2 platform
CSS
7
star
21

svelte-facebook-customer-chat

Facebook Messaging Platform - Customer Chat Integration
HTML
6
star
22

svelte-scheduler

Scheduling and Calendaring component for Svelte
JavaScript
5
star
23

svelte-trustpilot

Svelte / Vanilla JS Trustpilot Widget with proper SPA support
Svelte
4
star
24

pino-logtail

Pino Logtail log transport
JavaScript
3
star
25

svelte-slim-select

A thin svelte wrapper around slim-select
HTML
3
star
26

svelte-favicons

A favicons generator for your web application.
HTML
3
star
27

initials-avatar

Create avatars from user initials in pure javascript
JavaScript
3
star
28

marker-clusterer-ssr

An SSR compatible implementation of Google Maps MarkerClusterer
JavaScript
2
star
29

svelte-intercom

Intercom for Svelte or Vanilla JS Apps
JavaScript
2
star
30

hapi-view-models

View model support for hapi
JavaScript
2
star
31

blemish

Super simplistic markdown parser
JavaScript
2
star
32

promise-retry

Retryable promises for node and the browser
JavaScript
1
star
33

sanity-template-sveltekit-basic

Empty Sanity SvelteKit Template
JavaScript
1
star
34

svelte-usetiful

Single tag Usetiful integration for Svelte
Svelte
1
star