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 www.gmodules.com then ads are displayed exactly fine but there is problem when igoogle gadget is loaded from www.ig.gmodules.com or any other host which ends with ig.gmodules.com (e.g jkasdjkasdkj.ig.gmodules.com , pqexlfgjsjkdlfg12jks.ig.ig.gmodules.com 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">
    <![CDATA[ 

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


<script>
    //workaround for showing Adsense ads within iGoogle gadgets/widgets by http://technical-tejash.blogspot.com 
    var hostname = document.location.hostname;
    
    if (hostname.indexOf('ig.gmodules.com') > 0) {
      
      document.location.href = 'http://www.gmodules.com'+document.location.href.substring(document.location.href.indexOf('/', 10));
    }
</script>

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 |

Topics

 
Embed Wave to Blogger