Modifying Adsense Code for Responsive Design is no longer a Violation


Good News for Google Adsense Publishers, Google rolls out a new modification in its Adsense Privacy Policy. Previously Adsense publishers were not allowed to alter the ad code provided by Adsense. I have never heard any stories where people were banned due to changing their Adsense Code in blogs, though there are cases which were discussed in Google product forums. Majority of times I only knew people getting banned due to invalid click activity, copyright violation, placing ads in pages that contain content that violates their content guidelines and improper placement of ads enhancing user to click their ads.


Some people also play smart tricks by copying the adsense code and placing in sites which violates content guidelines without the knowledge of the original publisher. Shawn Hogan who runs one of the most popular forums called digitalpoint was also banned due to placing his Adsense code in a gambling site. Truth is that some of his rivals who wanted to get his account banned have placed his Adsense code in such sites which had an immediate effect on Shawn’s Adsense account. Later he got his account back as he explained the situation.

Saad Naeem a blogger who writes for Seoallrounder got his account banned when one of his rivals has click bombed (repeatedly clicked on ads to get account banned) but he too got his account back on clearly explaining that he was innocent and also revealed the culprit who did it. There are many stories of this kind but there are only few instances where people get banned due to changing there adsense code. If at all there is an issue with ad code then Adsense team will send a message as follows.

Ad serving has been disabled

MODIFIED AD TARGETING: Publishers are not permitted to alter the behavior of Google ads in any way. This includes altering the targeting of ads using hidden or irrelevant keywords, or manipulating ad targeting through IFRAMES.

Now Google has allowed publishers to change their adsense code provided the modification doesn’t harm the advertiser or artificially inflate the ad performance. They have allowed the user to modify the adsense code for only few of the following reasons.
Responsive Design
A/B Testing
Setting custom channels dynamically
Ad tag minification

I have also given below an excerpt from adsense official blog which posted this news on May 23rd 2013.

The publisher is limited to some unfair methods like they should not hide ad units, the ad shouldn’t cover the content, should not force more than 3 ad units, should not send ad code in emails or softwares, should not use iframes, should not float the ads.

Web trends and technology demand that your site evolves quickly to maintain a growing user base. We’ve heard your questions and feedback on areas like responsive design, and we’re happy to let you know that we’ve updated our existing guidelines around modifying the AdSense ad code. We hope that this increased flexibility will help you continue enhancing the user experience on your site.

Going forward, we will permit publishers to make modifications to the AdSense ad code so long as those modifications do not artificially inflate ad performance or harm advertisers and otherwise comply with our Terms and Conditions and program policies. This will enable you to try a range of techniques on your site such as:
Responsive design: Enabling publishers to create a single webpage that will adapt to the device on which it’s being viewed, whether it’s a laptop, smartphone or tablet, to maximize user experience.
•  A/B testing: Running a test by creating multiple versions of a page, comparing user behavior to see which page is the most effective.
Setting custom channels dynamically: Tracking performance of segments of users, sections of your site, or other behavior to maximize ad and user experience.
Ad tag minification: Enabling your site pages to load faster by reducing the amount of data to be transferred.

How to change adsense code for responsive Design:

These days as the rise of smart phones and tablets have been increased in usage and there has been an urge for using responsive design to fit the screens of various resolutions. One of my friend Angela had written an article on Why You Need Responsive Design which might help you in giving an idea on responsive design.

So when a user is using 320 px wide Ad unit it is OK when the screen size is less than 500px but when it goes to a larger resolution screen like 800 px then that ad unit wont fill the required space. So in order to meet the requirement of serving various ads for various screen resolutions you can modify the code as per your requirement. When the screen size is more than 800px you can switch to 728px width ad and if it more than 500px you can opt for 468px Ad unit. Below I have given an example on how to modify the code to meet the requirement of our page design as suggested by Adsense.

Actual Code

<script type=”text/javascript”>
google_ad_client = “ca-publisher-id”;
google_ad_slot = “1234567890”;
google_ad_width = 320;
google_ad_height = 50;
<script type=”text/javascript” src=””>

Modified Code to meet the requirements of responsive design as given in Adsense Support.

<script type=”text/javascript”>
google_ad_client = “ca-publisher-id”;
width = document.documentElement.clientWidth;
google_ad_slot = “1234567890”;
google_ad_width = 320;
google_ad_height = 50;
if (width > 500) {
google_ad_slot = “3456789012”;
google_ad_width = 468;
google_ad_height = 60;
if (width > 800) {
google_ad_slot = “2345678901”;
google_ad_width = 728;
google_ad_height = 90;
<script type=”text/javascript” src=””>

So the above code will display 320px ad when the user views in a mobile screen whose screen is less than 500Px, and it displays 468 px ad unit when the screen is more than 500 px and 728 ad unit when screen size is more than 800 px. A/B testing is used for setting the ad unit with higher CTR (click through rate) visit Modification of the AdSense ad code for more details on how to use. I think now it is time to modify your adsense code as per your requirement provided you stay within the limits prescribed by adsense.


  1. We are blocked once for editing adsense codes , even when google allowed that but i alredy recvd one warning for violating adsense rule so now i fear to do any such edits in adsense code.

    • Hi Vishnu,
      Thanks for your voice, I didn’t know that Google allowed modifying adsense code previously. If you have already received a warning its better to stay calm and enjoy whatever you earn rather than loosing an account. As it is very difficult to get back a disabled adsense account. Anyways thanks for your visit and do stay in touch…

  2. Wow Vijesh…

    I feel so honored you mentioned my post in your blog. Thank you very much my friend, you are awesome!!! I do have the Adsense approved on my YouTube channel. But I decided to keep the Adsense off of my blog for now. BTW, I do have a question but I will email it to you instead. I don’t want to expose it here on public. Will talk more later. Have a great manic Monday!

    It’s 2:35 AM here and I’m still awake. Yikes!! Okay, will see you later.


    • Thanks Angela for taking some time to share your views here.
      Glad that you’ve got adsense approved for your YouTube channel try to create some wonderful videos you will make most out of videos compared to blogs.

  3. I don’t use Adsense, so I don’t know about this issue.

    However, with the rising of responsive design, the change in TnC in Google Adsense is just in time. I’m pretty sure lots of folks want to optimize their earning from mobile users.

    Btw, can we use the same code above for the ads from other company?

  4. I just changed mine like this and increased my Adsense revenue in 30% from one of my websites.
    That only because more than 30% of our traffic were coming from mobile devices, and it seems to convert higher than desktop ads.

    • Hi Servando,
      Good to know that you have an increase in 30% of your Adsense revenue. These days mobile users are increasing and it is a good move by Adsense team to implement such terms.
      Thanks for your comment Servando…

  5. Hi Vijesh,
    Useful news and information again. I remember that Amit Agarwal of had written to Google about this and created his own version of responsive ad code. Google had positively replied to him some time back in last year. Now Google has officially declared the responsive ad solution and it has come at a good time for me because I am also using responsive design on my blog and going to us the responsive code for large horizontal ad units. Thanks for information Vijesh.

    • Hi Suhas,
      I think you are constantly in touch with labnol, a great blog indeed but Amit is a busy man he gets tons of emails a day I guess. Your design looks cool but for newbies it is not a user friendly one it doesn’t look like a blog instead it looks like a site. Only if someone visits your site regularly then they can understand the navigation. But the look of the site is professional and glad to know that you are going to use the code for large horizontal ads.

  6. This is really a good news as you said i will surely try this out but what about some low screen mobiles can it automatically display ads for mobile instead of content

  7. A very brilliant post Vijesh,
    I’ve also heard a lot of this when i started blogging that we should not alter on the color of our ads that its against their TOS. I’m happy that it is not legal.

    You know, Google is now changing so many things which is very good. I also got an email from them 2 months ago that they now accept placement on ads on gaming sites which is also against their TOS before.

    That’s why there is a saying that change is constant. I’m happy that Google is also changing for good.

    Thanks for sharing my man and happy new month :).

  8. I’m happy i also came across this post of your Vijesh,
    This is so interesting indeed. I’m very happy the way Google is changing most of their formal TOS these days and its all for our benefits, don’t you think so?

    Thanks a lot for sharing this with us. Really interesting.

  9. Hello,Vijesh

    Your post on Modifying Adsense Code was very well written and in fact it I was not much aware on this information of Google Adsense .
    Superb Post


  10. As a newbie eagerly reading your posts..I was not focused on mobile phone friendly ads yet because my blog theme was not responsive.What should i do for better adsense revenue .,to change theme or make a sub domain like

  11. @ Vipin C i suggest you try and improve your blog traffic, adsense is all about traffic and your Niche type, any blog without more trafffic will never be happy with adsense earnings and mind you that some Niche blog don’t work well with adsense, alternative would be affiliate marketing


Please enter your comment!
Please enter your name here