---
title: Installing Segment's Consent Manager in Next.js
slug: oms/installing-segments-consent-manager-in-nextjs
docTags: 
createdAt: 2024-03-27T15:13:34.457Z
---

Chord's [Next.js starter kit](https://github.com/chordcommerce/nextjs-starter-autonomy) uses the `ConsentManager` React component. It comes with a fully built UI for selecting data collection preferences:

![](https://api.archbee.com/api/optimize/TmutqdeXiIw-V3gBZXVjd/_ov3Bar2VUSSSLMcESANF_image.png)

If you prefer to build a custom UI, you can use the `ConsentManagerBuilder` component. View the [Github repo](https://github.com/segmentio/consent-manager) for complete installation instructions.

## Installing the package

First, verify you have Segment's Analytics.js installed. Segment's npm package `@segment/analytics-next` is [not currently compatible](https://github.com/segmentio/consent-manager/issues/193) with the Consent Manager, so you'll need to install Segment via snippet.

Next, install the `@segment/consent-manager` package:

:::CodeblockTabs
yarn

```shell
yarn add @segment/consent-manager
```

npm

```shell
npm install @segment/consent-manager
```
:::

Be sure to remove `analytics.load("YOUR_WRITE_KEY")`  from your site code, so the Consent Manager can handle loading.

## Adding the `ConsentManager` React component

Chord's Next.js starter includes a [ConsentManagerWrapper](https://github.com/chordcommerce/nextjs-starter-autonomy/blob/main/src/components/Segment/ConsentManager/index.jsx) component. This component is responsible for configuring and rendering a banner (or pop-up, depending on your level of customization) that will offer users an option to opt in or out of tracking. To customize the look and behavior of the Consent Manager, change various properties on the `ConsentManager` component (full reference [here](https://github.com/segmentio/consent-manager#consentmanager-props)).

:::hint{type="info"}
Please note that the Consent Manager banner in the starter is shown automatically for visitors from the EU. Please refer to the `shouldRequireConsent` method of the component to alter that behavior. You can decide to show the banner for all visitors, regardless of their actual location, by configuring the `SEGMENT_SHOULD_REQUIRE_CONSENT` environment variable to `true` in your `.env` file.&#x20;
:::

The `ConsentManagerWrapper` component wraps the root page element of the starter in [`_app.js`](https://github.com/chordcommerce/nextjs-starter-autonomy/blob/main/pages/_app.js). The starter also includes an [example](https://github.com/chordcommerce/nextjs-starter-autonomy/blob/main/src/components/Footer/Legal/index.jsx) of a link that will open the Consent Manager pop-up.

:::hint{type="success"}
if you have any questions or need help, please reach out to us at [help@chord.co](mailto\:help@chord.co)
:::

