Unity App Implementation (SDK)

InMobi CMP is compatible with Unity version 2019.4.* and later.

CMP SDK & Configuration

Before integrating InMobi CMP into your mobile app, it must be configured on the dashboard. First, follow the Protect an App process. After completion, click the Download SDK button.

Download InMobi CMP Unity Package

Click here to download the InMobi CMP Unity Package.

Import InMobi CMP Unity Package to Project

  1. Open Unity and navigate to the Assets >> Import Package >> Custom Package.
  2. Locate and select the downloaded InMobi CMP Unity Package file. You can view the contents of the package in Unity.
  3. Select all the entries and click Import.

Add Dependency Package

  1. In Unity Editor, navigate to Window >> Package Manager.
  2. Click the plus (+) icon on the top right corner of the Package Manager window.
  3. Select Add package from git URL and enter com.unity.nuget.newtonsoft-json.
  4. Click Add.

Find Your P-CODE

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.

Start InMobi CMP

  1. In the designated method for initiating the CMP process, invoke the StartChoice() method within the ChoiceCMP class. Ensure you provide the PCode obtained from the InMobi CMP portal as an argument.
    public void StartChoice() 
    { 
        ChoiceCMP.StartChoice(pCode, false); 
    }
    
  2. Set the value for shouldDisplayIDFA to show the Allow tracking popup on iOS. By default, the value is true.

Note

By employing the StartChoice() method, the user can solely view the consent dialog during the initial launch. Subsequent launches will not display the dialog if the user has previously consented unless the user uninstalls the app or clears data on his/her Android device. The next instance the popup will appear is when modifications are made in the portal, and you specify the interval after which the popup should reappear.

Force Display Consent Popup

To forcibly display the popup, utilize the ForceDisplayUI() function.

public void ForceDisplayUI() 
{ 
    ChoiceCMP.ForceDisplayUI(); 
}

Note

After invoking the StartChoice() method, use the ForceDisplayUI() method to display the popup.

Show CCPA Consent Popup

To present the CCPA consent popup, initiate the process by calling the StartChoice() method. Subsequently, invoke the ShowCCPA() method whenever you wish to display the popup. Unlike the GDPR consent popup, the ShowCCPA() popup will appear each time the method is called.

public void ShowCCPA() 
{ 
    ChoiceCMP.ShowCCPA(); 
}

Retrieve TCString

To retrieve the TCString, employ the GetTCString() method.

public void GetTCString() 
{ 
    string TCString = ChoiceCMP.GetTCString(); 
}

Set LogLevel

You also have the option to specify the desired level of log output. The available log levels are as follows:

  • None: To disable logging entirely, set ChoiceCMP.ChoiceLogLevel to None. This represents the default log level and can be implemented as follows: ChoiceCMP.ChoiceLogLevel = ChoiceCMP.LogLevel.None;.
  • Error: To enable retrieving error logs, set ChoiceCMP.ChoiceLogLevel to Error. You can implement as follows: ChoiceCMP.ChoiceLogLevel = ChoiceCMP.LogLevel.Error;.
  • Debug: To receive debug and error logs, set ChoiceCMP.ChoiceLogLevel to Debug. You can implement as follows: ChoiceCMP.ChoiceLogLevel = ChoiceCMP.LogLevel.Debug;.

Subscribe to Callbacks

Subscribe to callbacks to monitor CMP events. Below is an example demonstrating how to subscribe to the callbacks within your class:

void Start() 
{ 
    ChoiceCMPManager.CMPDidLoadEvent += delegate (PingResult pingResult) 
    { 
        // Fired when the SDK has finished loading 
    };  

    ChoiceCMPManager.CMPDidErrorEvent += delegate (string error) 
    { 
        // Fired when SDK fails to load 
    };  

    ChoiceCMPManager.CMPDidShowEvent += delegate (PingResult pingResult) 
    { 
        // Fired when popup is shown 
    };  

    ChoiceCMPManager.CMPDidReceiveAdditionalConsentEvent += delegate (ACData acData) 
    { 
        // Fired when on receiving the Additional Consent 
    };  

    ChoiceCMPManager.CMPDidReceiveCCPAConsentEvent += delegate (string ccpaConsent) 
    { 
        // Fired when on receiving the CCPA Consent 
    };  

    ChoiceCMPManager.CMPDidReceiveIABVendorConsentEvent += delegate (TCData tcData) 
    { 
        // Fired when on receiving the IAB Vendor Consent 
    };  

    ChoiceCMPManager.CMPDidReceiveNonIABVendorConsentEvent += delegate (NonIABData nonIABData) 
    { 
        // Fired when on receiving the NON IAB Vendor Consent 
    }; 
}

Set Up Android Project

Follow the instructions below to set up the Android project for Unity:

  1. To enable the Custom Gradle Main Template, navigate to your Project Settings >> Build Settings >> Player Settings.

    You can now view the mainTemplate file in your Plugins/Android folder.

    

  1. Incorporate the following set of dependencies into your mainTemplate.gradle file:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Android UI and appcompat 
    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.code.gson:gson:2.10.1'
    implementation 'com.google.android.material:material:1.3.0' 
   
    // KTX
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1" 
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"

**DEPS**}

Setting up the iOS project

Follow the instructions below to set up the iOS project for Unity:

  1. Open Unity and navigate to File >> Build Settings. Select the iOS platform.
  2. To create the Xcode project, click File >> Build And Run.
  3. After the Xcode project is generated and opened, download the InMobi CMP iOS Framework and use the framework in the root folder of your Xcode project.
  4. Add the framework to your project (in Unity Framework and App Target).
  5. To run the project on a simulator, exclude the arm64 architecture in the Xcode build settings.
  6. Set the Enable Bitcode option to No to disable Bitcode in both the App and Unity Framework.

On This Page

Last Updated on: 19 Jul, 2024