Strapi plugin logo for Cookie Manager

Cookie Manager

Manage categorized cookies directly within the Strapi CMS admin panel at one place and use the predefined plugin API to provide GDPR consent cookies.

thumbnail for Cookie Manager
Cookie Manager Icon

Strapi v4 - Cookie Manager

NPM Version Monthly download on NPM code style: prettier PRs welcome! License Follow eigengrau Repo stars

Manage categorized cookies directly within the Strapi CMS admin panel at one place and use the predefined plugin API to provide GDPR consent cookies.

Screenshot of Cookie Manager usage

🎉 Features

  • 🥞 Predefined API: Simple and ready for use API endpoint
  • 📦 Cookie Categories: Easly create categories and manage your cookies within
  • 💬 Internationalization: Possibility to localize your cookies supporting Strapi's I18n plugin
  • 👥 Duplicate: Maximize cookie creation efficiency by duplicating
  • 🌓 Light & Dark: Complete reuse of Strapi's design system components
  • 📢 GDPR Consent: Communicate transparently in the name of data privacy
  • 📍 One place: Manage everything related to cookies in one place

⚙️ Versions

  • Strapi v4 - (current) - v1.x

⏳ Installation

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:

Screenshot of sidebar with Cookie Manager installed

You will notice that the plugin generated new content types named cookie, cookie-category and cookie-popup. Initially the relation fields are not populated! 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.

🔧 Configuration

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

Screenshot of the Cookie Manager settings pahe

Or you change it manually in your ./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  'cookie-manager': {
    enabled: true,
    config: {
      localization: true
    }
  },
  // ...
});

Options

OptionTypeDefault
localizationBooleantrue

🔌 API Fields

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
{
  "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.",
  "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
{
  "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"
      }
    }
  },
  "locale": "en"
}

Popup

1
2
3
4
5
{
  "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.",
  "locale": "en"
}

👉 Good to know

Internationalization is enabled per default, even if disabled! Disabling it just hides the possibility to edit multiple locales.

This plugin generates content types cookies and cookie-categories in your content manager (not plugin content type). Those will be hidden the content manager per default.

🤝 Contributing

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!

❤️ Support the plugin

If this plugin was helpful, dont hesitate giving a ⭐️.

✨ Special Thanks

@Daedalus, @Eventyret

🔗 Links

📝 Licence

MIT Licence copyright (c) 2022 eigengrau GmbH & Strapi Solutions

Install now

npm install strapi-plugin-cookie-manager

Last updated

43 days ago

Strapi Compatibility

>=4.0.0 <5.0.0-0

Author

github profile image for eigengrau
eigengrau

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.