InMobi CMP empowers site owners to efficiently handle consent across diverse devices and environments, including Android. The InMobi CMP strictly adheres to the IAB TCF v2.2 standard.
Ensure a minimum Android version 5.0 (API 21) or higher for seamless operation. While not mandatory, we highly recommend using Android Studio 4+ for an optimal experience.
The CMP utilizes native UI components within a DialogFragment, providing an intuitive interface overlaying the current Activity.
The IAB TCF v2 mobile specifications securely store all consent data, utilizing SharedPreferences for robust data management.
We have UI customization capabilities with our SDK. This feature empowers developers to tailor color schemes and font styles for all UI components used in the InMobi CMP This ensures seamless integration with the host application's UI style. For more information on customizing styles, see UI Customization for Mobile Android.
There is an issue with the accurate display of consent rates on the Privacy Properties page. However, the complete analytical reports remain accessible through the Reports button.
Before integrating InMobi CMP into your mobile app, make sure you have followed the instructions on how to protect an app. Once done, click Download SDK.
To initialize the SDK, you must provide your account's p-code for proper identification. After you log in to the InMobi CMP portal, you can see the p-code at the top right corner of the screen. However, as shown below, you must omit the initial two characters ("p-") when copying the code for use elsewhere.
.aar
file into projects/libs
directory of your application.build.gradle
file, include the following Gradle dependencies:
implementation files('libs/inmobicmp-2.0.2.aar')
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.code.gson:gson:2.8.8'
implementation "com.iabgpp:iabgpp-encoder:3.1.1"
## InMobi CMP
-keep class com.inmobi.cmp.ChoiceCmp {public protected *;}
-keep interface com.inmobi.cmp.ChoiceCmpCallback {public protected *;}
-keep class com.inmobi.cmp.model.ChoiceError {public protected *;}
-keep class com.inmobi.cmp.model.NonIABData {public protected *;}
-keep class com.inmobi.cmp.model.PingReturn {public protected *;}
-keep class com.inmobi.cmp.core.model.ACData {public protected *;}
-keep class com.inmobi.cmp.core.model.GDPRData {public protected *;}
-keep class com.inmobi.cmp.core.model.gbc.GoogleBasicConsents {public protected *;}
-keep class com.inmobi.cmp.core.model.Vector {public protected *;}
-keep class com.inmobi.cmp.core.model.mspa.USRegulationData {public protected *;}
-keep class com.inmobi.cmp.data.model.ChoiceStyle {public protected *;}
-keep class com.inmobi.cmp.data.model.ChoiceColor {public protected *;}
-keep class com.inmobi.cmp.model.DisplayInfo {public protected *;}
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type
##---------------End: proguard configuration for Gson ----------
## AndroidX
-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }
-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.* { *; }
ChoiceCmpCallback
functionality, implement the ChoiceCmpCallback
interface.
import com.inmobi.cmp.ChoiceCmpCallback
class ChoiceSampleApp: Application(), ChoiceCmpCallback
import com.inmobi.cmp.ChoiceCmpCallback;
class ChoiceSampleApp extends Application implements ChoiceCmpCallback
ChoiceCmpCallback
, implement the required methods. For detailed best practices on callbacks, see the next section.
import com.inmobi.cmp.ChoiceCmp
import com.inmobi.cmp.ChoiceCmpCallback
import com.inmobi.cmp.core.model.ACData
import com.inmobi.cmp.core.model.GDPRData
import com.inmobi.cmp.core.model.gbc.GoogleBasicConsents
import com.inmobi.cmp.core.model.mspa.USRegulationData
import com.inmobi.cmp.model.ChoiceError
import com.inmobi.cmp.model.DisplayInfo
import com.inmobi.cmp.model.NonIABData
import com.inmobi.cmp.model.PingReturn
override fun onCCPAConsentGiven(consentString: String) {
/* code */
}
override fun onCmpError(error: ChoiceError) {
/* code */
}
override fun onCmpLoaded(info: PingReturn) {
/* code */
}
override fun onCMPUIStatusChanged(status: DisplayInfo) {
/* code */
}
override fun onGoogleBasicConsentChange(consents: GoogleBasicConsents) {
/* code */
}
override fun onGoogleVendorConsentGiven(acData: ACData) {
/* code */
}
override fun onIABVendorConsentGiven(gdprData: GDPRData) {
/* code */
}
override fun onNonIABVendorConsentGiven(nonIABData: NonIABData) {
/* code */
}
override fun onReceiveUSRegulationsConsent(usRegulationData: USRegulationData) {
/* code */
}
override fun onUserMovedToOtherState() {
/* code */
}
import com.inmobi.cmp.ChoiceCmp
import com.inmobi.cmp.ChoiceCmpCallback
import com.inmobi.cmp.core.model.ACData
import com.inmobi.cmp.core.model.GDPRData
import com.inmobi.cmp.core.model.gbc.GoogleBasicConsents
import com.inmobi.cmp.core.model.mspa.USRegulationData
import com.inmobi.cmp.model.ChoiceError
import com.inmobi.cmp.model.DisplayInfo
import com.inmobi.cmp.model.NonIABData
import com.inmobi.cmp.model.PingReturn
@Override
public void onCCPAConsentGiven(String consentString) {
// code
}
@Override
public void onCmpError(ChoiceError error) {
// code
}
@Override
public void onCmpLoaded(PingReturn info) {
// code
}
@Override
public void onCMPUIStatusChanged(DisplayInfo displayInfo) {
// code
}
@Override
public void onGoogleBasicConsentChange(GoogleBasicConsents consents) {
// code
}
@Override
public void onGoogleVendorConsentGiven(ACData acData) {
// code
}
@Override
public void onIABVendorConsentGiven(GDPRData gdprData) {
// code
}
@Override
public void onNonIABVendorConsentGiven(NonIABData nonIABData) {
// code
}
@Override
public void onReceiveUSRegulationsConsent(USRegulationData usRegulationData) {
// code
}
@Override
public void onUserMovedToOtherState() {
// code
}
Application
class's onCreate
method, add the following code snippet. The startChoice
method requires the application context, your app's package ID (matching the web portal), your p-code, a delegate object, and an optional parameter for customization styles.
import com.inmobi.cmp.ChoiceCmp
import com.inmobi.cmp.ChoiceCmpCallback
class ChoiceSampleApp : Application(), ChoiceCmpCallback {
override fun onCreate() {
super.onCreate()
ChoiceCmp.startChoice(
app = this,
packageId = "packageId",
pCode = "pCode",
callback = this
)
}
}
import com.inmobi.cmp.ChoiceCmp;
import com.inmobi.cmp.ChoiceCmpCallback;
class ChoiceSampleApp extends Application implements ChoiceCmpCallback {
@Override
public void onCreate() {
super.onCreate();
ChoiceCmp.startChoice(
this,
"packageId",
"pcode",
this,
new ChoiceStylesResources()
);
}
}
For Kotlin users, the last parameter is optional. For more details, see UI Customization for Mobile Android.
import com.inmobi.cmp.ChoiceCmp
ChoiceCmp.forceDisplayUI(activity)
import com.inmobi.cmp.ChoiceCmp;
ChoiceCmp.forceDisplayUI(activity);
The SDK actively monitors lifecycle events to ensure that consent information is readily available. If consent data is not found, the CMP will trigger automatically, prompting the user for their preferences. Subsequently, each time a user interaction with the CMP occurs, the associated callbacks will be triggered.
Implementing all three consent callbacks is imperative, even if you haven't configured all the consent features. This ensures comprehensive coverage and prevents any potential oversight in consent handling.
onIABVendorConsentGiven
method is triggered when the user consents to IAB-compliant vendors. For more information, see IAB-compliant vendors. Ideally, IAB-compliant mobile frameworks will autonomously adapt to this consent, configuring themselves accordingly. However, it's worth noting that limited IAB-compliant mobile frameworks are available. It is advisable to reach out to your vendor for further clarification. In cases where the framework is not compliant, the responsibility of handling consent falls on you. If the framework includes a setup method that is called in the onCreate
, it should be relocated to this section and executed after consent is verified. For example:
override fun onIABVendorConsentGiven(tcData: TCData) {
//Use TCData to know the consent information related to IAB vendors
}
@Override
public void onIABVendorConsentGiven(@NonNull TCData tcData) {
//Use TCData to know the consent information related to IAB vendors
}
To access the TC String from the shared preference, retrieve it by accessing the IABTCF_TCString
key from the < PackageName >_preferences
preference file upon receiving the consent.
onNonIABVendorConsentGiven
callback is triggered for vendors already configured in the portal and does not automatically verify consent. In this case, consent is provided in a binary manner: either a complete yes or no for all services. To verify consent, retrieve the specific vendor by their ID using the following method:
override fun onNonIABVendorConsentGiven(nonIABData: NonIABData) {
//Use NonIABData to know the consent information related to Non-IAB vendors
}
@Override
public void onNonIABVendorConsentGiven(@NonNull NonIABData nonIABData) {
//Use NonIABData to know the consent information related to Non-IAB vendors
}
onGoogleVendorConsentGiven
. This callback is called only if you have Google Vendors turned on in the portal. For more information about Google Vendors, see Google’s Additional Consent technical specification. Similar to the other callbacks, use this callback to manage the Google Vendors.
override fun onGoogleVendorConsentGiven(acData: ACData) {
//Use ACData to know the consent information related to Google vendors
}
@Override
public void onGoogleVendorConsentGiven(@NonNull ACData acData) {
//Use ACData to know the consent information related to Google vendors
}
While not essential, additional callbacks are available for debugging or advanced scenarios. One such callback is onCmpError
, which triggers whenever the CMP exits unexpectedly and fails to collect consent.
onReceiveUSRegulationsConsent
is triggered when the user gives consent to MSPA. Since it is opt-out by default, the callback is also triggered when the consent changes. You will get consent details in usRegulationData
.
override fun onReceiveUSRegulationsConsent(usRegulationData: USRegulationData) {
// use usRegulationData to retrieve info related to MSPA
}
@Override
public void onReceiveUSRegulationsConsent(USRegulationData usRegulationData) {
// use usRegulationData to retrieve info related to MSPA
}
onUserMovedToOtherState
is triggered when the user changes location due to which the applicable MSPA consent changes. You can re-trigger MSPA if you want new consent according to a new location.
override fun onUserMovedToOtherState() {
//use this to retrigger MSPA to renew consent
}
@Override
public void onUserMovedToOtherState() {
// Use this to retrigger MSPA to renew consent
}
After successfully initialising the SDK, present the MSPA screen by invoking the following method:
ChoiceCmp.showUSRegulationScreen(this)
ChoiceCmp.showUSRegulationScreen(this);
If you select opt-out screen notice trigger from the portal, the MSPA consent screen will be presented automatically and the corresponding consent will be taken.
Once the user has given consent, onReceiveUSRegulationsConsent
will be fired.
After initializing the SDK, present the CCPA screen by invoking the following method from ChoiceCmp
object and passing the Activity
:
import com.inmobi.cmp.ChoiceCmp
ChoiceCmp.showCCPAScreen(activity)
import com.inmobi.cmp.ChoiceCmp;
ChoiceCmp.showCCPAScreen(activity);
Once the user gives consent in the CCPA screen, you can retrieve the IABUSPrivacy_String
upon receiving the consent from the <PackageName>_preferences
preference file.
CCPA is deprecated by IAB. Use MSPA instead.
By installing this SDK update, you agree that your Children Privacy Compliance setting remains accurate or that you will update that setting, whenever there is a change in your app's audience. You may update the app's Children Privacy Compliance settings at https://publisher.inmobi.com/my-inventory/app-and-placements.