Consent Manager

Code examples:


1. Request Consent Info Update 

Default

Consent manager SDK can be synchronized at any moment of the application lifecycle. We recommend to synchronize it at application launch. Multiple synchronization calls are allowed.

Required parameter is appKey - Appodeal API Key and ConsentInfoUpdateListener - listener for result request.

Optional parameter is url  (string) - Custom consent manager server URL for the request.

/// Initialisation 

ConsentManager consentManager = ConsentManager.getInstance();

consentManager.requestConsentInfoUpdate(appKey, this);

After request completion, you can receive information about the previous user consent and regulation zone. Before request these parameters are undefined

// Get manager
ConsentManager consentManager = ConsentManager.getInstance();

// Get consent object for Appodeal SDK
Consent consent = consentManager.getConsent();

// Check regulation
Consent.Zone consentZone = consentManager.getConsentZone();

// Check consent status
Consent.Status consentStatus = consentManager.getConsentStatus();

// Get consent string
String iabString = consentManager.getIabConsentString();

You can check whether to show a Consent Dialog or not. Before request these parameters are undefined

// Get manager
ConsentManager consentManager = ConsentManager.getInstance();

// Get current ShouldShow status
Consent.ShouldShow consentShouldShow = consentManager.shouldShowConsentDialog();

if (consentShouldShow == Consent.ShouldShow.TRUE){
    // show dialog
}

Advanced

You can force consent manager to write iAB keys in SharedPreference by setting up storage property before the request to ConsentManager.Storage

SDK does not remove iAB keys from SharedPreference and only overrides them

// Store IAB strings in SharedPreference
// NOTE: should be called before request

// Get manager
ConsentManager consentManager = ConsentManager.getInstance();

// Set storage
consentManager.setStorage(ConsentManager.Storage.SHARED_PREFERENCE);

// Get storage
ConsentManager.Storage iabStorage = consentManager.getStorage();


You can register yourself as a vendor before request. 

ParameterTypeDescription
nameStringDisplay name. Will be displayed in the consent window
bundleString Custom string to check consent result for the vendor
policyUrlStringPolicy URL
purposeIdsArray of integersiAB purposes ids array
featureIdsArray of integersiAB features ids array
legitimateInterestPurposeIdsArray of integersiAB leg int purposes ids array
// Register custom vendor (will be displayed on consent window)
// should be called before request

// Get manager
ConsentManager consentManager = ConsentManager.getInstance();

// Create custom vendor
Vendor customVendor = new Vendor.Builder(
                    "Custom Vendor",
                    "customvendor",
                    "https://customvendor.com")
                .setPurposeIds(new List<int> {1, 2, 3})
                .setFeatureId(new List<int> {1, 2, 3})
                .setLegitimateInterestPurposeIds(new List<int> {1, 2, 3})
                .build();

// Set custom vendor
consentManager.setCustomVendor(customVendor);

// Get by bundle
consentManager.getCustomVendor("customvendor");

2. Show Consent window

SDK allows calling consent window API only after request 

After the SDK requests, you can build and load the consent window. Loading allowed in any regulation zone and independent from previous consent.

ConsentForm consentForm = new ConsentForm.Builder().withListener(this).build();
consentForm?.load();

You can check that the consent window is ready or not

// Indicates that consent window ready to present
boolean loaded = consentForm.isLoaded();

You can check that the consent window is showing or not

// Indicates that consent window is showing
boolean showing = consentForm.isShowing();

After consent window Is ready you can show it as Activity or Dialog

// Show consent dialog as Activity
consentForm.showAsActivity();

// Show consent dialog as Dialog
consentForm.showAsDialog();

Handling presentation callbacks

#region ConsentFormListener

public void onConsentFormLoaded() { print("ConsentFormListener - onConsentFormLoaded");}

public void onConsentFormError(ConsentManagerException exception) { print($"ConsentFormListener - onConsentFormError, reason - {exception.getReason()}");}

public void onConsentFormOpened() { print("ConsentFormListener - onConsentFormOpened");}

public void onConsentFormClosed(Consent consent) { print($"ConsentFormListener - onConsentFormClosed, consentStatus - {consent.getStatus()}");}

#endregion

3. Error handling

All returned errors are Exception instances with custom codes:

ConsentManagerErrorCode:
CodeDescription
INTERNAL(1)Error on the SDK side. Includes JS-bridge or encoding/decoding errors
NETWORKING(2)HTTP errors, parse request/response 
INCONSISTENT(3)Incorrect SDK API usage
#region ConsentInfoUpdateListener

public void onConsentInfoUpdated(Consent consent) { print("onConsentInfoUpdated");}

public void onFailedToUpdateConsentInfo(ConsentManagerException error) { print($"onFailedToUpdateConsentInfo Reason: {error.getReason()}");}

#endregion