# Managed Consent

### Introduction

AATKit’s Managed Consent is an easy way to facilitate [IAB TCF](https://iabeurope.eu/transparency-consent-framework/) compliant third-party [Consent Management Platforms](https://iabeurope.eu/tcf-for-cmps/) (CMPs) by providing a unified API and wrappers. In order to make use of Managed Consent, pass an instance of `AATManagedConsent` to your `AATConfiguration` instance while initializing AATKit.

An [ManagedConsent](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-managed-consent/index.html) instance must be initialized with:

* `cmp`: An instance of `CMP` interface. Currently, supported implementations are `CMPGoogle` ([Google CMP](/android-integration/start/consent/managed-consent/google-cmp.md)), `CMPSourcepoint` ([Sourcepoint CMP](/android-integration/start/consent/managed-consent/sourcepoint-cmp.md)), and `CMPAppConsent` ([SFBX (AppConsent) CMP](/android-integration/start/consent/managed-consent/sfbx-appconsent-cmp.md))  &#x20;
* `context`: An Context instance (Activity, Application)
* `delegate`: An instance of an object that implements [ManagedConsentDelegate](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-managed-consent/-managed-consent-delegate/index.html) interface.

Also, the app needs to trigger the presentation of the CMP by calling `showIfNeeded`. The CMP will only appear if user consent wasn’t asked for recently or is outdated.

{% tabs %}
{% tab title="Java" %}

```java
AATKitConfiguration configuration = new AATKitConfiguration(this);
configuration.setDelegate(this);
CMP cmp = <INSTANCE OF CMPGoogle or CMPSourcepoint or CMPAppConsent>;
ManagedConsent managedConsent = new ManagedConsent(cmp, this, this, ManagedConsent.ShowIfNeededSetting.ALWAYS);
configuration.setConsent(managedConsent);
AATKit.init(configuration);
...
managedConsent.showIfNeeded(<ActivityInstance>);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val configuration = AATKitConfiguration(this)
configuration.delegate = this
val cmp: CMP = <INSTANCE OF CMPGoogle or CMPSourcepoint or CMPAppConsent>
val managedConsent = ManagedConsent(cmp, this, this, ManagedConsent.ShowIfNeededSetting.ALWAYS)
configuration.consent = managedConsent
AATKit.init(configuration)

managedConsent.showIfNeeded(<ActivityInstance>)
```

{% endtab %}
{% endtabs %}

Added to this, your app must provide a way for the user to edit once given consent settings, e.g. by providing a button in the app’s “Privacy Settings”. This button must trigger `editConsent`.

Also, your instance of the respective CMP used must be set up at its respective backend/dashboard. Please refer to your CMP’s documentation or contact our support.

### Managed Consent States

When the user finishes his consent choice, you can check the consent status via the [ManagedConsentDelegate](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-managed-consent/-managed-consent-delegate/index.html)'s method: `managedConsentCMPFinished(state: ManagedConsentState)` where [ManagedConsentState](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-managed-consent/-managed-consent-state/index.html) is an enum with the available (non-IAB) consent states. This shall facilitate a more easy understanding of the complex IAB consent string and is only used for internal purposes (e.g. reporting).

### Re-asking for consent if rejected

If you would like to periodically re-ask users that rejected consent, you can use method `showIfNeededOrRejected(daysAgo: Int, activity: Activity)` instead of `showIfNeeded`. In addition to normal `showIfNeeded` behaviour, it will check consent state and timestamp of last consent string update. If the consent is rejected and last update happened more than `daysAgo`, consent dialog will be shown again.

### Consent Opt-in Status

To set Consent opt-in status, you need to pass `showIfNeededSetting` to `ManagedConsent` while initializing.

* `showIfNeededSetting` can be one of the following:
  * `ALWAYS`:  always show the CMP.
  * `NEVER`: never show the CMP, However, the publisher can still call the  `editConsent` API.
  * `SERVER_SIDE_CONTROL`: showing the CMP will be based on the dashboard configurations.
* It has a default value of: `SERVER_SIDE_CONTROL`.

To check the server-side consent opt-in status call `AATKit.isConsentOptIn()`, which only returns meaningful information after AATKit was successfully initialized (and did download its mediation rules from the backend (If you want to observe this, see [AATKit.Delegate](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-a-a-t-kit/-delegate/index.html))).

### Code Examples

* [Example using Google CMP](/android-integration/start/consent/managed-consent/google-cmp.md#usage).
* [Example using Sourcepoint CMP.](/android-integration/start/consent/managed-consent/sourcepoint-cmp.md)
* [Example using SFBX (AppConsent) CMP.](/android-integration/start/consent/managed-consent/sfbx-appconsent-cmp.md)


---

# 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://aatkit.gitbook.io/android-integration/start/consent/managed-consent.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.
