Manage categorized cookies directly within the Strapi CMS admin panel at one place and use the predefined plugin API to provide GDPR consent cookies.
Manage categorized cookies directly within the Strapi CMS admin panel at one place and use the predefined plugin API to provide GDPR consent cookies.
Make sure that the i18n plugin
is installed within your strapi admin settings.
Then install the plugin with your desired package manager.
(It's recommended to use yarn to install this plugin within your Strapi project. Install yarn with these docs)
yarn add strapi-plugin-cookie-manager
# or
npm install strapi-plugin-cookie-manager
After successful installation you need to re-build your Strapi:
yarn build && yarn develop
# or
npm run build && npm run develop
or just run Strapis development mode with --watch-admin
option
yarn develop --watch-admin
#or
npm run develop --watch-admin
Now the Cookie Manager should appear inside the Plugins section on the left hand sidebar like so:
You will notice that the plugin generated new content types named cookie
, cookie-category
and cookie-popup
. Initially the relation fields are not populated for cookie
and cookie-category
! That means they won't show in your API.
In order to get them populated, just edit the following files like below:
./src/api/cookie/services/cookie.js
1
2
3
4
5
6
7
8
9
10
module.exports = createCoreService('api::cookie.cookie', ({ strapi }) => ({
async find(params) {
const { pagination } = await super.find(params);
const results = await strapi.entityService.findMany("api::cookie.cookie", Object.assign(params, {
populate: { category: true }
}))
return { results, pagination };
},
}));
./src/api/cookie-category/services/cookie-category.js
1
2
3
4
5
6
7
8
9
10
module.exports = createCoreService('api::cookie-category.cookie-category', ({ strapi }) => ({
async find(params) {
const { pagination } = await super.find(params);
const results = await strapi.entityService.findMany("api::cookie-category.cookie-category", Object.assign(params, {
populate: { cookies: true }
}))
return { results, pagination }
},
}));
This step is not required for the content type cookie-popup
.
You might wanna check out API Fields to see the JSON response.
Currently there is only one option for the plugin settings. You can change the plugin settings inside the Strapi admin panel under:
Strapi Settings -> Cookie Manager -> Configuration
Or you change it manually in your ./config/plugins.js
module.exports = ({ env }) => ({
// ...
'cookie-manager': {
enabled: true,
config: {
localization: true
}
},
// ...
});
Option | Type | Default |
---|---|---|
localization | Boolean | true |
Category
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"name": "Necessary Cookies",
"description": "These cookies are required to enable the basic features of this site, such as adjusting your consent preferences. These cookies do not share any personally identifiable data.",
"isNecessary": true,
"key": "necessary-cookies",
"cookies": {
"data": [
{
"attributes": {
"name": "Cookies Necessary",
"description": "We set this cookie to remember the consent of users for the use of cookies in the \"Necessary\" category.",
"host": "mydomain.com",
"party": "First-party",
"isVisible": true,
"duration": {
"days": 365,
"hours": 0,
"minutes": 0
},
"locale": "en"
}
}
]
},
"locale": "en"
}
Cookie
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"name": "Cookies Necessary",
"description": "We set this cookie to remember the consent of users for the use of cookies in the \"Necessary\" category.",
"host": "mydomain.com",
"party": "First-party",
"isVisible": true,
"duration": {
"days": 365,
"hours": 0,
"minutes": 0
},
"category": {
"data": {
"attributes": {
"name": "Necessary Cookies",
"description": "These cookies are required to enable the basic features of this site, such as adjusting your consent preferences. These cookies do not share any personally identifiable data.",
"locale": "en"
}
}
},
"key": "necessary-cookies",
"locale": "en"
}
Popup
1
2
3
4
5
6
7
8
9
10
11
{
"title": "We value your privacy",
"description": "We use cookies to help you navigate efficiently. You will find detailed information about all cookies under each category below. The cookies that are categorized as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. We also use third-party cookies that help analyze how you use our website in order to provide the content and advertisements that are relevant to you. These cookies will only be stored in your browser with your prior consent. You can choose to enable or disable some or all of these cookies but disabling some of them may affect your browsing experience.",
"buttons": [
{
"buttonTyp": "Primary",
"label": "Button"
}
],
"locale": "en"
}
The i18n plugin
must be installed by default, even if you change the config to disabled
! Disabling just hides the possibility to edit on multiple locales.
This plugin generates content types cookies
and cookie-categories
in your content manager (not plugin content type). Those will be hidden inside the content manager per default.
If you like to enhance, fix or just helping improving the quality or security of the code. Feel free to fork and make a pull request to bring this plugin further ahead. All inputs are welcome!
If this plugin was helpful, dont hesitate giving a ⭐️.
@Daedalus, @Eventyret, @derrickmehaffy, @kirdk, @dimitribarbot
MIT Licence copyright (c) 2022 eigengrau GmbH & Strapi Solutions
npm install strapi-plugin-cookie-manager
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.