# consent-manager-bitio **Repository Path**: mirrors_databricks/consent-manager-bitio ## Basic Information - **Project Name**: consent-manager-bitio - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-19 - **Last Updated**: 2025-10-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # consent-manager [![build status](https://circleci.com/gh/segmentio/consent-manager.svg?style=svg&circle-token=d3a9e0da7a07fb443f1b4e558ad9c60a55dca223)](https://circleci.com/gh/segmentio/consent-manager) > Drop-in consent management plugin for analytics.js [StoryBook](https://segmentio.github.io/consent-manager/index.html) - [Segment Consent Manager](#segment-consent-manager) - [Features](#features) - [Usage](#usage) - [Standalone Script](#standalone-script) - [Options](#options) - [Globals](#globals) - [Callback Function](#callback-function) - [ConsentManager](#consentmanager) - [Install](#install) - [Example](#example) - [Example in Next.js](#example-in-next.js) - [ConsentManager Props](#consentmanager-props) - [ConsentManagerBuilder](#consentmanagerbuilder) - [Install](#install-1) - [Example](#example-1) - [ConsentManagerBuilder Props](#consentmanagerbuilder-props) - [ConsentManagerBuilder Render Props](#consentmanagerbuilder-render-props) - [Utility functions](#utility-functions) - [Setting Custom Anonymous ID](#setting-custom-anonymous-id) - [Development](#development) - [Publishing New Version](#publishing-new-version) - [License](#license) ## Segment Consent Manager The Segment Consent Manager is an analytics.js add-on with support to consent management. At its core, the Consent Manager empowers your visitors to control and customize their tracking preferences on a website. They can opt out entirely of being tracked, or selectively opt out of tools in which they don’t want their information stored. It works by taking control of the analytics.js load process to only load destinations that the user has consented to and not loading analytics.js at all if the user has opted out of everything. The user's tracking preferences are saved to a cookie and sent as an identify trait (if they haven't opted out of everything) so that you can also access them on the server-side and from destinations (warehouse). _Segment works to ensure the Consent Manager Tech Demo works with most of our product pipeline. We cannot ensure it works in your specific implementation or website. Please contact our Professional Services team for implementation support. Please see the License.txt included._ _Please note, Consent Manager is not currently compatible with [Personas](https://segment.com/docs/personas/). Personas may send user data to destinations the user has explicitly opted out of for data collection._ ### Features - Give users the ability to opt-in or opt-out to tracking. - Fine grained control of tools or categories used for tracking. - 30s setup with a drop in script tag. - Or fully customizable UI/UX through React components. - EU traffic detection through [@segment/in-eu][ineu]. - Ability for visitors to reconsent and change preferences. - Automatically updates to reflect the destinations you have enabled in Segment. - **5.0.0**: Consent Manager will add consent metadata to the context of all track calls: Track call message payloads will be extended to include Consent metadata in the `context` object: ```js { "context": { "campaign": {}, "consent": { "categoryPreferences": { "Amplitude": true, "Customer.io": true, "Google Analytics": true, "Webhooks": true }, "defaultDestinationBehavior": "disable", "destinationPreferences": { "Amplitude": true, "Customer.io": true, "Google Analytics": true, "Webhooks": true } } }, "event": "Send Track Event Clicked", "integrations": { "All": false, "Amplitude": true, "HubSpot": false, "Salesforce": false, "Segment.io": true } } ``` **Breaking Changes:** Version 5.0.0 and above require that your analytics.js snippet include the method `addSourceMiddleware` in the `analytics.methods` array: ```js analytics.methods = [ 'trackSubmit', 'trackClick', 'trackLink', 'trackForm', 'pageview', 'identify', 'reset', 'group', 'track', 'ready', 'alias', 'debug', 'page', 'once', 'off', 'on', 'addSourceMiddleware' // This method is necessary for Consent Manager to forward consent metadata. ] ``` ## Usage The Segment Consent Manager can be used in several ways, depending on how custom you want your visitor's experience to be. To get started, make sure you're using the latest version of the [analytics.js snippet][] (4.1.0 or above) and remove the `analytics.load("YOUR_WRITE_KEY");` call (so the consent manager can manage the loading process). Then continue onto one of the implementation methods below. ### Standalone Script The standalone script is a prebuilt bundle that uses the [ConsentManager][] React component with [Preact][] (a lightweight React alternative). It's best for if you want to get up and running quickly or you don't have a preexisting React setup. Include the consent manager script tag after your analytic.js snippet and add your own custom copy. The standalone script can be configured in one of two ways, via data attributes for simple usage or via a global callback function for advanced usage. Both methods allow the consent manager script to be loaded async. #### Options All of the [ConsentManager][] options are supported with the addition of these options: ##### container **Type**: `string` [CSS selector][] to the DOM element that will host the consent banner. It should be an empty DOM element (usually a `
`) because the consent manager will replace any existing DOM elements inside it. The element must also exist on the page before the script is executed. You can also control the positioning of the consent banner by applying styles to the container element (optional). E.g: ```css #target-container { position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; } ``` ```html
``` #### Globals The following global variables are also exposed: - `consentManager.version` - Version of the consent manager. - `consentManager.openConsentManager()` - Opens the consent manager preferences dialog. - `consentManager.doNotTrack()` - Utility function that returns the user's Do Not Track preference (normalises the cross browser API differences). Returns `true`, `false` or `null` (no preference specified). - `consentManager.inEU()` - The [@segment/in-eu][ineu] `inEU()` function. - `consentManager.preferences` - Returns an instance of `PreferencesManager` with the following helper functions: - `loadPreferences` - returns the cookie value for consent preferences - `savePreferences` - allows for managing the consent cookie programatically (useful if you want to re-hydrate consent from your own database or prefill consent options) - `onPreferencesSaved(callback)` - allows for subscribing to changes in preferences. #### Callback Function All the options are supported. The callback function also receives these exports: - `React` - Reference to the [Preact][] library (the API is React compatible). Useful for if you need to use virtual DOM in your content. - `version` - Version of the consent manager. - `openConsentManager()` - Opens the consent manager preferences dialog. - `doNotTrack()` - Utility function that returns the user's Do Not Track preference (normalises the cross browser API differences). Returns `true`, `false` or `null` (no preference specified). - `inEU()` - The [@segment/in-eu][ineu] `inEU()` function. - `consentManager.preferences` - Returns an instance of `PreferencesManager` with the following helper functions: - `loadPreferences` - returns the cookie value for consent preferences - `savePreferences` - allows for managing the consent cookie programatically (useful if you want to re-hydrate consent from your own database or prefill consent options) - `onPreferencesSaved(callback)` - allows for subscribing to changes in preferences. ```html ``` ### ConsentManager The `ConsentManager` React component is a prebuilt consent manager UI (it's the one we use on https://segment.com) that uses the [ConsentManagerBuilder][] component under the hood. To use it, just mount the component where you want the consent banner to appear and pass in your own custom copy. _Note: Consent Manager is React-based so is not currently compatible with other frameworks such as Vue.js or Angular. In case you want to use it in another framework that is not React, you should use the Standalone implementation._ #### Install Using npm: ``` npm install @segment/consent-manager ``` Using yarn: ``` yarn add @segment/consent-manager ``` #### Example ```javascript import React from 'react' import { ConsentManager, openConsentManager } from '@segment/consent-manager' import inEU from '@segment/in-eu' export default function() { const bannerContent = ( We use cookies (and other similar technologies) to collect data to improve your experience on our site. By using our website, you’re agreeing to the collection of data as described in our{' '} Website Data Collection Policy . ) const bannerSubContent = 'You can change your preferences at any time.' const preferencesDialogTitle = 'Website Data Collection Preferences' const preferencesDialogContent = 'We use data collected by cookies and JavaScript libraries to improve your browsing experience, analyze site traffic, deliver personalized advertisements, and increase the overall performance of our site.' const cancelDialogTitle = 'Are you sure you want to cancel?' const cancelDialogContent = 'Your preferences have not been saved. By continuing to use our website, you՚re agreeing to our Website Data Collection Policy.' return (
) } ``` #### Example in Next.js In Next.js we do not have an html file where to inject the script. Here we will use the Script component to inject the snippet provided by Segment. ```javascript import React from 'react' import Script from 'next/script' import { ConsentManager, openConsentManager } from '@segment/consent-manager' export default function Home() { const bannerContent = ( We use cookies (and other similar technologies) to collect data to improve your experience on our site. By using our website, you’re agreeing to the collection of data as described in our{' '} Website Data Collection Policy . ) const bannerSubContent = 'You can change your preferences at any time.' const preferencesDialogTitle = 'Website Data Collection Preferences' const preferencesDialogContent = 'We use data collected by cookies and JavaScript libraries to improve your browsing experience, analyze site traffic, deliver personalized advertisements, and increase the overall performance of our site.' const cancelDialogTitle = 'Are you sure you want to cancel?' const cancelDialogContent = 'Your preferences have not been saved. By continuing to use our website, you՚re agreeing to our Website Data Collection Policy.' return (