# @hashicorp/react-consent-manager

> A GDPR-compliant Consent Manager

Latest version **9.3.0** (published 2024-07-05) · MPL-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @hashicorp/react-consent-manager
pnpm add @hashicorp/react-consent-manager
yarn add @hashicorp/react-consent-manager
bun add @hashicorp/react-consent-manager
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 9.3.0 |
| Published | 2024-07-05 |
| First published | 2019-09-04 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 70.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 62 |
| Author | HashiCorp |
| Maintainers | kaitlynnefuery, abhishek-hashicorp, dstaley, cameronperera, alexju, consul-ui-services, wenincode-hashicorp, hashicb, britt.lindgren, paulhcp, nandereck, tstormk, hashibot-hds, lackeyjb1, youriwims, jpogran, _natmegs, thrashr888, melsumner, mwickett, didoo, zchsh, hcitsec, gregone, meirish, enmod, kaxcode, anubhavmishra-hashicorp, hashibot-web, cstitt-hashi, mocohen, dhaulagiri |

## Links

- npm: https://www.npmjs.com/package/@hashicorp/react-consent-manager
- Repository: https://github.com/hashicorp/react-components
- Homepage: https://github.com/hashicorp/react-components#readme
- Issues: https://github.com/hashicorp/react-components/issues
- npm.io page: https://npm.io/package/@hashicorp/react-consent-manager

## Dependencies (6)

- [js-cookie](https://npm.io/package/js-cookie.md) ^2.2.1
- [classnames](https://npm.io/package/classnames.md) ^2.3.1
- [@hashicorp/flight-icons](https://npm.io/package/@hashicorp/flight-icons.md) ^2.5.0
- [@hashicorp/react-button](https://npm.io/package/@hashicorp/react-button.md) ^6.2.0
- [@hashicorp/react-toggle](https://npm.io/package/@hashicorp/react-toggle.md) ^5.1.1
- [@hashicorp/platform-util](https://npm.io/package/@hashicorp/platform-util.md) ^0.2.0

## Recent versions

- 9.3.0 (latest) — 2024-07-05
- 9.3.0-canary-20240624195037 (canary) — 2024-06-24
- 5.3.3-alpha.14 (next) — 2021-07-30
- 1.1.17-fonts.0 (fonts) — 2019-10-30
- 9.2.1 — 2024-06-20
- 9.2.0 — 2023-07-17
- 9.2.0-canary-20230711210816 — 2023-07-11
- 9.2.0-canary-20230711204911 — 2023-07-11
- 9.1.2 — 2023-05-25
- 9.1.1 — 2023-05-05
- 9.1.1-canary-20230505185900 — 2023-05-05
- 9.1.1-canary-20230505185850 — 2023-05-05
- 9.1.1-canary-20230505182613 — 2023-05-05
- 9.1.1-canary-20230505173926 — 2023-05-05
- 9.1.1-canary-20230505172719 — 2023-05-05
- … 193 more at https://npm.io/package/@hashicorp/react-consent-manager/versions

## README

# Consent Manager

A GDPR-compliant consent manager.

### Props

- `version` (integer) - version number, bump up to override previous consent preferences
- `container` (string) - id of container where the consent manager should live
- `companyName` (string) - your company name to be inserted in various copy
- `privacyPolicyLink` (string) - link to your company's privacy policy
- `segmentWriteKey` (string) - your production segment write key
- `segmentServices` (array of objects) - use this to override the category or description of a service provided by Segment
  - `name` - name of the Segment integration, must match the integration you are overriding
  - `category` _[optional]_ - new category name
  - `description` _[optional]_ - new description
- `categories` (array) - State of toggle
  - `name` - name of category
  - `description` - description for the category
- `additionalServices` (array of objects) - additional integrations outside of Segment that you wish to include in the consent manager
  - `name` - name of service
  - `description` - description of service
  - `category` - category of service
  - `body` _[optional]_ - javascript body associated with service _If present, overrides `url` below_
  - `url` _[optional]_ - url of js file associated with service
  - `async` (bool) _[optional]_ - add `async` property to script element
  - `addToBody` (bool) _[optional]_ - inject script before closing `<body>` tag
  - `dataAttrs` (arr) _[optional]_ - array of `data-` attributes to add to script tag
    - `name` (str) - name of data attribute (`data-name`)
    - `value` (str) - value of `data` attribute to set

# Upgrading from `v8` to `v9`

```
npm install @hashicorp/react-consent-manager@latest
```

> **Warning**: `v9` is technically not a breaking change, but there are some significant changes to be aware of with regards to our analytics.

As of `v9.0.0`, the Segment CDN hostname has been replace with a HashiCorp hostname via `analytics._cdn`. A custom Segment Analytics.js URL is also being used. There is no breaking change to the react component API.

## `SegmentPreloadScript`

In `v9.0.0`, ConsentManager now exports a `SegmentPreloadScript` component. Why? ConsentManager uses a very similar Segment script to the current preloading script that we use in our `_document.tsx/js` files.

Now that we're updating both with a custom Segment AJS URL and CDN hostname, it makes sense for the two to be co-located.

Expect the new change to look like the following:

```diff
// pages/_document.tsx


  import Document, { Html, Head, Main, NextScript } from 'next/document'
  import HashiHead from '@hashicorp/react-head'
+ import { SegmentPreloadScript } from '@hashicorp/react-consent-manager/scripts/segment'
  // other imports

  export default class MyDocument extends Document {
    static async getInitialProps(ctx) {
      const initialProps = await Document.getInitialProps(ctx)
      return { ...initialProps }
    }

    render() {
      return (
        <Html lang="en">
          <Head>
            <HashiHead />
          </Head>
          <body>
-           <script
-             dangerouslySetInnerHTML={{
-               __html: `!function(){var analytics=window... ... ...`
-             }}
-           />
+           <SegmentPreloadScript />

// etc...
```

No additional updates are necessary!

---
_Source: https://npm.io/package/@hashicorp/react-consent-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
