# Custom Consent Manager

Freshpaint supports integrating with a custom consent manager in order to ensure you are respecting your users' data privacy choices while still being able to leverage Freshpaint for sending data to your preferred marketing and advertising platforms.

### Prerequisites

This guide assumes you have already set up the Freshpaint Javascript SDK and set up at least one data destination in the Freshpaint app. If not, follow these guides to get set up

* [Installing the Freshpaint Javascript SDK](https://documentation.freshpaint.io/readme/guides/quickstart/installing-freshpaint)
* [Configuring a Destination](https://documentation.freshpaint.io/readme/guides/quickstart/configuring-a-destination)

### Installation

There are 2 steps to integrating the Freshpaint SDK with your consent manager:

1. Initialize Freshpaint with the default (or most recent) consent choices
2. Set up an event listener to update the user's consent elections whenever they change

To ensure that the Freshpaint SDK loads with the default consent, we need to pass in that consent object at initialization like so:

```javascript
freshpaint.init("<environment_id>", {
  "consent_management": {
    "initial_consent": {
      "All": false,
      "Mixpanel": true
    }
  }
})
```

The `initial_consent` object follows the same pattern as the [Integrations Object](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#using-the-integrations-object).&#x20;

Secondly, to ensure that changes to your user's consent are respected, you must set up an event listener on consent changes to update this consent object.

```javascript
// if your consent manager has a built-in event listener hook
consentmanager.addEventListener("onConsentSaved", function (consentObject) {
  // add internal mapping from consent manager to freshpaint destinations here
  const fpConsentObject = mapConsentToFP(consentObject)
  freshpaint.set_consent(fpConsentObject)
})

// otherwise
window.addEventListener("onConsentSaved", function () {
  // add internal mapping from consent manager to freshpaint destinations
  const fpConsentObject = mapConsentToFP(consentmanager.getConsent())
  freshpaint.set_consent(fpConsentObject)
})
```

### Using the Consent Object

You can pass a consent object into the `freshpaint.init` function call to set a default/initial state for the user's consent.

To limit which destinations a user's data is sent to, set `All: false` to ensure user events are not sent to any destinations unless the destination is explicitly set to true.&#x20;

Example:

```javascript
{
  "All": false,
  "Mixpanel": true,
  "Facebook Conversions API": false
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.freshpaint.io/integrations/consent-management/custom-consent-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
