Hello I am trying to implement Admob with unity, I have successfully integrated banner ads and Interstitial ads using the Test ids provided by Admob over here https://developers.google.com/admob/android/test-ads. How ever I am unable to display any rewarded Video ads. When ever I call the RewardedVidosAds nothing shows up and a debug log error displays Ad not ready. This is the following code I am using:
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdManager: MonoBehaviour {
public RewardBasedVideoAd rewardBasedVideoAd;
private InterstitialAd fullAdmob;
private bool rewardBasedEventHandlersSet = false;
// reward initialized
public int scoreAmount = 100;
// Use this for initialization
void Start() {
//loading both rewarded and interstitial ads in start.
LoadRewardBasedAd();
//RequestFull ();
}
// Update is called once per frame
void Update() {
}
public void LoadRewardBasedAd() {
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
//Test
AdRequest adRequest = new AdRequest.Builder()
.Build();
rewardBasedVideoAd.LoadAd(adRequest, "ca-app-pub-3940256099942544/5224354917");
}
public void ShowRewardBasedAd() {
if (rewardBasedVideoAd.IsLoaded()) {
Debug.Log("Showiung video");
rewardBasedVideoAd.Show();
} else Debug.Log("not ready");
}
}
I have not currently mediated my video Ads could this be causing the problem? I read that you dont need to mediate your ads if your using a test AdId. I also get the following errors in my logcat when calling for a rewardedVideoAd
Fail to instantiate adapter com.google.DummyAdapter
Fail to load ad:3
Related
I did everything on Google's official AdMob tutorial. Test ad was showing up on the editor but when i try it on my phone there are no ads. Google approved my account and still nothing shows up. What do i have to do now?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using UnityEngine.SceneManagement;
public class AdManager : MonoBehaviour
{
BannerView _banner;
string bannerId = "banner-id";
void Start()
{
MobileAds.Initialize(initStatus => { });
RequestBanner();
}
void RequestBanner()
{
_banner = new BannerView(bannerId, AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
_banner.LoadAd(request);
}
}
Put banner test ID in string bannerId and in your Start() function call this function _banner.Show() after RequestBanner(); function. It will defiantly work.
I'm implementing google native ads on android.Most of the code I copy/pasted from this example
The only difference is I request bunch of ads instead of one ad.Here is load function:
public void loadAds(String unitId,int count) {
if (nativeAds.size()>0) {
for(UnifiedNativeAd ad: nativeAds)
ad.destroy();
}
nativeAds =new ArrayList();
//load
AdLoader.Builder builder = new AdLoader.Builder(context, unitId);
builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
// OnUnifiedNativeAdLoadedListener implementation.
#Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd nativeAd) {
// You must call destroy on old ads when you are done with them,
// otherwise you will have a memory leak.
//nativeAd = unifiedNativeAd;
int numAds =nativeAds.size();
int insertTo=numAds==0? firstAdPosition : firstAdPosition +numAds*(AdStep +1);
CategoryData item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_NATIVE_AD;
if (insertTo<data.size())
data.add(insertTo, item);
item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_SEPARATOR;
if (insertTo<data.size())
data.add(insertTo+1, item);
nativeAds.add(nativeAd);
Log.d("nativead","got ad body "+nativeAds.size()+":"+nativeAd.getBody());
notifyItemRangeInserted(insertTo,2);
}
});
VideoOptions videoOptions = new VideoOptions.Builder()
.setStartMuted(true)
.build();
NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();
builder.withNativeAdOptions(adOptions);
AdLoader adLoader = builder.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Log.d("nativead","error code " +errorCode);
/*
Toast.makeText(context, "Failed to load native ad: "
+ errorCode, Toast.LENGTH_SHORT).show();
*/
}
}).build();
AdRequest adRequest;
// get unpersonalized ads if needed
if(AppModel.getAppData().gdpr.eea && AppModel.getAppData().gdpr.consentStatus!= ConsentStatus.PERSONALIZED) {
Bundle extras = new Bundle();
extras.putString("npa", "1");
adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,extras).build();
} else {
adRequest = new AdRequest.Builder().build();
}
adLoader.loadAds(adRequest,count);
//adLoader.loadAd(adRequest);
}
First time it loads ok, but if I restart the app it throws a bunch of errors:
I/Ads: Received log message: The ad request returned a no fill for the particular slot. The error log below that says 'Malformed native JSON response' is a benign warning that will be removed in a future SDK release.
Also error code 0 is passed into onAdFailedToLoad.If I clear app's data banners are loaded again but again only for single run
As you mentioned, in the comment above, you're testing it on real ad units (which is quite dangerous as you might get blocked for that).
You're getting NO_FILL, which means there is no inventory left to serve in the AdMob backend.
You can find out more about this issue (not an issue, we can call it a "thing") here.
To get proper results, always test with test ads, so that you get maximum fill rate for the ads while testing.
You'll find the ad unit ID's for test ads on this page.
And, if you still get NO_FILL error a lot in production, try using mediation to get ads from multiple ad sources. You'll never get 100% fill rate for your ads, though, so make sure you code accordingly to handle the NO_FILL.
Also, one more reminder, do not use live ads to test the app, you might get blocked by Admob/Google for doing that.
As the Documentation of Mopub say's here ,integrated the Native ads and followed by Native Video ads.
After integrating the code the ad request response is calling the callback method onNativeFail()
with some of the response
Below code is related to the workflow and logcat message
public class MainActivity extends Activity {
private MoPubView moPubView;
//private MoPubInterstitial mInterstitial;
private MoPubNative moPubNative;
private MoPubNativeNetworkListener moPubNativeNetworkListener;
private NativeAd.MoPubNativeEventListener moPubNativeEventListener;
AdapterHelper adapterHelper;
private NativeFullScreenVideoView nativeFullScreenVideoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
moPubNativeNetworkListener = new MoPubNativeNetworkListener() {
#Override
public void onNativeLoad(NativeAd nativeAd) {
Log.d("MoPub", "Native ad has loaded.");
}
#Override
public void onNativeFail(NativeErrorCode errorCode) {
Log.d("MoPub", "Native ad failed to load with error: " + errorCode.toString());
}
};
moPubNativeEventListener = new NativeAd.MoPubNativeEventListener() {
#Override
public void onImpression(View view) {
Log.d("MoPub", "Native ad recorded an impression.");
// Impress is recorded - do what is needed AFTER the ad is visibly shown here.
}
#Override
public void onClick(View view) {
Log.d("MoPub", "Native ad recorded a click.");
// Click tracking.
}
};
moPubNative = new MoPubNative(this, "02a2d288d2674ad09f3241d46a44356e ", moPubNativeNetworkListener);
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_list_item)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build();
MediaViewBinder mediaViewBinder = new MediaViewBinder.Builder(R.layout.native_video_ad_layout)
.mediaLayoutId(R.id.native_ad_video_view)
.iconImageId(R.id.native_ad_icon_image)
.titleId(R.id.native_ad_title)
.textId(R.id.native_ad_text)
.build();
MoPubVideoNativeAdRenderer moPubVideoNativeAdRenderer = new MoPubVideoNativeAdRenderer(mediaViewBinder);
moPubNative.registerAdRenderer(moPubVideoNativeAdRenderer);
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of(
RequestParameters.NativeAdAsset.TITLE,
RequestParameters.NativeAdAsset.TEXT,
RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
RequestParameters.NativeAdAsset.MAIN_IMAGE,
RequestParameters.NativeAdAsset.ICON_IMAGE,
RequestParameters.NativeAdAsset.STAR_RATING
);
RequestParameters mRequestParameters = new RequestParameters.Builder()
.desiredAssets(desiredAssets)
.build();
moPubNative.makeRequest();
}
}
After running this code, the ad is not getting loaded and the response of my code is below
06-06 17:01:41.797 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:01:41.911 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:18.623 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:02:18.954 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:51.796 13278-13278/com.fabgrad.students.android D/MoPub: Native ad request failed.
com.mopub.network.MoPubNetworkError: No ads found for ad unit.
at com.mopub.network.AdRequest.parseNetworkResponse(AdRequest.java:180)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
06-06 17:02:51.800 13278-13278/com.fabgrad.students.android D/MoPub: Native ad failed to load with error: Server returned empty response.
As per their blog, No ads found will come for following scenarios:
These errors indicate that there was no fill for your ad unit.
No ad network will have fill 100% of the time, so seeing this log is normal. New apps and apps with very low volume tend to experience lower fill rates. Contact your ad network representative if you have any concerns related to a particular network’s fill.
If you are consistently seeing no fill, review your ad network placement details in the Networks tab of the MoPub UI, as well as your settings in the Network’s UI.
You won’t be able to show ads from Certified Ad Networks if you forgot to include the network SDK or adapter files. The Couldn't locate or instantiate custom event and Unable to find Native Network or Custom Event adapter log messages are indicators that the network SDK or adapter file is missing, renamed, or in the wrong location.
Review our Integrating Third-Party Ad Networks documentation to resolve this.
Link for reference.
I am trying to put an interstitial ad after every 5 games the user plays. What I've done is created an empty object with the following script:
using UnityEngine;
using GoogleMobileAds.Api;
public class AdBetweenGames : MonoBehaviour {
InterstitialAd interstitial;
void Start()
{
if(PlayerPrefs.GetInt("games-played", -1) % 5 == 0)
{
this.ShowInterstitial();
}
}
private void RequestInterstitial()
{
string adUnitId = "UNITID";
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
public void ShowInterstitial()
{
RequestInterstitial();
Debug.Log("Interstatial ad called.");
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
I am sure the code here is called properly based on the debug log. I've also tried doing banner ads and they show without a problem after 1-2 seconds. I am making an android game.
Also I was thinking, could it be that the ad needs some extra time to load and I am clicking try again too early. But then what would a solution be?
The interstitial ad of ad mob need time to load try it in update and wait for at least 4 sec and call ShowInterstitial function inside a bool set its value true in start and false it after calling the function to show ad once.
I am trying to implement Amazon Ads in my Android app, but have not been able to get any ads to display. The message in my logs is always:
D/AmazonMobileAds DefaultAdListener: Default ad listener called - Ad Failed to Load. Error code: NO_FILL, Error Message: Server Message: no results
I have set up my account, verified my tax information, I have an application key. I have tried both with testing enable and disabled with the same results. I have followed the guide for loading ads from both Amazon and Admob for backfill, but the AdMob ads are then not retrieved either. If I retrieve just AdMob ads, I have no problem with them. The relevant code is below:
in onCreate():
AdRegistration.setAppKey(getString(R.string.amazon_ad_id));
AdRegistration.enableTesting(true);
AdRegistration.enableLogging(true);
// Initialize ad views
amazonAdView = new com.amazon.device.ads.AdLayout(this);
amazonAdView.setListener(new MyAdListener());
admobAdView = new com.google.android.gms.ads.AdView(this);
admobAdView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
admobAdView.setAdUnitId(getString(R.string.banner_ad_unit_id));
Method called to retrieve an ad:
void getAd(){
// Initialize view container
adViewContainer = (ViewGroup)findViewById(R.id.adView);
amazonAdEnabled = true;
adViewContainer.removeAllViews();
adViewContainer.addView(amazonAdView);
AdTargetingOptions adOptions = new AdTargetingOptions();
adOptions.enableGeoLocation(true);
amazonAdView.loadAd(adOptions);
}
Inner AdListener class
class MyAdListener extends DefaultAdListener {
public void onAdLoaded(com.amazon.device.ads.AdLayout view, AdProperties adProperties) {
Log.d(LOG_TAG, "Ad Loaded");
if (!amazonAdEnabled) {
amazonAdEnabled = true;
adViewContainer.removeView(admobAdView);
adViewContainer.addView(amazonAdView);
}
}
public void onAdFailedToLoad(com.amazon.device.ads.AdLayout view, AdError error) {
Log.d(LOG_TAG, "Ad Failed to load");
// Call AdMob SDK for backfill
if (amazonAdEnabled) {
amazonAdEnabled = false;
adViewContainer.removeView(amazonAdView);
adViewContainer.addView(admobAdView);
}
admobAdView.loadAd((new com.google.android.gms.ads.AdRequest.Builder()).build());
}
}
In my logging, neither of the statements from the AdListener shows, so it appears that the listener is never being called. So, I have two issues here:
Why am I always receiving a NO_FILL response, even when testing?
Why is the listener never called?