{"id":20726765,"url":"https://github.com/hmcts/cookie-manager","last_synced_at":"2025-10-10T08:06:09.358Z","repository":{"id":40424887,"uuid":"356631299","full_name":"hmcts/cookie-manager","owner":"hmcts","description":"Module for managing cookies","archived":false,"fork":false,"pushed_at":"2025-10-03T06:48:17.000Z","size":797,"stargazers_count":4,"open_issues_count":10,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-03T08:38:56.265Z","etag":null,"topics":["compliance","consent","cookie","cookie-manager","cookie-preference","cookies","gdpr"],"latest_commit_sha":null,"homepage":"https://hmcts.github.io/cookie-manager/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hmcts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-04-10T16:05:32.000Z","updated_at":"2025-09-04T06:47:16.000Z","dependencies_parsed_at":"2023-02-15T15:16:57.791Z","dependency_job_id":"5ba7f189-8be1-4d75-871c-617df94cc806","html_url":"https://github.com/hmcts/cookie-manager","commit_stats":{"total_commits":66,"total_committers":4,"mean_commits":16.5,"dds":0.4696969696969697,"last_synced_commit":"eb91223333a0af46d982662792c77e680eed72f2"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/hmcts/cookie-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmcts%2Fcookie-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmcts%2Fcookie-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmcts%2Fcookie-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmcts%2Fcookie-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hmcts","download_url":"https://codeload.github.com/hmcts/cookie-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmcts%2Fcookie-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003293,"owners_count":26083555,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["compliance","consent","cookie","cookie-manager","cookie-preference","cookies","gdpr"],"created_at":"2024-11-17T04:27:15.067Z","updated_at":"2025-10-10T08:06:09.329Z","avatar_url":"https://github.com/hmcts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Cookie Manager ·\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/hmcts/cookie-manager/actions/workflows/test.yml/badge.svg)](https://www.github.com/hmcts/cookie-manager)\n[![Known Vulnerabilities](https://snyk.io/test/github/hmcts/cookie-manager/badge.svg)](https://snyk.io/test/github/hmcts/cookie-manager)\n======\n\n@hmcts/cookie-manager is a JavaScript library for dealing with cookie compliance.\n\nIt provides a streamline way to define essential and non-essential cookies on a service,\nwhich then acts as a basis for user’s to provide consent for each different category of cookie.\nThe minified script is just under 4KB (after GZIP) and supports IE11 / ES5 by default.\n\nThis library is intended to be used with the [GDS Cookie Banner component](https://design-system.service.gov.uk/components/cookie-banner/)\nthough it can be configured to support a variety of multi-stage cookie banners of varying designs. \n\n**In-depth documentation on all configuration options, emitted events, configuration with common analytics\nlibraries and more can be [found on the project's documentation site](https://hmcts.github.io/cookie-manager/).**\n\n## Quick start\n\n### Installing the library\nThere are 2 main ways to start using the Cookie Manager library within your app:\n\n#### 1. Install with NPM (recommended)\n\n   We recommend [installing cookie-manager through Node's package\nmanager (NPM) or Yarn](https://hmcts.github.io/cookie-manager/getting-started/install-using-nodejs/).\n\n#### 2. Install using compiled script\n\n   You can also install cookie-manager by [serving our compiled JavaScript\nfile](https://hmcts.github.io/cookie-manager/getting-started/install-using-script-tag/)\n(included on each [release](https://github.com/hmcts/cookie-manager/releases/latest)).\n\n### Configuring and initializing the library for your service\nOnce you've included the library within your app, you can begin\nconfiguring it for use within your service. See our documentation\non [configuring and initializing](https://hmcts.github.io/cookie-manager/getting-started/configuring-the-library/index.html#configuring-and-initializing-the-library/),\nor learn more about the [configuration options](https://hmcts.github.io/cookie-manager/configuration-options/) available.\n\n## Features\n\n### Cookie banner support\nBy default, the Cookie Manager library is configured to display or hide a cookie banner configured\nwithin your service. Without any extra configuration, the library is configured out-of-the-box to work\nwith the [template provided within our documentation](https://hmcts.github.io/cookie-manager/cookie-banner/#html-nunjucks-template).\n\nIn short, the library works by binding event listeners to the buttons defined for each action, with these\n[actions being specified within the config](https://hmcts.github.io/cookie-manager/configuration-options/cookie-banner/#action).\nEach action defines:\n\n- How consent should be affected\n- What confirmation message should be shown\n\n#### An example action of an action and how it works:\n\n```json\n{\n  \"name\": \"accept\",\n  \"buttonClass\": \"cookie-banner-accept-button\",\n  \"confirmationClass\": \"cookie-banner-accept-message\",\n  \"consent\": true\n}\n```\nThis action specifies that upon an element with the class `cookie-banner-accept-button` (within the cookie banner) being clicked:\n\n1. We consent to all optional cookie categories.\n2. Any elements with the class `cookie-banner-accept-message` (within the cookie banner) should be shown.\n3. A `CookieBannerAction` event is then emitted with the activated action's name (in this case, 'accept') being passed to any listening callbacks.\n\nMore information about how the cookie banner functionality and how it can be configured\nto support a variety of different action/message (stage-based) cookie banners can be [found\nwithin the docs](https://hmcts.github.io/cookie-manager/configuration-options/cookie-banner/).\n\n\n### Cookie preferences form support\nThe Cookie Manager library is also, by default, setup to parse a cookie preference form which allows a user\nto set their cookie preferences in a fine-grained manner. The default configuration\nis built to work with the [template provided within our documentation](https://hmcts.github.io/cookie-manager/cookie-preferences-form/#html-nunjucks-template).\n\nIn short, on the form submission event:\n\n1. The radio groups within the form are parsed.\n2. Each selected option is matched to a cookie category (based on the radio element's `name` attribute).\n3. The consent value for the selected option is derived from the radio element's `value` attribute, which should be either `on` or `off`.\n4. The selected options are then set as user's active cookie preferences.\n\nThe form layout needs to be configured for each different cookie category you are utilising within your service.\nThis requires you to add another set of radio inputs, with the `name` attribute set to that of your cookie category,\nusing `on`/`off` as their values for consent / reject respectively.\n\nMore information about the cookie preferences form functionality and how it can be configured can be [found\nwithin the docs](https://hmcts.github.io/cookie-manager/configuration-options/cookie-preferences-form/).\n\n### Emitting events and callbacks\nWhen an important event occurs within @hmcts/cookie-manger, an event is emitted by the library. \nUtilising the exported `on` and `off` [functions](https://hmcts.github.io/cookie-manager/listenining-to-cookie-manager-events/#listener-functions) from the library, you can easily add callbacks to each event which fires. \nThis could be used to disable a third party analytics package, conditionally change the DOM etc.\n\n```js\nimport cookieManager from '@hmcts/cookie-manager';\n\nconst someEventCallback = function (eventData) { ... };\ncookieManager.on('\u003cEVENT-NAME-HERE\u003e', someEventCallback);\n```\n\nMore information about the built-in event processor / emitter can be [found\nwithin the project's documentation](https://hmcts.github.io/cookie-manager/listenining-to-cookie-manager-events/index.html#events-and-listeners).\n\nA list of the events fired by the Cookie Manager library can also be [found here](https://hmcts.github.io/cookie-manager/listenining-to-cookie-manager-events/#events-list).\n\nYou can also see an example of this used to enable / disable Google Analytics (through GTM) and \nDynatrace RUM based on user preferences [here within the docs](https://hmcts.github.io/cookie-manager/google-analytics-and-dynatrace-setup/#1-add-the-library-and-some-event-listeners).\n\n## Configuration\nConfiguration of the library is done through a config provided to the exposed `init` function\nused when initializing the library. The default configuration is:\n```json\n{\n    \"userPreferences\": {\n        \"cookieName\": \"cookie-preferences\",\n        \"cookieExpiry\": 365,\n        \"cookieSecure\": false\n    },\n    \"preferencesForm\": {\n        \"class\": \"cookie-preferences-form\"\n    },\n    \"cookieBanner\": {\n        \"class\": \"cookie-banner\",\n        \"showWithPreferencesForm\": false,\n        \"actions\": [\n            {\n                \"name\": \"accept\",\n                \"buttonClass\": \"cookie-banner-accept-button\",\n                \"confirmationClass\": \"cookie-banner-accept-message\",\n                \"consent\": true\n            },\n            {\n                \"name\": \"reject\",\n                \"buttonClass\": \"cookie-banner-reject-button\",\n                \"confirmationClass\": \"cookie-banner-reject-message\",\n                \"consent\": false\n            },\n            {\n                \"name\": \"hide\",\n                \"buttonClass\": \"cookie-banner-hide-button\"\n            }\n        ]\n    },\n    \"cookieManifest\": [],\n    \"additionalOptions\": {\n       \"defaultConsent\": false,\n       \"deleteUndefinedCookies\": false,\n       \"disableCookieBanner\": false,\n       \"disableCookiePreferencesForm\": false\n    }\n}\n```\n\nSee our documentation to learn more about [configuring and initializing the library](https://hmcts.github.io/cookie-manager/getting-started/configuring-the-library/index.html#configuring-and-initializing-the-library/),\nor to view the other [configuration options](https://hmcts.github.io/cookie-manager/configuration-options/) available. \nThe provided templates/examples within the documentation are intended to require little extra\nconfiguration to get a basic cookie compliance solution working on your service.\n\n**Note: Cookie Manager will attempt to validate the config passed to it on initialization. \nIf any malformed, missing properties etc. are supplied, the library will be disabled until it is resolved. \nA warning will be printed in the console alerting of the problematic property.**\n\n## Development\n### Building\n\nThere are currently 2 seperate build options for this library\n- `build:package` - builds the `esm` version of the module, intended to be used with NodeJS based applications.\nIncludes TS declarations / typings and JSDoc comments on exposed functions.\n- `build:browser` - builds the `umd` version of this module, intended for use directly within browsers (script tag).\nBuilds a minified version of the library.\n\nBoth builds use [rollup.js](https://github.com/rollup/rollup) and a number of plugins\nto compile, minify, and create declarations for the library.\n\n### Dependencies\nThis project currently only uses dependencies for linting and building the project.\n\n### Using within your project\nFollow the setup guide on installing and initializing the module within NodeJS,\nthis project provides type declarations built in, so for projects using TypeScript,\nyou should see typings support.\n\n## Testing\nTo run the tests run `npm run test` or to see the coverage, `npm run test:coverage`.\n\nAs of v1.0.0 of this library, there are over 110 unit tests with a coverage of around 95%.\nManual testing has also been performed across most major browsers, including IE11.\n\n**Note: The unit tests will fail if coverage is found to be below 90%.**\n\n## Authors\n[Thomas Geraghty](https://github.com/Thomas-Geraghty)\n\n[Linus Norton](https://github.com/linusnorton) - Additional support\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\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%2Fhmcts%2Fcookie-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhmcts%2Fcookie-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmcts%2Fcookie-manager/lists"}