Global Settings

The MobileAds class provides global settings for the Google Mobile Ads SDK.

Raise ad events on the Unity main thread

The Google Mobile Ads SDK raises events on a different thread than the Unity main thread. If you implement ad events and interact with Unity objects, you must synchronize the Mobile Ads SDK events with the Unity main thread.

If you would like the Mobile Ads SDK to handle this threading concern for you, set MobileAds.RaiseAdEventsOnUnityMainThread to true. This forces the SDK to raise all events and callbacks on the Unity main thread.

...
using GoogleMobileAds.Api;
...
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
    public void Start()
    {
        // When true all events raised by GoogleMobileAds will be raised
        // on the Unity main thread. The default value is false.
        MobileAds.RaiseAdEventsOnUnityMainThread = true;
    }
}

Video ad volume control

If your app has its own volume controls, such as custom music or sound effect volumes, disclosing app volume to the Google Mobile Ads SDK enables video ads to respect app volume settings. This ensures users receive video ads with the expected audio volume.

The device volume, controlled through volume buttons or OS-level volume slider, determines the volume for device audio output. However, apps can independently adjust volume levels relative to the device volume to tailor the audio experience.

You can report the relative app volume to the Google Mobile Ads SDK by calling the SetApplicationVolume() method. Valid ad volume values range from 0.0 (silent) to 1.0 (current device volume). Here's an example of how to report the relative app volume to the SDK:

// Set app volume to be half of current device volume.
MobileAds.SetApplicationVolume(0.5f);

To inform the SDK that the app volume has been muted, use the SetApplicationMuted() method:

// Set app to be muted.
MobileAds.SetApplicationMuted(true);

By default, the app volume is set to 1, the current device volume, and the app is not muted.

If your app has special requirements, you can set the optional ApplicationPreferences key gad_has_consent_for_cookies to zero to enable limited ads (LTD):

// Enable limited ads (LTD)
ApplicationPreferences.SetInt("gad_has_consent_for_cookies", 0);

Android minification

This Unity publishing option lets you enable java code minification. If you enable minification you will also need to create a custom proguard file to keep classes referenced by the SDK.

  1. Enable Custom Proguard File

    Go to Project Settings > Player > Android > Publishing Settings > Build, and select:

    • Custom Proguard File
  2. Open /Assets/Plugins/Android/proguard-user.txt and add the following:

-keep class com.google.** { public *; }

Disable crash reporting

The Google Mobile Ads SDK collects crash reports for debugging and analysis purposes. You can disable this crash reporting with the following code. The following sections describe how to disable crash reporting on Android and iOS.

Android

Add the <meta-data> tag with DISABLE_CRASH_REPORTING set to true in your app's AndroidManifest.xml file:

<manifest>
   <application>
       <meta-data
           android:name="com.google.android.gms.ads.flag.DISABLE_CRASH_REPORTING"
           android:value="true" />
   </application>
</manifest>

iOS

Call the DisableSDKCrashReporting method to disable crash reports on iOS:

void Awake() {
  MobileAds.DisableSDKCrashReporting();
}