A simple, lightweight cookie consent system.
npm install @thisisfever/cookies- Only loads cookies after the user gives consent
- Allows user preferences to be changed at any time via settings
- Splits cookies into categories
Simply add the CSS & JS in your :
``html`$3
> Note: If you intend to use Fever Cookies with the CDN, you can skip this
1. Install package via the following command:
`shell`
$ npm install @thisisfever/cookies
`
2. Import core script to your JS using:
js`
import '@thisisfever/cookies/src/fever-cookies';
`
3. Import core styling to your SCSS using:
scss`
import "~@thisisfever/cookies/src/fever-cookies";
First you need to initilise Fever Cookies.
1. Add the following in your
, below the CSS & JS:
`html
`2. To start adding scripts, you can integrate in two ways, or a combination of both:
1. Modify each script tag
2. Add JS directly into Fever Cookies
### Modify Scripts
To prevent a script from loading (unless the relevent category has been chosen by the user), you need to modify the script.
We need to add
data-cookie="[category] and type="text/plain" to the script tag. For example, Google Analytics would look like this:
`html
` > Important: For each category, you must fill in the the
cookies: [] array with the names of the cookies used within that category. ### Add JS to Fever Cookies
When you initialse the package, there is a
optional_cookies object.
`js
optional_cookies: {
analytics: {
cookies: [],
onAccept: function() {
},
onRevoke: function() {
}
},
marketing: {
cookies: [],
onAccept: function() { },
onRevoke: function() {
}
}
}
` For each category, you must fill in the the
cookies: [] array with the names of the cookies used within that category. For example, Google Analytics would be:
`js
cookies: ['_ga', '_gid', '_gat', '_gat_gtag_UA_XXXXXXXX_X'],
` For any JS you wish to run when a category is accepted, add it directly to the category's
onAccept.
`js
onAccept: function() {
// This category has been accepted, run JS here
},
`
Likewise, you can add any JS you wish to run when a category has been revoked using onRevoke
`js
onRevoke: function() {
// This category has been revoked, run JS here
},
`Options
window.FeverCookies accepts options to help tailor to each site.| Option | Type | Required | Description |
|---|---|---|---|
|
settings_toggle | string | Yes | Element selector. Can be either .class or #id |
| optional_cookies | object | Yes | Triggers for each cookie category |
| policy | object | No | Override default policy name & link. Accepts two keys; name link |
| message | string | No | Override the default notice message |
Examples
See below for a full example:
`html
``Copyright (c) 2021 This is Fever
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.