MoPub SDK Initialization

The MoPub 5.0 SDK introduces a new API for initialization called MoPub.InitializeSdk(). This API is required for a number of new functionalities, including:

v5.0.0 to v5.4.1:

  • GDPR consent mechanisms
  • Rewarded video pre-initialization

v5.5.0 and above:

  • GDPR consent mechanisms
  • Mediation SDKs initialization
  • Logging
  • Advanced Bidding
  • Legitimate Interest


You only need to initialize once using any valid ad unit ID from your app. Ad requests should only be made once the SDK initialization has completed.

  1. In your app’s Start(), instantiate a MoPub.SdkConfiguration object with any valid ad unit ID from your app, your mediation settings (optional), (optional) log level, (optional) map of configurations for networks, and (optional) a list of adapter configuration class names to initialize.
  2. Call MoPub.InitializeSdk() and pass in the MoPub.SdkConfiguration object.

Network SDK initialization

SDK initialization will automatically attempt to initialize all known networks. However, publishers will be given the option to specify additional networks via the SDK configuration object as shown in the example below. Note: you can use NetworkConfiguration to pass network configurations required for pre-initialization. Otherwise, your first attempt to pre-initialize mediated networks will be a no-op because no network data is cached at this point. All subsequent attempts to pre-initialize should succeed for the duration of the app’s lifecycle.

Logging Information

The MoPub 5.5.0 SDK enhances the logging experience to include more detailed information such as adapter version, SDK version and ad life cycle events and operations. You can set Debug, Info or None using MoPubBase.LogLevel during initialization.

Legitimate Interest

The MoPub SDK 5.5.0 now enables mediated networks to collect your user’s personal data based on legitimate interest basis when publishers opt-in. For more details read here. You can enable the legitimate interest flag using the API AllowLegitimateInterest during initialization.


private void Start()
        // NOTE: the MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first.
        var anyAdUnitId = _bannerAdUnits[0];
        MoPub.InitializeSdk(new MoPub.SdkConfiguration {
            AdUnitId = anyAdUnitId,

            // Set desired log level here to override default level of MPLogLevelNone
            LogLevel = MoPubBase.LogLevel.MPLogLevelDebug,

            // Uncomment the following line to allow supported SDK networks to collect user information on the basis
            // of legitimate interest.
            //AllowLegitimateInterest = true,

            // Specify the mediated networks you are using here:
            MediatedNetworks = new MoPub.MediatedNetwork[]
                // Example using AdMob.  Follow this template for other supported networks as well.
                // Note that keys must be strings, and values must be JSON-serializable (strings only, for MoPubRequestOptions).
                new MoPub.SupportedNetwork.AdMob
                    // Network adapter configuration settings (initialization).
                    NetworkConfiguration = {
                        { "key1", value },
                        { "key2", value },

                    // Global mediation settings (per ad request).
                    MediationSettings = {
                        { "key1", value },
                        { "key2", value },

                    // Additional options to pass to the MoPub servers (per ad request).
                    MoPubRequestOptions = {
                        { "key1", "value" },
                        { "key2", "value" },

                // Example using a custom network adapter:
                new MoPub.MediatedNetwork
                    // Specify the class name that implements the AdapterConfiguration interface.
                #if UNITY_ANDROID
                    AdapterConfigurationClassName = "classname",  // include the full package name
                #else // UNITY_IOS
                    AdapterConfigurationClassName = "classname",

                    // Specify the class name that implements the MediationSettings interface.
                    // Note: Custom network mediation settings are currently not supported on Android.
                #if UNITY_IOS
                    MediationSettingsClassName = "classname",

                    // Fill in settings and configuration options the same way as for supported networks:

                    NetworkConfiguration = { ... },

                #if UNITY_IOS  // See note above.
                    MediationSettings    = { ... },

                    MoPubRequestOptions  = { ... },

Last updated February 04, 2019

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2018 MoPub Inc.