Notification

Please make sure to visit Your AdSense Page where you can find personalized information about your account to help you succeed with AdSense.

Ad implementation guidelines

Modifications of AdSense ad code

Some AdSense code modifications are not permitted. Learn about acceptable ad code modifications and what to avoid when implementing your 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 allows you to create an ad layout that fits in with your site.

In general, we recommend you copy and paste 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 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.

If you need more control over your A/B tests, refer to 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="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-publisher-id" crossorigin="anonymous"></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>
Set 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?client=ca-publisher-id" crossorigin="anonymous"">
    <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="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-publisher-id" crossorigin="anonymous""></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 helpful?

How can we improve it?
true
Unlock Growth Potential

Don't miss out on valuable AdSense insights. Opt in to receive performance reports, personalized tips, and webinar invites that can help boost your earnings

Opt in

Search
Clear search
Close search
Google apps
Main menu
12394739589485057287
true
Search Help Center
true
true
true