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.
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 sectiondomain
: String – The domain for iubenda CDNlanguage
: String – The language code (e.g., “EN”, “IT”, “DE”, etc)appName
: String – The name of your app, used only for reporting purposesjsonConfig
: 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"
)
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)
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:
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)
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"
}
Opens the consent layer. It makes a network call to our backend, consuming one pageview in the process. It will display the consent layer allowing the user to either Accept All or Reject All of the choices, or, depending on the jumpToSettings parameter, allow them to control the consents in a more granular way.
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}"
}
}
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)")
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.
Parameters:
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")
}
}
Checks if consent has been given for a specific purpose and this consent is stored on the device. It checks the UserDefaults area for the consents accepted or rejected, and filter the ID passed as a parameter, returning true if the consent was accepted or false otherwise.
Parameters:
id
: String – The ID of the purpose to checkReturns: 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"
}
Accepts consent for all purposes and vendors, consuming one pageview in the process. It makes a network call to our backend via a message injected on the WebView, which will trigger the acceptance of all the consents, according to the CMP configuration. This information will only be available to the other methods after the callback returns a success or failure, which means it was succesfully processed by our backend and persisted on the device.
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}"
}
}
Accepts consent for specified purposes, consuming one pageview in the process. It makes a network call to our backend via a message injected on the WebView, which will trigger the acceptance of the determined purposes passed as a parameter, according to the CMP configuration. This information will only be available to the other methods after the callback returns a success or failure, which means it was succesfully processed by our backend and persisted on the device.
Parameters:
purposes
: List<String> – A list of purpose IDs to acceptupdatePurpose
: Boolean – Whether to update related purposescompletion
: A closure called when the operation completes, returning either a failure or a successReturns: None
Example:
cmpManager.acceptPurposes(listOf("2", "3"), true) { result ->
result.onSuccess {
toastMessage = "Purposes enabled"
}.onFailure { error ->
toastMessage = "Error: ${error.message}"
}
}
Imports consent information from a CMP string. This will receive a plain string containing the consent data, usually obtained through the exportCMPInfo
method. This information is persisted in the SharedPreferences area of the device, and at the same time is sent to our backend via a message injected in the WebView, consuming one pageview in the process.
Parameters:
cmpString
: String – The CMP string to importcompletion
: A closure called when the operation completes, returning either a failure or successReturns: None
Example:
val cmpString = "Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw"
cmpManager.importCMPInfo(cmpString) { result ->
result.onSuccess {
toastMessage = "Vendors Enabled"
}.onFailure { error ->
toastMessage = "Error: ${error.message}"
}
}
Rejects consent for all purposes and vendors, consuming one pageview in the process. It makes a network call to our backend via a message injected on the WebView, which will trigger the rejection of all the consents, according to the CMP configuration. This information will only be available to the other methods after the callback returns a success or failure, which means it was succesfully processed by our backend and persisted on the device.
Parameters:
completion
: A closure called when the operation completesReturns: None
Example:
cmpManager.rejectAll { result ->
result.onSuccess {
toastMessage = "All consents rejected"
}.onFailure { error ->
toastMessage = "Error: ${error.message}"
}
}
Rejects consent for specified purposes, consuming one pageview in the process. It makes a network call to our backend via a message injected on the WebView, which will trigger the rejection of the determined purposes passed as a parameter, according to the CMP configuration. This information will only be available to the other methods after the callback returns a success or failure, which means it was succesfully processed by our backend and persisted on the device.
Parameters:
purposes
: List<String>
– A list of purpose IDs to rejectupdateVendor
: Boolean
– Whether to update related vendorscompletion
: A closure called when the operation completesReturns: None
Example:
cmpManager.rejectPurposes(listOf("2", "3"), true) { result ->
result.onSuccess {
toastMessage = "Purposes disabled"
}.onFailure { error ->
toastMessage = "Error: ${error.message}"
}
}
Resets all consent management data. This completely erases al the SharedPreferences area entries related to consents accepted or rejected by the user. It is similar to completely removing the app from the device.
Parameters:
None
Returns: None
Example:
cmpManager.resetConsentManagementData()
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.
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
}
}
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.
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.
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.
This is triggered when the SDK faced any error, returning its code.