Consent Manager
Installation
Step 1. Define the ConsentManagerConfig function (or object) to configure the widget:
<script type="text/javascript">
window.ConsentManagerConfig = () => ({
country: 'US',
env: 'prod',
target: '#consent-manager-widget'
});
</script>
Step 2. Add the target container for the banner and preference center:
<div id="consent-manager-widget"></div>
Step 3. Add the widget script tag to your index.html file, after your target element and configuration snippet. The script must be loaded as an ES module:
<script type="module" src="https://consent.chick-fil-a.com/consent-manager.js"></script>
That's it! Open your site in an Incognito tab to see the cookie banner appear.
Performance Considerations
The Consent Manager Widget is designed to be easy to install, so it automatically downloads React and other dependencies on startup. This works great for most static websites, but what about websites that happen to use React?
For these sites, React dependencies would be downloaded twice, which could negactively impact performance. The Consent Manager widget supports preloading dependencies to address this scenario.
To preload dependencies, update your config to include a new dependencies object. Here's an example:
<script type="module">
const dependencies = loadDependencies();
window.ConsentManagerConfig = () => ({
country: 'US',
env: 'prod',
target: '#root',
dependencies,
})
async function loadDependencies() {
const [react, reactDom, reactDomClient, reactJsxRuntime] = await Promise.all([
import('https://esm.sh/react@19.2.1'),
import('https://esm.sh/react-dom@19.2.1'),
import('https://esm.sh/react-dom@19.2.1/client'),
import('https://esm.sh/react@19.2.1/jsx-runtime'),
]);
return {
react,
reactDom,
reactDomClient,
reactJsxRuntime,
}
}
</script>
Reference
SDK Methods
The window.ConsentManager object exposes a simple JavaScript SDK with the following methods:
| Method | Description |
|---|---|
| openPreferenceCenter() | Opens the Consent Manager Preference Center UI, allowing users to review and update their consent preferences. |
| refreshConfig() | Reads the latest config from window.ConsentManagerConfig and re-renders the UI. |
Config Options
The window.ConsentManagerConfig property can be a config object or a function that returns a config object. The config object supports the following options:
| Property | Type | Required | Description |
|---|---|---|---|
| country | 'US' | 'CA' |
Yes | The country code that determines localization and applicable consent regulations. |
| env | 'prod' | 'qa' |
No | The environment in which the Consent Manager is running. Defaults to 'prod' if not specified. |
| target | HTMLElement | string |
Yes | The DOM element or selector where the Consent Manager widget will be rendered. |
| user | User |
No | The user information object, containing authentication and identification details. |
| dependencies | Dependencies |
No | An object containing React, ReactDom, and other required dependencies. |
| adapter | Adapter |
No | Custom functions for reading and writing consent preferences. When both getPreferences and setPreferences are provided, they replace the default consent storage behavior. |
The User interface supports the following required properties:
| Property | Type | Description |
|---|---|---|
| cfaId | string |
The user's Chick-fil-A ID. |
string |
The user's email address. | |
| accessToken | string |
The user's access token for API authentication. |
The Dependencies interface supports the following required properties:
| Property | Type | Description |
|---|---|---|
| react | module |
The react module |
| reactDom | module |
The react-dom module |
| reactDomClient | module |
The react-dom/client module |
| reactJsxRuntime | module |
The react/jsx-runtime module |
The Adapter object supports the following required properties:
| Property | Type | Description |
|---|---|---|
| getPreferences | () => Promise<CookiePreferences | undefined> |
Returns the current consent choices, or undefined if the user has not set preferences yet. Keys are cookie category IDs; values are whether each category is allowed. |
| setPreferences | (preferences: CookiePreferences) => Promise<void> |
Persists the user’s consent choices when they save from the banner or preference center. |
The CookiePreferences object is a Record<string, boolean>, where each key is a category ID and each value indicates if tracking is opted in or out.
Classes and Test IDs
A unique data-testid attribute and class is added to every consent manager component to support CSS targeting.
| Component | Test ID | Classes |
|---|---|---|
| Modal | consent-manager-modal | .consent-manager .consent-manager-modal |
| Modal Footer | consent-manager-modal-footer | .consent-manager-modal-footer |
| Modal Save | consent-manager-modal-save | .consent-manager-modal-action |
| Modal Reject All Button | consent-manager-modal-reject-all | .consent-manager-modal-action |
| Modal Accept All Button | consent-manager-modal-accept-all | .consent-manager-modal-action |
| Banner | consent-manager-banner | .consent-manager .consent-manager-banner |
| Banner Footer | consent-manager-banner-footer | .consent-manager-banner-footer |
| Banner Open Button | consent-manager-banner-open-preferences | .consent-manager-banner-action |
| Banner Reject All Button | consent-manager-banner-reject-all | .consent-manager-banner-action |
| Banner Accept All Button | consent-manager-banner-accept-all | .consent-manager-banner-action |
Note: be sure to target the attribute data-testid (e.g. [data-testid="consent-manager-modal"]) for the Test ID values listed above.