capacitor-community / admob

Community plugin for using Google AdMob
MIT License
205 stars 66 forks source link

Feature: Integrate generic code for Mediation Networks #39

Open distante opened 3 years ago

distante commented 3 years ago

See:

Context:

AdMob Mediation is a feature that lets you serve ads to your apps from multiple sources, including the AdMob Network, third-party ad networks, and AdMob campaigns. AdMob Mediation helps maximize your fill rate and increase your monetization by sending ad requests to multiple networks to ensure you find the best available network to serve ads.

rdlabo commented 3 years ago

I'm interesting this (I'm AdMob user too, and interested at increment income). But this looks not realistic as OSS because it depends on a particular library. If the user needs it, I think it must be forked.

distante commented 3 years ago

Not really, is up to the user to install the sdk libraries, the plugin just need to check the initialized object.

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.AdapterStatus;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
                Map<String, AdapterStatus> statusMap = initializationStatus.getAdapterStatusMap();
                for (String adapterClass : statusMap.keySet()) {
                    AdapterStatus status = statusMap.get(adapterClass);
                    Log.d("MyApp", String.format(
                            "Adapter name: %s, Description: %s, Latency: %d",
                            adapterClass, status.getDescription(), status.getLatency()));
                }

                // Start loading ads here...
            }
        });
    }
}

I am not using mediation networks at the moment so I can not really test it now.

maximnara commented 2 years ago

Hello! Mediation is implemented for release 3.2.0? I really need this working

jaimyborgman commented 1 year ago

does this mean that if you setup admob correctly and within google admob itself you'll define like for instance Meta Audience Network that it doesn't show their advertisements?

denesh-r commented 10 months ago

In Admob.java

// Initialize AdMob with appId
@PluginMethod
public void initialize(final PluginCall call) {
    this.setRequestConfiguration(call);
    try {
        MobileAds.initialize(
            getContext(),
            new OnInitializationCompleteListener() {
                @Override
                public void onInitializationComplete(InitializationStatus initializationStatus) {
                    Map<String, AdapterStatus> statusMap = initializationStatus.getAdapterStatusMap();
                    for (String adapterClass : statusMap.keySet()) {
                        AdapterStatus status = statusMap.get(adapterClass);
                        Log.d("MyApp", String.format(
                            "Adapter name: %s, Description: %s, Latency: %d",
                            adapterClass, status.getDescription(), status.getLatency()));
                    }
                }
            }
        );
        bannerExecutor.initialize();
        call.resolve();
    } catch (Exception ex) {
        call.reject(ex.getLocalizedMessage(), ex);
    }
}

Then include the adapter class in build.gradle under dependencies.

implementation 'com.google.ads.mediation:facebook:6.15.0.0'

This worked and I was able to use both admob and meta after configuring mediation on admob.

So if we could mention the SDKs needed somewhere, we should be able to conditionally add them to the build to make this work.

I would love to see this feature implemented, instead of forking the plugin. @rdlabo @distante let me know how I can assist.

distante commented 6 months ago

@denesh-r this got buried on my notifications till now... Would you be able to create a PR for this?