Friday, June 24, 2011

Showing Adsense Ads on iGoogle gadgets

Recently igoogle made changes to its site and stop supporting ads from adsense in home view. They says it is only supported in canvas view but that seems to be also broken there is already defect logged for the same but they closed stating won't fix because of adsene employee at adsense forum conversation says it could be adsense issue. Finally none of them has given solution for the same.
 I observed that when my igoogle gadget is loaded from then ads are displayed exactly fine but there is problem when igoogle gadget is loaded from or any other host which ends with (e.g , etc.) the Adsense ads are not displayed on such gadgets.

Finally I figured out workaround for the same for my gadgets, and I would like to share the same with you. Which could be very much helpful in your adsense revenue until google fixes this annoying issue. Following are simple steps you need to follows:

Your igoogle gadget must be having <content> section  for example
<Content type="html" view="home">

Just after starting of this section put following javascript code which helps your gadget to be rendered from domain.

    //workaround for showing Adsense ads within iGoogle gadgets/widgets by 
    var hostname = document.location.hostname;
    if (hostname.indexOf('') > 0) {
      document.location.href = ''+document.location.href.substring(document.location.href.indexOf('/', 10));

If your gadget has more than one <content> sections then you need to place above code at the beginning of each <content> sections.

For your reference your can find following my gadget has working adsense ads on igoogle

All In One

All Emails

Yahoo Messenger App

Multiple Chat App!

Share |


Embed Wave to Blogger