<br />

The `MobileAds` class provides global settings for .

## Raise ad events on the Unity main thread

raises events on a different thread than the Unity
main thread. If you implement ad events and interact with Unity objects, you
need to synchronize the events with the Unity main thread.

Synchronize ad events with the Unity main thread either manually, or
automatically, by letting handle the synchronization.

### Recommended: Manually synchronize ad events

To synchronize ad events manually, use the `ExecuteInUpdate` method on the main
thread. You should use the `ExecuteInUpdate` method when interacting with
UnityEngine objects, and while the `RaiseAdEventsOnUnityMainThread` property is
disabled.

The following example logs a background thread and runs an action to interact
with UnityEngine objects:

    // Google Mobile Ads events are raised off the Unity main thread.

    // This log is executed off the Unity main thread.
    // Write all time-sensitive code before ExecuteInUpdate().
    Debug.Log("Executing off the Unity main thread.");

    // Use ExecuteInUpdate to run code on the main thread, allowing you to
    // interact with Unity UI and GameObjects.
    // Changed to fully-qualified name to resolve CS0103
    GoogleMobileAds.Common.MobileAdsEventExecutor.ExecuteInUpdate(() =>
    {
        // This callback may be delayed on Android until the user returns to the app.
        Debug.Log("Executing on the Unity main thread.");

        // Place all code that interacts with Unity UI and GameObjects inside this callback.
        if (_myGameObject != null)
        {
            _myGameObject.SetActive(true);
        }
    });

> [!IMPORTANT]
> **Important:** The Unity `Update()` loop delays all code placed inside the `ExecuteInUpdate` method. You should place all time-sensitive code, such as telemetry or [impression-level ad revenue (ILAR)](https://developers.google.com/admob/unity/impression-level-ad-revenue) *outside* the `ExecuteInUpdate` method.

### Automate synchronizing on ad events

For to synchronize ad events, set
`MobileAds.RaiseAdEventsOnUnityMainThread` property to `true`:

    ...
    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;
        }
    }

> [!WARNING]
> **Warning:** When setting `MobileAds.RaiseAdEventsOnUnityMainThread` to a `true` value, ad events triggered while your game is paused or backgrounded are delayed until the user returns to the game. If the user closes the app during this time, these delayed ad events are dropped entirely. Publishers setting `MobileAds.RaiseAdEventsOnUnityMainThread` to a `true` reported up to a 30% discrepancy in [impression-level ad revenue](https://developers.google.com/admob/unity/impression-level-ad-revenue) reporting. Recommendation:[Manually synchronize individual ad events](https://developers.google.com/admob/unity/global-settings#manually-synchronize-ad-events) instead.

## Video ad volume control

If your app has its own volume controls, such as custom music or sound effect
volumes, disclosing app volume to 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 by calling
the `SetApplicationVolume()` method before loading the ad. 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);

> [!WARNING]
> **Warning:** Lowering your app's audio volume reduces video ad eligibility and might reduce your app's ad revenue. You should only utilize this method if your app provides custom volume controls to the user, and the user's volume is properly reflected in the app.

To inform the SDK that the app volume has been muted, call the
`SetApplicationMuted()` method before loading the ad:

    // 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.

> [!WARNING]
> **Warning:** Muting your app reduces video ad eligibility and might reduce your app's ad revenue. You should only utilize this method if your app provides a custom mute control to the user, and the user's mute decision is properly reflected in the app.

## Consent for cookies

If your app has special requirements, you can set the optional
`ApplicationPreferences` key `gad_has_consent_for_cookies` to zero to enable

[limited ads](https://support.google.com/admob/answer/10105530)
:

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

## Android minification

This Unity publishing option lets you enable
[java code minification](https://developer.android.com/studio/build/shrink-code).
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

collects crash reports for debugging and analysis
purposes. To disable crash reporting, see the following sections for
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();
    }

## Get Unity plugin version

To get the Unity SDK version, run the following:

    // Get the Unity SDK version.
    Debug.Log("Unity SDK Version: " + MobileAds.GetVersion());

## Get platform version

The for Unity depends on the Android and iOS platform SDKs.
To get the version of the platform SDK, run the following:

    // Get the underlying platform SDK version.
    Debug.Log("Platform SDK Version: " + MobileAds.GetPlatformVersion());