1.0.3 • Published 1 year ago

@boxfish-studio/sveltekit-cookie-manager v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Disclaimer

Minimum required SvelteKit version: 1.0.0-next.581.

About 📝

Sveltekit Cookie Manager reduces the workload of creating and mantaining multiple cookie consents by centralizing them into this package. Enables cookie management of following services:

  • Google Analytics Universal.
  • Google Analytics 4.

Features ✨

  • Display a customizable popup to accept or reject cookies.
  • Create a cookie library showing:
    • Tables with details about site's necessary cookies and additional cookies: cookie name, provider name and url, cookie category, purpose, expiry and type.
    • Radio inputs (allow or reject all cookies) and a button to update preferences.

Installation 🧰

$ npm i @boxfish-studio/sveltekit-cookie-manager

or yarn

$ yarn add @boxfish-studio/sveltekit-cookie-manager

How to use 📝

Show a popup

Import the CookieManager component to your Svelte page and pass the configuration with your desired settings:

<script lang="ts">
	import { CookieManager } from '@boxfish-studio/sveltekit-cookie-manager'
	import type { SKCMConfiguration } from '@boxfish-studio/sveltekit-cookie-manager'

	const configuration: SKCMConfiguration = {
		disclaimer: {
			title: 'This website uses cookies',
			body: 'By using this site, you agree with our use of cookies'
		},
		services: {
			googleAnalyticsUniversalId: 'UA-XXXXXXXX',
			googleAnalytics4Id: 'G-XXXXXXXX'
		},
		theme: {
			primary: '#14cabf',
			dark: '#131f37',
			medium: '#b0bfd9',
			light: '#fff'
		}
	}
</script>

<CookieManager {configuration} />

Show the cookie library

Import the CookieLibrary component to your svelte file and pass the configuration with your desired settings, as shown in the example below.

You can also use the library without any configuration or you can pass a theme to the configuration:

<script lang="ts">
	import { CookieLibrary } from '@boxfish-studio/sveltekit-cookie-manager'
	import type { SKCMConfiguration } from '@boxfish-studio/sveltekit-cookie-manager'

	const configuration: SKCMConfiguration = {
		theme: {
			primary: '#14cabf',
			dark: '#131f37',
			medium: '#b0bfd9',
			light: '#fff'
		}
	}
</script>

<CookieLibrary {configuration} />

Using the internal store

You can use the servicesInitialized writable to know whether the services are running or not.

import { servicesInitialized } from '@boxfish-studio/sveltekit-cookie-manager'
import { get } from 'svelte/store'

const isRunning = get(servicesInitialized)

Configuration 🪛

Custom configuration must be of type SKCMConfiguration. All available props are shown below:

type SKCMConfiguration = {
	disclaimer: {
		title?: string
		body?: string
		policyText?: string
		policyUrl?: string
		acceptButtonText?: string
		rejectButtonText?: string
	}
	services: {
		googleAnalyticsUniversalId?: string
		googleAnalytics4Id?: string
		adCookiesEnabled?: boolean
		customNecessaryCookies?: {
			name: string
			provider: string
			providerUrl: string
			purpose: string
			expiry: string
			type: string
			showDisclaimerIfMissing?: boolean
		}[]
	}
	theme: {
		primary?: string
		dark?: string
		medium?: string
		light?: string
	}
}

Disclaimer props

NameDescriptionDefault value
titleThe title of the popup"Cookie Preferences"
bodyBody message of the popup"By using this site, you agree with our use of cookies."
policyTextText that links to Privacy Policy"Read our Cookie Policy"
policyUrlPrivacy Policy url"/privacy-policy"
acceptButtonTextText shown in 'Accept' button"Accept Additional Cookies"
rejectButtonTextText shown in 'Reject' button"Reject Additional Cookies"

Services props

You must use googleAnalyticsUniversalId or googleAnalytics4Id.

NameDescriptionDefault value
googleAnalyticsUniversalIdYour Google Analytics Universal key
googleAnalytics4IdYour Google Analytics 4 key
adCookiesEnabledWhether cookies with the category Advertising should be set in the browser and shown in the librarytrue
customNecessaryCookiesCookies that should be present in the Necessary Cookies table to inform the user their usage. To configure them see below

Custom necessary cookies

You can configure extra cookies that will also appear in the Cookie library by specifying them in the customNecessaryCookies property. They accept the following options:

NameDescriptionDefault valueRequiredExample
nameName of the cookieYesBoxfish Cookie
providerName of it's providerNoBoxfish
providerUrlURL of it's providerNohttps://boxfish.studio
purposeUsage of the cookieYes"Stores the user's consent"
expiryTime that the cookie with remain in the user's browser since it's creationYes"30 days"
typeType of cookieYes"HTTP"
showDisclamerIfMissingShow the accept/reject popup if this cookie is missingfalseNotrue

Theme props

A 4-colour palette has been predefined following a custom style guide. You may overwrite these values in your custom configuration variable.

NameDescriptionDefault value
primaryUsed in buttons backgrounds, anchors#14cabf (teal)
darkUsed in headings, body#131f37 (black)
mediumUsed in table headings, table borders#b0bfd9 (gray)
lightUsed in banner background colour, buttons text colour#fff (white)

Built with

  • Sveltekit.
  • Typescript.

Release Package

npm run package && cd package && npm publish --access=public

1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.2

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago