# Sourcepoint CMP

### Requirements <a href="#requirements" id="requirements"></a>

* Add the Sourcepoint CMP dependency to your build.gradle:

```
implementation 'com.sourcepoint.cmplibrary:cmplibrary:<version>'
```

Make sure, your Sourcepoint CMP has been set up at its backend dashboard. Our support recommends certain vendors to be included in your server-side setup in order to yield optimal revenues. Please also refer to your[ Sourcepoint CMP’s documentation](https://github.com/SourcePointUSA/android-cmp-app).

### Usage

Follow the instructions in the Managed Consent [introduction section](/android-integration/start/consent/managed-consent.md).

{% hint style="info" %}
Sourcepoint CMP needs an Activity instance when being created.
{% endhint %}

* Create an instance of `CMPSourcePoint` (`CMPSourcePoint` implements `CMP`interface).
* Pass the created `CMPSourcePoint` instance while creating the ManagedConsent using the `public constructor ManagedConsent(cmp: CMP, context: Context, delegate: ManagedConsent.ManagedConsentDelegate)`.

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

```java
private ManagedConsent managedConsent;

public void onActivityReady(Activity activity) {
    if (managedConsent == null) { //we want to do it only once
        CMP cmp = new CMPSourcePoint(activity, <accountId>, <propertyId>, <propertyName>, <pmId>);
        managedConsent = new ManagedConsent(cmp, this, this);
        AATKitRuntimeConfiguration newConf = new AATKitRuntimeConfiguration();
        newConf.setConsent(managedConsent);
        AATKit.reconfigure(newConf);
        managedConsent.showIfNeeded(activity);
        OR
        managedConsent.showIfNeededOrRejected(10, activity);
    }
}

// ManagedConsentDelegate implementation
@Override
public void managedConsentNeedsUserInterface(@NonNull ManagedConsent managedConsent) {
    // CMP is loaded and ready to be shown
    // Show the CMP using active Activity
    managedConsent.showIfNeeded(<ACTIVITY_INSTANCE>);
    OR
    managedConsent.showIfNeededOrRejected(10, <ACTIVITY_INSTANCE>);
}

@Override
public void managedConsentCMPFinished(@NonNull ManagedConsent.ManagedConsentState state) {
    // The user finished his action with CMP with the state as the user chosen state
}

@Override
public void managedConsentCMPFailedToLoad(@NonNull ManagedConsent managedConsent, String error) {
    // CMP failed to load with the error message.
    // Consider reloading the CMP using the active Activity:
    // managedConsent.reload(<ACTIVITY_INSTANCE>);
    // if you know that the user is in GDPR region
}

@Override
public void managedConsentCMPFailedToShow(@NonNull ManagedConsent managedConsent, String error) {
    // CMP failed to show with the error message
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
private var managedConsent: ManagedConsent? = null

fun onActivityReady(activity: Activity) {
    if (managedConsent == null) { //we want to do it only once
        val cmp: CMP = CMPSourcePoint(activity, <accountId>, <propertyId>, <propertyName>, <pmId>)
        managedConsent = ManagedConsent(cmp, this, this)
        val newConf = AATKitRuntimeConfiguration()
        newConf.consent = managedConsent
        AATKit.reconfigure(newConf)
        managedConsent?.showIfNeeded(activity)
        OR
        managedConsent?.showIfNeededOrRejected(10, activity)
    }
}

// ManagedConsentDelegate implementation
fun managedConsentNeedsUserInterface(managedConsent: ManagedConsent) {
    // CMP is loaded and ready to be shown
    // Show the CMP using active Activity
    managedConsent.showIfNeeded(<ACTIVITY_INSTANCE>)
    OR
    managedConsent.showIfNeededOrRejected(10, <ACTIVITY_INSTANCE>)
}

fun managedConsentCMPFinished(state: ManagedConsentState) {
    // The user finished his action with CMP with the state as the user chosen state
}

fun managedConsentCMPFailedToLoad(managedConsent: ManagedConsent, error: String?) {
    // CMP failed to load with the error message.
    // Consider reloading the CMP using the active Activity:
    // managedConsent.reload(<ACTIVITY_INSTANCE>);
    // if you know that the user is in GDPR region
}

fun managedConsentCMPFailedToShow(managedConsent: ManagedConsent, error: String?) {
    // CMP failed to show with the error message
}
```

{% endtab %}
{% endtabs %}


---

# 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/sourcepoint-cmp.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.
