Search
Clear search
Close search
Google apps
Main menu

Ad implementation policies

Modification of the AdSense ad code

Our program policies do not permit any alteration to AdSense code which artificially inflates ad performance or harms advertiser conversions. Your publisher account offers a number of options when generating the ad code, which we hope will allow you to create an ad layout that fits in with your site. In general, we recommend copying and pasting the ad code. In some situations though, we understand that modifications are crucial to a clean user experience.

Techniques to avoid

Here are some techniques you’ll want to avoid:

  • Hiding ad units at anytime (e.g., display:none), unless you're implementing a responsive ad unit
  • Implementing AdSense ad code in a way that covers content or where content covers ads
  • Placing ad units on a mobile site or a responsive design site in such a way which will cause content and ads to overlap
  • Manipulating the ad targeting using hidden keywords, IFRAMEs, or any other method
  • Distributing ads in emails or software
  • Manipulating the delivery or presentation of the ad to attract unwarranted attention (e.g., ads sliding into the screen, ads zooming in/out).
  • Triggering an ad click during user drag actions on a mobile web page.

Acceptable modifications

Here are some acceptable modifications:

Responsive design

The new asynchronous ad code allows you to set the size of an ad through CSS, and optionally media queries, to fit in with your responsive site. Learn more about how to use responsive ad units.

A/B testing

AdSense experiments allow you to compare the performance of different ad type and/or text ad style settings of your ad units. Experiments help you make informed decisions about how to configure your ad units and can help you to increase your earnings. Learn more about experiments.

Should you need more control over your A/B tests, please see the following code snippets:

  • Synchronous ad code:
    <script type="text/javascript">
        var random_number = Math.random();
        google_ad_client = "ca-publisher-id";
        google_ad_width = 728;
        google_ad_height = 90;

        if (random_number < .5){
            google_ad_slot = "1234567890";
        } else {
            google_ad_slot = "2345678901";
        }

    </script>
    <script type="text/javascript"
        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
  • Asynchronous ad code:
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
        style="display:inline-block;width:728px;height:90px"
        data-ad-client="ca-publisher-id">
    </ins>
    <script>
        if (Math.random() < .5) {
          mySlotId = '1234567890';
        } else {
          mySlotId = '2345678901';
        }
        (adsbygoogle = window.adsbygoogle || []).push({
          params: { google_ad_slot: mySlotId }
        });
    </script>
Setting custom channels dynamically
  • Synchronous ad code:
    <script type="text/javascript">
        var channel_condition = object.booleanMethod();
        google_ad_client = "ca-publisher-id";
        google_ad_slot = "1234567890";
        google_ad_width = 728;
        google_ad_height = 90;
        if (channel_condition){
            google_ad_channel = "123457789";
        } else {
            google_ad_channel = "263477489";
        }

    </script>
    <script type="text/javascript"
        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
  • Asynchronous ad code:
    <script async src="http://pagead2.googlesyndication.com/pagead/adsbygoogle.js">
    <ins class="adsbygoogle"
        style="display:inline-block;width:728px;height:90px"
        data-ad-client="ca-publisher-id"
        data-ad-slot="1234567890">
    </ins>
    <script>
        channel_condition = object.booleanMethod();
        if (channel_condition) {
          my_google_ad_channel = '123457789';
        }
        else {
          my_google_ad_channel = '263477489';
        }
        (adsbygoogle = window.adsbygoogle || []).push({
          params: { google_ad_channel: my_google_ad_channel}
        });
    </script>
Ad tag minification
  • Synchronous ad code:
    <script type="text/javascript">
        google_ad_client = "ca-publisher-id";
        google_ad_slot = "1234567890";
        google_ad_width = 728;google_ad_height = 90;
    </script>
    <script type="text/javascript"
        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
  • Asynchronous ad code:
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
        style="display:inline-block;width:728px;height:90px"
        data-ad-client="ca-publisher-id"
        data-ad-slot="1234567890"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

For details on what alterations you're permitted to make to AdSense for search code, see the AdSense for search policies.

Was this article helpful?
How can we improve it?
Sign in to AdSense

Sign in to AdSense to see help for your account

Don't have an AdSense account? Sign Up for AdSense!