Documentation

Table of Contents

iubenda SDK v3.5 – Android – API documentation

The CMPManager class provides methods to manage user consent for data processing and tracking. This documentation covers the main methods available for mobile app integration.

Initialization

UrlConfig()

Sets the URL configuration for the iubenda SDK. Needs to be initialized with the value below, and passed to the getInstance method. 

Parameters:

  • id: String – Your site-specific configuration retrieved on the embedding section of your Privacy Controls and Cookie Solution embedding section
  • domain: String – The domain for iubenda CDN
  • language: String – The language code (e.g., “EN”, “IT”, “DE”, etc)
  • appName: String – The name of your app, used only for reporting purposes
  • jsonConfig: JSON Object – Optional, can be useful to inject a local configuration direcl inside the mobile SDK 

Example:

val urlConfig = UrlConfig(
    id = "your_site_specific_id",
    domain = "cdn.iubenda.com",
    language = "EN",
    appName = "CMDemoAppKotlin"
)

setActivity()

Sets the Activitythat will present the consent layer. It should be a ComponentActivity

Parameters:

  • viewController: ComponentActivity – The Activity where the consent layer will be presented.
CMPManager.shared.setPresentingViewController(self)

getUserStatus()

Returns a detailed snapshot of the user’s current consent status and preferences. This method provides comprehensive information about the user’s consent choices, including their overall consent status, individual vendor permissions, purpose-specific consents, and relevant consent strings.

Parameters:

  • None

Returns:

Return Type: CMPUserStatusResponse object, explained in the code below. 

Example:

let status = CMPManager.shared.getUserStatus()
var message = "Status: \(status.status)\n\n"

message += "Vendors:\n"
for (vendorId, state) in status.vendors {
    message += "- \(vendorId): \(state)\n"
}

message += "\nPurposes:\n"
for (purposeId, state) in status.purposes {
    message += "- \(purposeId): \(state)\n"
}

message += "\nTCF: \(status.tcf)\n"
message += "Additional Consent: \(status.addtlConsent)\n"
message += "Regulation: \(status.regulation)"

print(message)

checkAndOpen()

Checks with the server if consent is required and opens the consent layer if necessary. This will make a network call to our servers via the WKWebView created inside our SDK, consuming one pageview in the process. This network call will send a message to our backend via JavaScript, which will detect whether the device has a valid consent or not, which will in turn determine whether the consent layer needs to be displayed or not.  

Parameters:

  • jumpToSettings: A boolean value to determine whether the consent layer displayed will automatically lead to the page where a more granular control over the consents given by the users, allowing them to fine tune their choices (when set to true) or the initial default screen with the buttons (when set to false or suppressed).
  • completion: A closure called when the operation completes, with the result, either true or false.

Returns: None

Example:

cmpManager.checkAndOpen { result ->
    result.onSuccess {
	    toastMessage = "Check and Open Consent Layer operation done successfully."
    }.onFailure { error ->
    	toastMessage = "Check and Open Consent Layer operation failed with error: $error"
}

forceOpen()

Parameters:

  • jumpToSettings: A boolean value to determine whether the consent layer displayed will automatically lead to the page where a more granular control over the consents given by the users, allowing them to fine tune their choices (when set to true) or the initial default screen with the buttons (when set to false or suppressed).
  • completion: A closure called when the operation completes, returning either a sucess or an error. 

Returns: None

Example:

cmpManager.openConsentLayer { result ->
	result.onFailure { error ->
    	toastMessage = "Error: ${error.message}"
	}
}

exportCMPInfo()

Exports the current consent information stored on the device as a string. This method retrieves the consent string from the SharedPreferences area of the device, and returns it. Usually this information is passed to the importCMPInfo method.

Returns: String – The exported consent information

Example:

val cmpInfo = CMPManager.shared.exportCMPInfo()
Log.d("Exported CMP info: \(cmpInfo)")

getGoogleConsentModeStatus()

Seamlessly integrates with Consent Mode, a Google technology that enables conversion and analytics modeling, allowing Google’s services to fill in data gaps when users do not consent. This function translates the user’s consent from your CMP into a format that Firebase Analytics can understand, so you can simply get the return of this method and pass it along to Firebase .setConsent method.

  • It then updates Google Analytics with the user’s current consent status.

Parameters:

  • None

Returns: Map<String, String> – An key value array with the four Google Consent Mode keys: .analyticsStorage.adStorage.adUserData and .adPersonalization, and their respective values in terms of .choiceDoesntExist.granted or .denied.

Example:

val settings = cmpManager.getGoogleConsentModeStatus()
Log.d("CMPDemo", "Google Consent Mode Settings: $settings")
toastMessage = buildString {
  append("Google Consent Settings:")
  settings.forEach { (key, value) ->
	  append("\n$key: $value")
  }
}

getStatusForPurpose()

Parameters:

  • id: String – The ID of the purpose to check

Returns: UniqueConsentStatus – An enum with the values .choiceDoesntExist if no consent was given, .granted or .denied.

Example:

val purposeStatus = cmpManager.getStatusForPurpose("c53")
var message = "Vendor s2789's status: "
switch purposeStatus {
   	case .choiceDoesntExist: message += "No Choice"
    case .granted: message += "Granted"
    case .denied: message += "Denied"
    @unknown default: message += "No Choice"
}

acceptAll()

Parameters:

  • completion: A closure called when the operation completes, returning failure or success.

Returns: None

Example:

cmpManager.acceptAll { result ->
    result.onSuccess {
	    toastMessage = "All consents accepted"
  	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

acceptPurposes()

Parameters:

  • purposes: List<String> – A list of purpose IDs to accept
  • updatePurpose: Boolean – Whether to update related purposes
  • completion: A closure called when the operation completes, returning either a failure or a success

Returns: None

Example:

cmpManager.acceptPurposes(listOf("2", "3"), true) { result ->
	  	result.onSuccess {
	  	toastMessage = "Purposes enabled"
  	}.onFailure { error ->
  		toastMessage = "Error: ${error.message}"
    }
}

importCMPInfo()

Parameters:

  • cmpString: String – The CMP string to import
  • completion: A closure called when the operation completes, returning either a failure or success

Returns: None

Example:

val cmpString = "Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw"
cmpManager.importCMPInfo(cmpString) { result ->
	result.onSuccess {
		toastMessage = "Vendors Enabled"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

rejectAll()

Parameters:

  • completion: A closure called when the operation completes

Returns: None

Example:

cmpManager.rejectAll { result ->
	result.onSuccess {
		toastMessage = "All consents rejected"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

rejectPurposes()

Parameters:

  • purposesList<String> – A list of purpose IDs to reject
  • updateVendorBoolean – Whether to update related vendors
  • completion: A closure called when the operation completes

Returns: None

Example:

cmpManager.rejectPurposes(listOf("2", "3"), true) { result ->
    result.onSuccess {
      toastMessage = "Purposes disabled"
    }.onFailure { error ->
      toastMessage = "Error: ${error.message}"
	}
}

resetConsentManagementData()

Parameters:

None

Returns: None

Example:

cmpManager.resetConsentManagementData()

Passing consent data to third-party SDKs

updateThirdPartyConsent

This method handles the automatic passing of consent data to third-party SDKs like AppsFlyer, AdJust, Branch, Kochava, Singular, AirBridge and Tenjin. It works via introspection/reflection, so initialize the third-party SDK with your credentials using the usual strategy recommended by the provider, and our CMP SDK will detect the instance of the 3P SDK and invoke the needed methods under the hood. 

 

CMPManagerDelegate events

The SDK provides a flexible link handling mechanism that allows applications to customize how URLs within the consent layer are handled. By default, all links open within the WebView, but applications can intercept specific URLs to handle them externally when needed.

cmpManager.setOnClickLinkCallback { url ->
            if (url.contains("google.com")) {
                // Open Google URLs in external browser
                try {
                    startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
                    true // Return true to indicate we handled the URL
                } catch (e: Exception) {
                    Log.e("DemoApp", "Error opening URL: $url", e)
                    false
                }
            } else {
                // Let other URLs load in the WebView
                false
            }
        }

didReceiveConsent(consent: String, jsonObject: Map<String, Any>)

This is triggered when the consent layer was closed after the user updating his/her consents OR when invoking methods that cause changes in the consents, like acceptAll, rejectAll, acceptVendors, rejectVendors, etc. It means that the user accepted of rejected some of all of the consents, and that those were correctly saved in the device.

didShowConsentLayer

This is triggered when the consent layer was actually displayed. It means that there was not a consent valid in the device, so a new one should be collected.

didCloseConsentLayer


This is triggered when the SDK checked the need for a consent, but it was not needed and the layer was not displayed. It means that there is already a valid in the device, so a new one is not necessary and tue consent layer will not be displayed.

didReceiveError

This is triggered when the SDK faced any error, returning its code.