strapi-plugin-cookie-manager

1.2.2 • Public • Published
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

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:

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 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

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

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

Option Type Default
localization Boolean true

🔌 API Fields

Category

{
  "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

{
  "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

{
  "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"
}

👉 Good to know

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.

🤝 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 for contributing

@Daedalus, @Eventyret, @derrickmehaffy, @kirdk, @dimitribarbot

🔗 Links

📝 Licence

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

/strapi-plugin-cookie-manager/

    Package Sidebar

    Install

    npm i strapi-plugin-cookie-manager

    Weekly Downloads

    268

    Version

    1.2.2

    License

    MIT

    Unpacked Size

    1.19 MB

    Total Files

    84

    Last publish

    Collaborators

    • eigengrau