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

@manchtools/svelte-cookie-consent

v0.2.0

Published

## A user friendly way to ask for consent

Downloads

7

Readme

svelte-cookie-consent

A user friendly way to ask for consent

I could not find a good solution for my SvelteKit project, where i could ask a user for tracking and advertising consent. So i made one.

⚠️ THIS PROJECT IS STILL IN BETA, BUGS AND ERRORS ARE EXPECTED ⚠️

You can install it, right from NPM

npm i @manchtools/svelte-cookie-consent@latest

You have access to 11 exports that control the consent banner behavior.

<CookieConsentBanner>   | Svelte component
<TrackingHead>          | Svelte component
<TrackingBody>          | Svelte component
<AdvertismentHead>      | Svelte component
<AdvertismentBody>      | Svelte component
<MarketingHead>         | Svelte component (new in v0.2.0)
<MarketingBody>         | Svelte component (new in v0.2.0)
trackingConsent         | Svelte store
advertisingConsent      | Svelte store
marketingConsent        | Svelte Store (new in v0.2.0)
cookieConsentSeen       | Svelte store
resetCookieBanner       | function that removes all cookies and resets banner to default

Cookies get an expiration date of 365 days. After that time period, the user will be asked for consent again.

CookieConsentBanner

This is the main banner that your users sees when first loading your site.

Dark version

Cookie consent banner for users with dark preference

Light version

Cookie consent banner for users with light preference

It provides 8 named slots

titleText
mainText
allowTrackingCheckText
allowAdvertisingCheckText
allowMarketingCheckText
giveConsentAllText
giveConsentSelectedText
denyConsentText

You can insert your own text or HTML into these slots to extend it for your needs.

Cookie consent banner for users with dark preference, that shows all the named slots

New in v0.2.0 are now 3 props

showAdvertisingOption   | Default true
showMarketingOption     | Default true
showTrackingOption      | Default true

Passing false to any of these props will remove them from the banner and a user wont be able to consent to that form of data collection

<Banner showAdvertisingOption={false} showMarketingOption={false} showTrackingOption={false}>

If you pass {false} to every prop, the user will only see the option from slot denyConsentText

Cookie consent banner for users with dark preference and all optional data collection disabled

Styling

The banner contains the following styles as CSS root variables that can be replaced to fit your color schema.

--ccb-dark-color-bg: #121212;
--ccb-light-color-bg: #ffffff;
--ccb-dark-color-text: hsla(0, 0%, 100%, 0.8);
--ccb-light-color-text: #000000;
--ccb-dark-color-border: #ffffff;
--ccb-light-color-border: #000000;
--ccb-light-color-button-text: hsla(0, 0%, 100%, 1);
--ccb-dark-color-button-text: hsla(0, 0%, 100%, 0.85);
--ccb-allow-all-button: #38b000;
--ccb-allow-selected-button: #ff9500;
--ccb-deny-button: #bd1f36;

TrackingHead, AdvertismentHead and MarketingHead

You can place any content inside these components that needs to be inside your <head>. You can place it inside your root layout, or on a page by page basis.

Content inside this component, only gets injected once the user has given consent.

TrackingBody, AdvertismentBody and MarketingBody

You can place any content inside these components that needs to be inside your <body>. You can place it inside your root layout, or on a page by page basis. It will be inserted like a normal component so order matters.

Content inside this component only gets injected once the user has given consent.

trackingConsent, advertisingConsent and marketingConsent

These stores contain the user selection as a boolean value. You can use them inside your JavaScript/TypeScript to dynamically have access to user consents, or build your own custom components.

cookieConsentSeen

This store is just for triggering the CookieConsentBanner. If value is false, banner will get displayed, else banner won't be shown.

Cookies that get set on client

The following cookies get set in the client Browser, after the user has interacted with the cookie consent banner.

tracking-cookie-consent         | Default false
advertising-cookie-consent      | Default false
marketing-cookie-consent        | Default false
cookie-banner-seen              | Default false

Legal disclaimer

This tool tries to adhere to GDPR best practices. We are not responsible for any legal liability you may encounter whilst using this tool. You are fully responsible for checking all legal repercussions before implementing this tool