Hello everybody,
In this tutorial I will show you tutorial about admob open bidding with facebook admob and applovin.
Here we will add 3 ad networks in our app. open bidding means that among these 3 networks, higher ecpm network ad will be shown. Highest paying ad source will be served. this will increase your app revenue
To do so, just follow these steps
Go to Admob Mediation and create new Mediation group for banner ad
Click on Add Ad Units
Here select your app
Now in Bidding, click add ad source
Here you can see that for Banner ad , Applovin is not available , So we have to add only Facebook
Now go to facebook monetization manager and copy banner ad placement id
Finally don't forget to click on save
Similarly we have to create mediation groups for interstitials ads in similar manner
For interstitial ads you can see both facebook and applovin networks are available
We have to add both of them
for first time when you click on Applovin select option, you have to sign partnership agreement ,
just click this option Applovin account here
Now just sign in to your applovin account
Go back to admob tab, and you will see that agreement is opened, click on Acknowlege and continue
Now if you have not added your in applovin yet, first add your app. If app is already added, proceed further.
Now you have to copy sdk key,
go to account tab and click on key
copy sdk key from here
Now we have to go to Android studio
Add these 4 libraries in build.gradle
review:
implementation 'com.google.android.gms:play-services-ads:20.4.0' implementation 'com.google.ads.mediation:applovin:10.3.3.0' implementation 'com.google.ads.mediation:facebook:6.6.0.0' implementation 'com.google.android.ads:mediation-test-suite:2.0.0'
Now in res folder, create xml resource directory and create an xml file named network security config
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">127.0.0.1</domain> </domain-config> </network-security-config>
Now you have to open android manifest file and add internet permission
under application tag, add meta data
Final AndroidManifest.xml file is
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.sampleappdev.admobopenbidding"> <uses-permission android:name="android.permission.INTERNET"/> <application android:networkSecurityConfig="@xml/network_security_config" tools:targetApi="n" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AdmobOpenBidding"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="@string/admobAppLevelIDManifest" /> </application> </manifest>
now go to strings.xml and add ad ids strings
Strings.xml file
<resources> <string name="app_name">Admob Open Bidding</string> <!-- Here I have used test ad ids, which may lead to No fill from Ad Source. Please use real Ad ids and add your device as test device in admob settings--> <string name="admobbannerad">ca-app-pub-3940256099942544/6300978111</string> <string name="admob_int_ad">ca-app-pub-3940256099942544/1033173712</string> <string name="AdmobRewarded">ca-app-pub-3940256099942544/5224354917</string> <string name="admobAppLevelIDManifest">ca-app-pub-3940256099942544~3347511713</string> </resources>
now in your java main activity , initialize admob sdk
now add banner and interstitial ad codes
Final MainActivity.java is
package com.sampleappdev.admobopenbidding; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.View; import android.widget.Button; import android.widget.FrameLayout; import android.widget.Toast; //import com.google.android.ads.mediationtestsuite.MediationTestSuite; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.LoadAdError; 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; import com.google.android.gms.ads.interstitial.InterstitialAd; import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback; import java.util.Map; public class MainActivity extends AppCompatActivity { private InterstitialAd adMobIntAd; private AdView adView; private FrameLayout adContainerView; @Override 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())); } LoadInterstitialAds(); // This code was missing adContainerView = findViewById(R.id.ad_view_container); adContainerView.post(new Runnable() { @Override public void run() { LoadAdmobBannerAd(); } }); //MediationTestSuite.launch(MainActivity.this); } }); Button button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (adMobIntAd == null){ Toast.makeText(getApplicationContext(), "Ad not loaded yet", Toast.LENGTH_SHORT).show(); }else { ShowInterstitialAds(); } } }); } private void LoadInterstitialAds() { AdRequest adRequest = new AdRequest.Builder().build(); InterstitialAd.load(this, getString(R.string.admob_int_ad), adRequest, new InterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { adMobIntAd = interstitialAd; } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { adMobIntAd = null; } }); } public void ShowInterstitialAds(){ if (adMobIntAd != null) { adMobIntAd.show(MainActivity.this); } } public void LoadAdmobBannerAd(){ adView = new AdView(this); adView.setAdUnitId(getString(R.string.admobbannerad)); adContainerView.removeAllViews(); adContainerView.addView(adView); AdSize adSize = getAdSize(); adView.setAdSize(adSize); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); } private AdSize getAdSize() { Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = outMetrics.density; float adWidthPixels = adContainerView.getWidth(); if (adWidthPixels == 0) { adWidthPixels = outMetrics.widthPixels; } int adWidth = (int) (adWidthPixels / density); return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth); } }
Now in activitymain.xml, add this code
Final ActivityMain.xml file
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="300dp" android:layout_height="95dp" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_marginStart="76dp" android:layout_marginTop="64dp" android:layout_marginEnd="34dp" android:text="Show Interstitial Ad" /> <RelativeLayout android:id="@+id/relativeLayoutAds" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="0.0dip"> <FrameLayout android:id="@+id/ad_view_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> </RelativeLayout>
If you get No fill from ad source, don't worry, just publish your app on playstore and wait for about 72 hours, then ads will be shown on your app. Make sure that you have replaced test ad ids with real ad ids before publishing on playstore. To test mediation correctly, use real ad ids instead of test ad ids.
Finally remove mediation test suite from your app and create signed bundle and publish on playstore
If you have any query, just comment.
If you are facing any other problem, just tell me to make a tutorial on it.
Subscribe this channel. Thanks
YouTube Tutorial