How to combine Madvertise with another ad network

A lot of people asked me how I implement the switch of Madvertise to another ad network. Here is how I do it:

I’m doing this example using an AdMob and an Madvertise view. Of course you can use any other similar networks like Adwhirl or Mobclix as well but I’m assuming you are familiar with including the two SDKs you are using.

At first we need a layout resource, here it is:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  xmlns:mad="http://schemas.android.com/apk/res/com.andlabs.gi"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  > 
          <com.google.ads.AdView
            android:id="@+id/admad"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="y0ur4dun1t1dh3r3"
            ads:adSize="BANNER"
            ads:loadAdOnCreate="true"
            />
         <de.madvertise.dev.android.MadView
             android:id="@+id/madad"
             android:layout_width="match_parent"
             android:layout_height="Wrap_content"
             mad:isTestMode="false"
             mad:backgroundColor2="#000000"
             mad:textColor="#FFFFFF"
             mad:bannerType="mma"
             mad:deliverOnlyText="false"
             android:visibility="gone"     
             />                
</FrameLayout>

Pretty basic. A Madvertise and an AdMob view. Next step: Get them in your Activity:

 private MadView mMadView;
 private AdView mAdmView;
 @Override
     public void onCreate(Bundle bundle) {
          super.onCreate(bundle);
          /* ... */
          mAdmView = (AdView)findViewById(R.id.admad);
          mMadView = (MadView)findViewById(R.id.madad);
     }


That’s easy too. Next, register an MadViewCallbackListener and switch the views the way you need it. As you have seen the MadView is invisible at the beginning. I assume that Madvertise always brings in more money, so when I receive an ad by them, I set the AdMob view to invisible and the MadView to visible. That’s essentially it:

 mMadView.setMadViewCallbackListener(new MadViewCallbackListener() {
     @Override public void onLoaded(boolean success, MadView arg1) {
          if (success) {
               if(D) {
                    Log.d(this.getClass().getSimpleName(), "MadAd Received");
               }  
               if (mAdmView.getVisibility() == View.VISIBLE) {
                    mAdmView.setVisibility(View.GONE);
               }
               mMadView.setVisibility(View.VISIBLE);
          } else {
               if(D) {
                    Log.d(this.getClass().getSimpleName(), "No MadAd Received");
               }
               mMadView.setVisibility(View.GONE);
          }
     }
 });

Not a big deal. And that’s all. Now you have your own little meta ad network.

 

Please feel free to leave your experiences, questions or suggestions in the comments.

27 Comments

  1. Nice tip.

    Just something offtopic. I think you should use View.GONE instead of INVISIBLE, using gone you remove the view from all layout processing, too. Only use INVISIBLE if other elements (e.g. in a linearlayout or relativelayout) need to be aligned to this element.

    regards,
    atla

  2. Ho Johannes,

    thanks for the snippets. BTW, I’m not shure if it is wise to show your Admob-Unit-ID…

    • Hi Richard,

      you’re welcome.
      Well, since I publish it with my apps anyway (it shouldn’t be too hard to decompile my apks (-;), I don’t care much. Nevertheless I changed it in the above code, thank you.

      Best regards
      Johannes

  3. Daniel online

    2011/08/20 at 09:20

    Thanks a lot! I just implemented this code.

    However, ” mMadView.setLayoutParams(new FrameLayout.LayoutParams(0, 0)); ” did not work.
    I used “mMadView.setVisibility(View.GONE);” instead.

    Sincerely,
    Daniel

  4. Very nice tutorial. Thanks for taking the time and writing this.

    There is one small problem left with madvertise for me. The ads are always showing in a small version like it would be required for a G1 and this looks a little bit strange. Is there a way to scale those ads?

    • You’re welcome Janusz.
      Yes, that’s a problem I’m experiencing too. I think the size of the ads delivered depends on their device database. I didn’t take a look into their SDK but I think you could rewrite that part so that they scale correctly. As I’ve seen you already left an issue in their bug tracker, I hope that will speed that thing up a little.

      Best regards
      Johannes

    • I took a quick look into their code: It seems as if they were working with the display’s width when drawing their text ads but they don’t use it when requesting an image ad. In fact they receive the displays height and width and put them into parameters but they don’t use them after that. That’s weird somehow.

  5. I asked Madvertise about the banner issue. Here’s their reply:

    german:
    “Bei Android ist es so, dass der Banner zwar skaliert wird, aber die Höhe des Banners fest definiert ist. Aktuell liegt diese bei 53 Pixel. Sie können diese Einschränkung aufheben, indem Sie in den SDK Sourcen die Variable “bannerHeight” suchen und dort die 53 Pixel ändern.”

    english translation:
    “The banner is scaled but the height is fixed by 53 pixels. You can change this by searching the SDK for the string ‘bannerHeight’ and change the value from 53 to whatever size you like.”

    Nevertheless I didn’t tried it out on my self. Madvertise also told me, that a new version of their SDK is on the way, which will let scale the banners correctly out of the box.

    Hope that help you guys :-)

  6. Sorry for spamming on this issue, but I found a way to rescale the banner image to the full view width. I posted it here: http://www.androidpit.de/de/android/forum/thread/435175/Rescale-Madvertise-Banner-Image#p793371

    • Hi Richard,
      great work! Changing the Madvertise code is not a problem as it’s Open Source. As they stated on their issue tracker: “btw. this is an open source project. just fork it and send us a pull request for fix or new feature.”
      For the english speaking people: The first part of Richard’s code is how it currently is, the second part is how it could be when you want your ads to scale. You should still be carefull when your app runs in landscape mode.
      Best regards
      Johannes

  7. I also did a little research on that topic and I found another problem with this implementation

    http://blog.mobclix.com/2011/02/24/how-to-increase-your-click-through-rate/

    According to this article such an implementation will hurt the AdNetworks and they will again reflect it on you.
    The question is, what could be a better solution?

    • Hi Lukas,
      thank you for sharing your results.
      I think it depends. When supporting an international app like mine with only two ad networks of which one is strongly focused on a certain region (Madvertise) and only one is international (AdMob), this should have little to no effect. For example in my case only about twelve percent of the AdMob impressions are overlayed by Madvertise (and my AdMob CTR is still above average (-;) Still, you can load your ads in your code just in time. Especially when your ad focuses on a certain area where both ad networks are strong this should be considered.
      Best regards
      Johannes

    • What I think is much more important is the refresh rate: This shrinks your CTR more than anything else.

  8. Hi,

    CTR is a good point. I didn’t know that the CTR influences your value for the ad networks. How do you deal with that? Johannes, you told me, that you suppress the refreshing of the ads. Are you doing this bei setting the Attribute runningRefreshAd of the MadView to false? I didn’t find a similar attribute for the AdmobView. Any suggestions? Would appreciate your help :-)

    • Hi Richard,
      please excuse my late reply.
      I don’t suppress the refreshing, I just don’t set an refresh rate. Madads do refresh themselves, maybe the user can set a refresh rate after the next update (or someone just has to modify the Madvertise SDK).

      Best regards
      Johannes

  9. I decided to try madvertise, because of your income reports :) I implemented this code, because i use admob too. My madvertise account is only getting requests and the fillrate is staying at zero. The code worked fine when i used the test token at testmode. Is there something else i need to add to the java class? The example on madvertise page used listadapter for countries, but i got the feeling it was optinal.

    • Hello Thrasheri,
      thank you for your comment.
      When ‘TestTokn’ worked fine everything should be okay. You might not receive an ad based on your position. When you are not located in the UK, in Germany, Italy, Spain, Switzerland or Austria, this is very likely the reason.
      I hope this helps.

      Best regards
      Johannes

  10. Yeah i noticed. The fillrate started rising now. Thank you for your reply blog that is very motivating :)

  11. Thanks, this helps me to implement AdMob and Madvertise in my first App. Next I will try to add an banner-rotation for my own websites, if both can not fill.

  12. That it’s very nice, and does not look overcomplicated.
    Thanks for your response.

  13. Hello,

    nice article and very helpful. I have problem with setVisibility(View.GONE). If I use it in the beginning or while app is running it never hides the madvertise ad banner. Do you have any idea what can be wrong? My MadvertiseView is inside FrameLayout. I would like to hide ads when app is starting…

    best regards,
    Tomas

    • Hello Tomas,

      as soon as an ad is fetched, the MadvertiseView sets itself to View.VISIBLE. To avoid this behavior, one has to call setFetchingAdsEnabled(false);

      Best regards
      Johannes

  14. Great stuff…sorry to be a noob…but you mentioned you have two ad services.

    Reason for this is your main ad service might not be pitching an ad to your app and a blank box would be in it’s place?

    Is this common with advertisers to have intermittent ad service?

  15. pradeep jain

    2013/02/15 at 06:20

    Hi,
    I have uploaded my first Android app on market. Link is https://play.google.com/store/apps/details?id=com.pradeep.vasooliManager. I have added adMob Banners ad and LeadBolt App Wall. Pl provide feedback about this app and any changes that you would suggest will be very helpful.

Leave a Reply

Your email address will not be published.

*

© 2024 Droid-Blog

Theme by Anders NorenUp ↑