Skip to content

Commit

Permalink
Refine docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaloo committed Apr 21, 2024
1 parent 51db39f commit 4d7d857
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

## How does it work?

1. It takes **JSON configuration** that controls display of the banner.
2. It fires **JS callback** when user interacts with the banner
3. It provides simple **JS object** with consent state
1. It takes **[JSON configuration](#user-content-config-object)** that controls display of the banner.
2. It fires **[JS callback](#user-content-callbacks)** when user interacts with the banner
3. It provides simple **[JS object](#user-content-consent-state-object)** with consent state


## Get started
Expand All @@ -35,14 +35,13 @@ Then in the footer you can include the actual JS:

To make that work you need to prepare **three** things:

1. A function to load the consent state from somewhere, for instance `localStorage` (see [examples](#examples))
2. A function to do something when the user provides their consent, for instance save it in `localStorage` (see [examples](#examples))
3. A config object that contains complete configuration for the banner content (see [examples](#examples))
1. A **function to load the consent state from somewhere**, for instance `localStorage` (see [examples](#examples))
2. A **function to do something when the user provides their consent**, for instance save it in `localStorage` (see [examples](#examples))
3. A **config object that contains complete configuration** for the banner content (see [examples](#examples))


## Config Object


```js
{
display: {
Expand All @@ -65,7 +64,7 @@ To make that work you need to prepare **three** things:
reject: 'Reject',
accept: 'Accept all'
}
}
},
settings: {
title: 'Customise your preferences',
description: 'Longer description with *simple markdown support*.',
Expand All @@ -79,6 +78,37 @@ To make that work you need to prepare **three** things:
}
```

## Consent State Object

Both JS callback functions provided needs to either accept (on save) or return (on load) Consent State Object:

```js
{
ad_storage: 'granted',
analytics_storage: 'denied'
}
```


## Callbacks

```js
cookiesBannerJs(
function loadConsentState() {
const consentState = {}; // get it from somewhere (e.g. localStorage);
return consentState;
},
function saveConsentState(consentState) {
// do something with consentState, which is basic JS object:
// {
// ad_storage: 'granted',
// analytics_storage: 'denied'
// }
},
config
);
```

**Simple Markdown**

All `description` fields in config object support simplified Markdown-like syntax:
Expand Down

0 comments on commit 4d7d857

Please sign in to comment.