How to manually initialize mediation network adapter and SDK with AdMob? (Unity, Android)

228 views
Skip to first unread message

Marek Stecker

unread,
May 20, 2025, 4:46:57 AMMay 20
to Google Mobile Ads SDK Developers
Hello,

I am using AdMob (Google Mobile Ads version 10.0.0) for ad mediation in Unity (2022.3.44f1).

The mediated networks I am using are:
- Meta Audience Network (SDK 6.19.0, adapter 6.19.0.1)
- Unity Ads (SDK 4.14.1, adapter 4.14.1.0)
- AdMob

My question is related to GDPR compliance. In the form displayed by Google UMP, when you go to Manage options and Vendor preferences, you can choose to give consent to each one of the vendors. The way I understand this is that when user doesn't give consent to Meta, but does give consent to the other networks, I am allowed to show ads from all vendors except Meta and so on.

I suppose AdMob handles this automatically for the TCF-registered vendors (like AdMob itself) and that I have to do it manually for non-TCF vendors. If that is the case, it would mean that I need to somehow tell AdMob to stop displaying ads from the vendors the user didn't consent to (based on the AC string).

I thought I could just initialize only the SDKs and adapters of the vendors the user consented to. For this I disable the mediation initialization using:

MobileAds.DisableMediationInitialization();

and then I manually initialize the Meta adapter and SDK like so:

private static async Task<bool> InitializeMetaSDK()
    {
        TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();

        AndroidJavaObject audienceNetworkAds = new AndroidJavaObject("com.facebook.ads.AudienceNetworkAds");

        var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        var context = activity.Call<AndroidJavaObject>("getApplicationContext");

        audienceNetworkAds.CallStatic("initialize", context);

        while (!audienceNetworkAds.CallStatic<bool>("isInitialized", context))
        {
            Debug.Log("Meta SDK is not yet initialized.");
            await Task.Delay(1000);
        }

        if (audienceNetworkAds.CallStatic<bool>("isInitialized", context))
        {
            Debug.Log("Sucessfully initialized Meta SDK.");
            tcs.SetResult(true);
        }
        else
        {
            tcs.SetResult(false);
        }

        return await tcs.Task;
    }

    private static void InitializeMetaAdapter()
    {
        AndroidJavaObject mediationAdapter = new AndroidJavaObject("com.google.ads.mediation.facebook.FacebookMediationAdapter");

        var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        var context = activity.Call<AndroidJavaObject>("getApplicationContext");

        AndroidJavaClass enumClass = new AndroidJavaClass("com.google.android.gms.ads.AdFormat");
        AndroidJavaObject adFormat = enumClass.GetStatic<AndroidJavaObject>("INTERSTITIAL");

        AndroidJavaObject bundle = new AndroidJavaObject("android.os.Bundle");
        bundle.Call("putString", "placement_id", "ca-app-pub-xxxxxxxxx");

        AndroidJavaObject mediationConfig = new AndroidJavaObject("com.google.android.gms.ads.mediation.MediationConfiguration", adFormat, bundle);
        AndroidJavaObject mediationConfigsList = new AndroidJavaObject("java.util.ArrayList");
        mediationConfigsList.Call<bool>("add", mediationConfig);

        mediationAdapter.Call("initialize", context, new InitializationCompleteCallbackProxy(), mediationConfigsList);
    }

    public class InitializationCompleteCallbackProxy : AndroidJavaProxy
    {
        public InitializationCompleteCallbackProxy() : base("com.google.android.gms.ads.mediation.InitializationCompleteCallback") { }

        public void onInitializationFailed(string error)
        {
            Debug.Log($"Initialization of Meta Adapter failed with error {error}");
        }
        public void onInitializationSucceeded()
        {
            Debug.Log("Sucessfully initialized Meta Adapter");
        }
    }

In the console, I then see that the SDK and adapter are both initialized, but I don't see them in Ad Inspector. I suppose I have to somehow notify AdMob that I initialized it and pass in a reference or something. How am I supposed to do that?

So overall, is this the correct way to ensure GDPR-compliance when it comes to the Vendor preferences and how should I continue? Or does AdMob handle it automatically?

Any help will be appreciated.

Thank you,
Marek Stecker

Marek Stecker

unread,
May 20, 2025, 4:47:03 AMMay 20
to Google Mobile Ads SDK Developers
Hello, I posted a question on the Google AdMob help forum and one of your product experts sent me here. Below is the original message.

Panji Wesley

unread,
May 20, 2025, 5:53:19 AMMay 20
to Marek Stecker, Google Mobile Ads SDK Developers

Yes sir


--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-admob-ads-sdk/a63f029f-8ab2-46c0-9f68-48d3dd7a8939n%40googlegroups.com.

Mobile Ads SDK Forum Advisor

unread,
May 20, 2025, 11:47:12 AMMay 20
to marek.free...@gmail.com, google-adm...@googlegroups.com
Hi Marek Stecker,

Thank you for contacting the Mobile Ads SDK Support team.

It looks like an incorrect implementation in terms of the AdInspector tool because AdInspector respects adapter status values from UMP SDK initializations. However, I will check this issue “AdInspector not showing after SDK and Adapters are initialized” with the wider team and one of my team members will reach out to you once we have an update.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-05-20 15:46:06Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qXaWu:ref" (ADR-00307047)



Marek Stecker

unread,
May 21, 2025, 4:55:03 AMMay 21
to Google Mobile Ads SDK Developers
Thanks for your reply.

Maybe I didn't state it clearly in the previous message. When I call MobileAds.Initialize and let AdMob handle initialization of the adapters and SDKs, I can see that they are initialized in the AdInspector. This works as expected.

But when I initialize the adapters and SDKs separately from AdMob by calling MobileAds.DisableMediationInitialization, I don't see the adapters and SDKs in AdInspector at all. I think this is expected as well, because I suppose I somehow need to notify AdMob that I initialized the SDKs and adapters manually but perhaps that should be handled automatically?

Thank you.
Marek

Mobile Ads SDK Forum Advisor

unread,
May 21, 2025, 10:29:04 AMMay 21
to marek.free...@gmail.com, google-adm...@googlegroups.com
Hi Marek,

Yes, this is the intended behavior as AdInspector is taking the SDK initialization status values from the MobileAds SDK initialization work flow but not from the separate initialization. 

I will raise this point to the wider team and inform you once we have an update. 

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-05-21 14:27:59Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qXaWu:ref" (ADR-00307047)



Marek Stecker

unread,
Jun 3, 2025, 7:40:53 PMJun 3
to Google Mobile Ads SDK Developers
Bump... does anyone know the answer?

Mobile Ads SDK Forum Advisor

unread,
Jun 9, 2025, 11:12:47 PMJun 9
to marek.free...@gmail.com, google-adm...@googlegroups.com
Hello Marek,

Thank you for reaching out and bumping the thread.

Consent string handling

After a user provides their consent, the Google UMP SDK writes the Transparency and Consent (TC) string into NSUserDefaults (iOS) or SharedPreferences (Android). The Google Mobile Ads SDK then reads this value from there.

Regarding which third-party SDKs support reading this consent string from shared preferences and setting their consent status accordingly, you would need to consult each ad source respective integration guide. For example, AppLovin supports this functionality starting from a specific version. I recommend checking the ad source integration guide for each of your partners and following their instructions. Some ad source SDKs do not automatically read the consent string, in which case you would need to manually forward the consent value to that specific ad source.

Ad partners list

In addition, you should ensure that you add your mediation partners to AdMob Privacy & messaging's US states or GDPR ad partners list. Please refer to the instructions in US states privacy laws and GDPR.


Your code and mediation initialization

Regarding your code, could you clarify why you are disabling mediation initialization? This is likely the reason why the adapter appears as not initialized, as when the Google Mobile Ads SDK first initializes, its adapters are not initialized yet.

I assume your logic is to avoid initializing an adapter until the user provides consent for that specific ad source. However, if you have correctly added Meta to your ad partners list in AdMob, and if the user does not consent to Meta, the ad serving mechanism should automatically know not to include Meta in bidding.


Is there an issue with Meta ads serving?
Are you currently observing a problem where Meta ads are still being served even when users have opted out of them?

Thanks!

 

Thanks,
 
Google Logo
Joshua
Mobile Ads SDK Team


Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-06-10 03:11:43Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qXaWu:ref" (ADR-00307047)



Marek Stecker

unread,
Jun 10, 2025, 1:39:33 AMJun 10
to Google Mobile Ads SDK Developers
Hello Joshua,

Thank you very much for your thorough response.

"However, if you have correctly added Meta to your ad partners list in AdMob, and if the user does not consent to Meta, the ad serving mechanism should automatically know not to include Meta in bidding." This clarifies it for me. I just wasn't sure to which extent AdMob handles initialization of the mediated networks. This means that there is no reason to handle the initialization manually and I can let AdMob handle it. That is great!

Is this information stored in the documentation somewhere? I went through quite a lot of it but I probably missed it.

Thank you for your help.
Marek

Mobile Ads SDK Forum Advisor

unread,
Jun 11, 2025, 2:45:02 PMJun 11
to marek.free...@gmail.com, google-adm...@googlegroups.com
Hello Marek,

You can refer to the Mediation Get started guide's US states privacy laws and GDPR section. Also see Manage GDPR ad partners in the AdMob Help Center.

If an ad source supports EU region, there would be an EU Consent and GDPR section in the corresponding integration guide that shows how to implement privacy settings, see AppLovin as an example.
 

Thanks,
 
Google Logo
Joshua
Mobile Ads SDK Team


Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-06-11 18:44:13Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qXaWu:ref" (ADR-00307047)



Thibault Lbt

unread,
Jun 25, 2025, 10:30:33 PMJun 25
to Google Mobile Ads SDK Developers
Hello Joshua,

Regarding this statement: "if you have correctly added Meta to your ad partners list in AdMob, and if the user does not consent to Meta, the ad serving mechanism should automatically know not to include Meta in bidding."

When mediation is involved, your documentation seems to suggest otherwise: "Google currently is unable to pass the user's consent choice to such networks automatically." 

Please correct me if I’m wrong, but as of today, my understanding is that the Applovin adapter (version 7.0.0 and above) is the only one that supports reading the consent string from shared preferences and setting the consent status accordingly.

Thanks,
Thibault

Mobile Ads SDK Forum Advisor

unread,
Jul 1, 2025, 4:20:40 PMJul 1
to thibau...@gmail.com, google-adm...@googlegroups.com
Hello Thibault,

Thanks for reaching out.

We always recommend publishers to make sure all the necessary partners are included in the ad partners list in the AdMob UI. If you use the UMP SDK, the TC String will be based on that list. For example, if you haven't added Meta to the list, you wouldn't be able to see Meta in the form under Vendor preferences, and Meta would then not be included in the auction.

To clarify your understanding, it's the AppLovin SDK (but not the adapter) that reads the consent string from shared preferences and sets the consent status on their end accordingly; this is not controlled by Google's end.

For third-party SDKs that do not perform the above (as indicated in our developer documentation or in their own developer documentation), you have to set it manually.

 

Thanks,
 
Google Logo
Joshua
Mobile Ads SDK Team


Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-07-01 20:19:44Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qXaWu:ref" (ADR-00307047)



Reply all
Reply to author
Forward
0 new messages