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
1module.exports = createCoreService('api::cookie.cookie', ({ strapi }) => ({
2 async find(params) {
3 const { pagination } = await super.find(params);
4 const results = await strapi.entityService.findMany("api::cookie.cookie", Object.assign(params, {
5 populate: { category: true }
6 }))
7
8 return { results, pagination };
9 },
10}));
./src/api/cookie-category/services/cookie-category.js
1module.exports = createCoreService('api::cookie-category.cookie-category', ({ strapi }) => ({
2 async find(params) {
3 const { pagination } = await super.find(params);
4 const results = await strapi.entityService.findMany("api::cookie-category.cookie-category", Object.assign(params, {
5 populate: { cookies: true }
6 }))
7
8 return { results, pagination }
9 },
10}));
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 "name": "Necessary Cookies",
3 "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.",
4 "isNecessary": true,
5 "key": "necessary-cookies",
6 "cookies": {
7 "data": [
8 {
9 "attributes": {
10 "name": "Cookies Necessary",
11 "description": "We set this cookie to remember the consent of users for the use of cookies in the \"Necessary\" category.",
12 "host": "mydomain.com",
13 "party": "First-party",
14 "isVisible": true,
15 "duration": {
16 "days": 365,
17 "hours": 0,
18 "minutes": 0
19 },
20 "locale": "en"
21 }
22 }
23 ]
24 },
25 "locale": "en"
26}
Cookie
1{
2 "name": "Cookies Necessary",
3 "description": "We set this cookie to remember the consent of users for the use of cookies in the \"Necessary\" category.",
4 "host": "mydomain.com",
5 "party": "First-party",
6 "isVisible": true,
7 "duration": {
8 "days": 365,
9 "hours": 0,
10 "minutes": 0
11 },
12 "category": {
13 "data": {
14 "attributes": {
15 "name": "Necessary Cookies",
16 "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.",
17 "locale": "en"
18 }
19 }
20 },
21 "key": "necessary-cookies",
22 "locale": "en"
23}
Popup
1{
2 "title": "We value your privacy",
3 "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.",
4 "buttons": [
5 {
6 "buttonTyp": "Primary",
7 "label": "Button"
8 }
9 ],
10 "locale": "en"
11}
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.