Search code examples
admob

Admob modified ad behavior


I got an email with stopped ad serving to my app and the app has 2 issues one of them is "Modified ad behavior"

Modified ad behavior : Publishers are not permitted to alter the behavior or targeting of Google ads. This includes implementing the AdSense ad code in a "floating box script" or altering the ad targeting using hidden keywords or IFRAMES.

It is the first time to get this issue and it isn't clear for me because i didn't put any of my ads in "floating box script" or using IFRAMES or ...

here is my interstitial code :

mPublisherInterstitialAd = new PublisherInterstitialAd(this);
        mPublisherInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad_unit_id));
        mPublisherInterstitialAd.loadAd(new PublisherAdRequest.Builder().build());
        mPublisherInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                // Load the next interstitial.
                mPublisherInterstitialAd.loadAd(new PublisherAdRequest.Builder().build());
            }
        });

my AppOpen ad code :

   /** Constructor */
   public AppOpenManager(MyApplication myApplication) {
       this.myApplication = myApplication;
       this.myApplication.registerActivityLifecycleCallbacks(this);
       ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
   }
   public void showAdIfAvailable() {
       // Only show ad if there is not already an app open ad currently showing
       // and an ad is available.
       Log.e(LOG_TAG, "showAdIfAvailable: " + (!isShowingAd) );
       Log.e(LOG_TAG, "showAdIfAvailable: " + (isAdAvailable()) );
       if (!isShowingAd && isAdAvailable()) {
           Log.e(LOG_TAG, "Will show ad.");

           FullScreenContentCallback fullScreenContentCallback =
                   new FullScreenContentCallback() {
                       @Override
                       public void onAdDismissedFullScreenContent() {
                           // Set the reference to null so isAdAvailable() returns false.
                           AppOpenManager.this.appOpenAd = null;
                           isShowingAd = false;
                           fetchAd();
                       }

                       @Override
                       public void onAdFailedToShowFullScreenContent(AdError adError) {
                           Log.e("TAGGGG", "onAdFailedToShowFullScreenContent: " + adError.getMessage() );
                       }

                       @Override
                       public void onAdShowedFullScreenContent() {
                           isShowingAd = true;
                       }
                   };

           appOpenAd.show(currentActivity, fullScreenContentCallback);

       } else {
           Log.e(LOG_TAG, "Can not show ad.");
           fetchAd();
       }
   }
   /** Request an ad */
   public void fetchAd() {
       // Have unused ad, no need to fetch another.
       if (isAdAvailable()) {
           return;
       }

       loadCallback =
               new AppOpenAd.AppOpenAdLoadCallback() {
                   /**
                    * Called when an app open ad has loaded.
                    *
                    * @param ad the loaded app open ad.
                    */
                   @Override
                   public void onAppOpenAdLoaded(AppOpenAd ad) {
                       AppOpenManager.this.appOpenAd = ad;
                       AppOpenManager.this.loadTime = (new Date()).getTime();
                   }

                   /**
                    * Called when an app open ad has failed to load.
                    *
                    * @param loadAdError the error.
                    */
                   @Override
                   public void onAppOpenAdFailedToLoad(LoadAdError loadAdError) {
                       // Handle the error.
                   }

               };
       AdRequest request = getAdRequest();
       AppOpenAd.load(
               myApplication, AD_UNIT_ID, request,
               AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT, loadCallback);
   }

   /** Utility method to check if ad was loaded more than n hours ago. */
   private boolean wasLoadTimeLessThanNHoursAgo(long numHours) {
       long dateDifference = (new Date()).getTime() - this.loadTime;
       long numMilliSecondsPerHour = 3600000;
       return (dateDifference < (numMilliSecondsPerHour * numHours));
   }

   /** Utility method that checks if ad exists and can be shown. */
   public boolean isAdAvailable() {
       return appOpenAd != null && wasLoadTimeLessThanNHoursAgo(4);
   }
   /** Creates and returns ad request. */
   private AdRequest getAdRequest() {
       return new AdRequest.Builder().build();
   }

//    /** Utility method that checks if ad exists and can be shown. */
//    public boolean isAdAvailable() {
//        return appOpenAd != null;
//    }

   @Override
   public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {

   }

   @Override
   public void onActivityStarted(@NonNull Activity activity) {
       currentActivity = activity;
   }

   @Override
   public void onActivityResumed(@NonNull Activity activity) {
       currentActivity = activity;
   }

   @Override
   public void onActivityPaused(@NonNull Activity activity) {

   }

   @Override
   public void onActivityStopped(@NonNull Activity activity) {

   }

   @Override
   public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {

   }

   @Override
   public void onActivityDestroyed(@NonNull Activity activity) {
       currentActivity = null;
   }
   @OnLifecycleEvent(ON_START)
   public void onStart() {
       showAdIfAvailable();
       Log.d(LOG_TAG, "onStart");
   }
}

please tell me if u need more information


Solution

  • Unfortunately Admob doesn't really state the specific problem regarding the "Modified ad behavior". In my experience the cause of that (unless it really is one of the IFRAME issues stated in the small Admob notice) had to do with the "Discouraged banner implementation" and if you have Interstitials "Discouraged interstitial implementations".

    I had implemented a native banner ad with a constraint bottom to parent and on top of that I had a scrollview with a list of textviews that I wrongfully constrained its bottom to parent as well, so I was violating "Ad overlapping with app content (against policy)" that resulted in limited ad serving from admob with the notice "Modified ad behavior". Setting the scrollview bottom constraint to the top of the adview (avoiding the content to go under the banner) solved my issue.

    If you still are having this issue, I would strongly advise you to go through your code verifying that you are not violating in any way the discouraged implementations.

    I hope that I was of help!