{"id":23066826,"url":"https://github.com/dvsa/cookie-manager","last_synced_at":"2025-08-15T11:33:29.264Z","repository":{"id":40794232,"uuid":"237405578","full_name":"dvsa/cookie-manager","owner":"dvsa","description":"Library for managing cookies","archived":false,"fork":false,"pushed_at":"2023-07-18T20:56:47.000Z","size":626,"stargazers_count":5,"open_issues_count":9,"forks_count":2,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-10T15:45:00.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dvsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-31T10:14:29.000Z","updated_at":"2024-09-05T20:51:26.000Z","dependencies_parsed_at":"2023-02-03T20:46:17.042Z","dependency_job_id":null,"html_url":"https://github.com/dvsa/cookie-manager","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fcookie-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fcookie-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fcookie-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fcookie-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvsa","download_url":"https://codeload.github.com/dvsa/cookie-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229910957,"owners_count":18143229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T05:15:05.118Z","updated_at":"2024-12-16T05:15:05.709Z","avatar_url":"https://github.com/dvsa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cookie Manager\n\nCookie Manager is a Javascript library for dealing with cookie compliance.\n\nIt can handle removing cookies the user does not consent to or are not defined in the manifest.\nIt can also handle the storing of user preferences when it comes to cookies, and displaying a banner when no\npreferences have been set.\n\n## Installation\n\nNPM\n\n```bash\nnpm install @dvsa/cookie-manager\n```\n\n## Usage\n\nInclude the `cookie-manager.js` script on your web pages:\n\n```html\n\u003cscript src=\"./cookie-manager.js\"\u003e\u003c/script\u003e\n```\n\nInvoke the Cookie Manager by calling init() with a config:\n\n```javascript\ncookieManager.init(configuration_object);\n```\n\n### Feature: Cookie Banner\n\nTo disable this functionality, set the configuration value of `cookie-banner-id` to `false` or remove the definition.\n\nIf you want functionality to display a cookie banner when user preferences have not been set (or expired)\nthen build your cookie banner markup, and give the wrapping element an ID and match it with the configuration value\n`cookie-banner-id`. The banner will be hidden using the HTML [hidden](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden) attribute.\n\nIf the banner includes a `button` element with the value `accept` the library will also bind to the `click` event of the\nbutton and upon user click, mark all optional categories as opt-in. \n\nIf the banner includes a `button` element with the value `reject` the library will also bind to the `click` event of the\nbutton and upon user click, mark all optional categories as opt-out.\n\nThe banner's hidden class will then be restored.\n\n```html\n\u003cheader id=\"cm_cookie_notification\" class=\"hidden\"\u003e\n    \u003cdiv class=\"govuk-cookie-banner \" data-nosnippet role=\"region\" aria-label=\"Cookies on [name of service]\"\u003e\n        \u003cdiv class=\"govuk-cookie-banner__message govuk-width-container\"\u003e\n\n            \u003cdiv class=\"govuk-grid-row\"\u003e\n                \u003cdiv class=\"govuk-grid-column-two-thirds\"\u003e\n                    \u003ch2 class=\"govuk-cookie-banner__heading govuk-heading-m\"\u003eCookies on [name of service]\u003c/h2\u003e\n\n                    \u003cdiv class=\"govuk-cookie-banner__content\"\u003e\n                        \u003cp class=\"govuk-body\"\u003eWe use some essential cookies to make this service work.\u003c/p\u003e\n                        \u003cp class=\"govuk-body\"\u003eWe’d also like to use analytics cookies so we can understand how you use the service and make improvements.\u003c/p\u003e\n                    \u003c/div\u003e\n                \u003c/div\u003e\n            \u003c/div\u003e\n\n            \u003cdiv class=\"govuk-button-group\"\u003e\n                \u003cbutton value=\"accept\" type=\"button\" name=\"cookies\" class=\"govuk-button\" data-module=\"govuk-button\"\u003e\n                    Accept analytics cookies\n                \u003c/button\u003e\n                \u003cbutton value=\"reject\" type=\"button\" name=\"cookies\" class=\"govuk-button\" data-module=\"govuk-button\"\u003e\n                    Reject analytics cookies\n                \u003c/button\u003e\n                \u003ca class=\"govuk-link\" href=\"#\"\u003eView cookies\u003c/a\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\u003c/header\u003e\n```\n\n### Feature: User Preferences Saving\n\nTo disable this functionality, set the configuration value of `user-preference-configuration-form-id` to `false` or remove the definition.\n\nIf you want functionality to setup a user preference cookie, then you need to define a HTML form with an ID and match\nthat to the configuration value `user-preference-configuration-form-id`. Upon initialisation, the library will look\nfor the form when the DOM is ready, and bind to the `submit` event. When submitted, the library will collect the\nvalue of all radio buttons with the `checked` state. The name of the radio buttons **must**\nreflect the category name for cookies defined in your manifest. The values for the radio buttons must be `on` and `off`.\n\n```html\n\u003cform id=\"cm_user_preference_form\"\u003e\n    \u003cfieldset\u003e\n        \u003clegend\u003eAnalytics:\u003c/legend\u003e\n        \u003cinput type=\"radio\" name=\"analytics\" value=\"on\" /\u003e On \u003cbr/\u003e\n        \u003cinput type=\"radio\" name=\"analytics\" value=\"off\" checked /\u003e Off \u003cbr/\u003e\n    \u003c/fieldset\u003e\n\n    \u003cfieldset\u003e\n        \u003clegend\u003eFeedback:\u003c/legend\u003e\n        \u003cinput type=\"radio\" name=\"feedback\" value=\"on\" /\u003e On \u003cbr/\u003e\n        \u003cinput type=\"radio\" name=\"feedback\" value=\"off\" checked /\u003e Off \u003cbr/\u003e\n    \u003c/fieldset\u003e\n\n    \u003cinput type=\"submit\" value=\"Save Preferences\"/\u003e\n\u003c/form\u003e\n```\n\n## Configuration\n\nConfiguration is done when calling `init()` on the Cookie Manager object and is used to determine how you want the\nCookie Manager to behave, and defines a manifest of cookies used on your site.\n\nUsing this method, it allows developers to use the native configuration in their application and it should be as\nsimple as serialising the top-level configuration object/array for Cookie Manager to JSON and putting the result into\nthe init() function (either as a variable or directly):\n\n```javascript\ncm.init(\n  {\n    \"delete-undefined-cookies\": true,\n    \"...\": \"...\"\n  }\n);\n```\n\n### Configuration Schema\n\n###\n```json\n{\n  \"delete-undefined-cookies\": true,\n  \"user-preference-cookie-name\": \"cm-user-preferences\",\n  \"user-preference-cookie-secure\": false,\n  \"user-preference-saved-callback\" : false, //accept a function\n  \"user-preference-cookie-expiry-days\": 365,\n  \"user-preference-configuration-form-id\": \"cookie-manager-form\",\n  \"cookie-banner-id\": \"cm_cookie_notification\",\n  \"cookie-banner-visible-on-page-with-preference-form\": false,\n  \"cookie-banner-saved-callback\": false, //accept a function\n  \"set-checkboxes-in-preference-form\": true,\n  \"cookie-manifest\": [\n    {\n      \"category-name\": \"essential\",\n      \"optional\": false,\n      \"cookies\": [\n        \"essential-cookie\",\n        \"another-essential-cookie\",\n        \"some-imperva-cookie\",\n        \"some-other-imperva-cookie\"\n      ]\n    },\n    {\n      \"category-name\": \"analytics\",\n      \"optional\": true,\n      \"cookies\": [\n        \"_ga\",\n        \"_gtm\"\n      ]\n    },\n    {\n      \"category-name\": \"feedback\",\n      \"optional\": true,\n      \"cookies\": [\n        \"_hotjar\",\n        \"_surveything\"\n      ]\n    }\n  ]\n}\n```\n\n## Development\n### Unit tests\nThe Unit Test will fail if the coverage is below 80%. To run the tests run `npm run test` or `npm run test-html`.\n\n#### HTML\nRunning `npm run test-html` will generate a nice html output for the unit tests and coverage in `/test` and `/coverage` respectivly.\n\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fcookie-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvsa%2Fcookie-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fcookie-manager/lists"}