Technology Blog, Wordpress Tips & Tricks, Thesis Theme Tutorial, Genesis Framework Guides.

Responsive Web Design and Google Adsense

These days lot of people access website on smartphones and tablets, which has made the life of the web designers and developers more difficult, thanks to Apple and Google for giving smartphone and tablets in almost every hand. A recent survey mentions that 35% of American adults have smartphones and 87% of them access internet on their phones. That is the reason most of the big websites are working on responsive web designs.

Google has also officially recommended that website owners use the responsive design approach instead of maintaining separate mobile and desktop website as responsive design “keeps your desktop and mobile content on a single URL.”

Google Adsense And Responsive Layouts

Its likely that you use Adsense to monetize the content on your website but the problem is that ads delivered by adsense are not responsive, which means that if a user visits a responsive website on a smartphone all the Adsense ads will be delivered of the same size. Lets take an example to make things more clear, if a website is using 728×90 banner and you are viewing the website on a mobile phone, the webpage might extend beyond the screen. That being said, how can we deliver ads of different size based on the viewer screen. Google Adsense is not responsive by design, but can be made to work with your responsive design with a simple Javascript code.

<!-- You can add multiple Adsense Ad units -->
<!-- Just change the ad on Line #4 and Line #7 -->
 
<div id="google-ads-1">
 <script type="text/javascript">
 
	adUnit   = document.getElementById("google-ads-1");
	adWidth  = adUnit.offsetWidth;
 
	/* Replace this with your AdSense Publisher ID */
	google_ad_client = "ca-pub-1234567890";
 
	if ( adWidth >= 768 ) {
	  /* Leaderboard 728x90 */
	  google_ad_slot	= "AAA";
	  google_ad_width	= 768;
	  google_ad_height 	= 90;
	} else if ( adWidth >= 468 ) {
	  /* Banner (468 x 60) */
	  google_ad_slot	= "BBB";
	  google_ad_width 	= 468;
	  google_ad_height 	= 60;
	} else if ( adWidth >= 336 ) {
	  /* Large Rectangle (336 x 280) */
	  google_ad_slot 	= "CCC";
	  google_ad_width 	= 336;
	  google_ad_height 	= 280;
	} else if ( adWidth >= 300 ) {
	  /* Medium Rectangle (300 x 250) */
	  google_ad_slot 	= "DDD";
	  google_ad_width 	= 300;
	  google_ad_height 	= 250;
	} else if ( adWidth >= 250 ) {
	  /* Square (250 x 250) */
	  google_ad_slot	= "EEE";
	  google_ad_width 	= 250;
	  google_ad_height 	= 250;
	} else if ( adWidth >= 200 ) {
	  /* Ad Link Unit (200 x 90) */
	  google_ad_slot 	= "FFF";
	  google_ad_width 	= 200;
	  google_ad_height 	= 90;
	} else {
	  /* Do not display the Google Ad */
	  google_ad_slot		= "0";
	  adUnit.style.display	= "none";
	}
 </script>
 
 <script type="text/javascript"    
   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
 </script>
</div>

Thanks to Amit from Digital Insipiration for this awesome code.

Lets make our hands dirty and try to understand this code. We are basically using the javascript offsetwidth property to get the width of the div element which encloses the google ad and based on the width we are delivering different ad banners and if the screen width is too small we are not displaying the ad at all.

To get started, create multiple ad units (say 768×90, 468×60 and 300×250) inside your AdSense dashbaord and replace the relevant google_ad_client (ca-pub-1234) and google_ad_slot (AAA, BBB, etc.) identifiers in the code with your own values.

Let me know how this goes. Until next time..!!!

Ten Worst Security Threats in the World of Digital Satellite Television

The modern technological era has its bright side and its dark side. We know all about the bright side and how it has improved our lives. The advancements being made today are unprecedented and it seems as if this is only the beginning. With time we … [Continue reading]

Import Contacts from iPhone to Android

After 4 years of loyalty with Apple I finally decided to move to Android and bought my new shiny [[[Samsung Galaxy Note II]]]. I was impressed with the device as soon as I got it in my hands. After a few minutes I realized that I have a few hundred … [Continue reading]

How Can EyeTV Mobile for iPhones and iPads Rule the Android Industry?

The last century has witnessed a remarkable revolution in terms of technology. The progress graph shapes steeply upwards and can even become an almost vertical line in a short span of time. This is because advancements are taking up at a very rapid … [Continue reading]

How to Make Outlook As Default Mail Client in Mac OS X

Microsoft Outlook 2011 for Mac

If you are have moved from Windows to Mac but still are using Microsoft Outlook as your Email Client. This tip might be helpful for you. You might be wondering why do you  need to setup Outlook as default email client, rather you can just open MS … [Continue reading]

Make Unlimited Free International Calls with Skype for a Month

Skype Logo

Holiday Season is here and its that time of the year when every one is busy calling their families and friends. This year is special as you can call your far-away relatives and friends without worrying about the international call bills. Isn't that a … [Continue reading]

Thesis 2.0 is Available for Download

Long awaited Thesis 2.0 theme is available for download since October 1, 2012 and comes packed with a bunch of new features, actually let me correct myself the whole theme itself has changed and new thesis theme has been designed to make customizing … [Continue reading]

Improved Ad Targeting and Relevancy using Robots.txt

As a website publisher you must have been looking for ways to optimize Google AdSense to monetize your content. There are a bunch of ways for that namely using standard ad formats, using mix of rich and text ads and most importantly writing unique … [Continue reading]

How to Enable Private Browsing in Firefox automatically

Change Firefox Address Bar Search Provider

If you like Mozilla Firefox’s private browsing mode and want to enable it by default. Here are few simple steps to do the same. Launch Firefox and type “about:config”  in the address bar. You will get a warning to be careful as any wrong … [Continue reading]

Gmail Advanced Search Gets Autocomplete in ‘To’ and ‘From’ Fields

advancedautocomplete.png

Google is committed to make the life simpler by adding more and more features to its products. While lot of people are still accustoming to the new look and feel of Google products. Last Week Google announced additional language support in Gmail … [Continue reading]