Ad code implementation

How to replace your Google Ad Manager ad tags with AdSense ad code

This guide shows you how to export a list of your Ad Manager ad units, set up ads in AdSense, and then retag your site with AdSense ad code.

There are three ways you can place ads with AdSense:

  • Auto ads
  • Manual ads
  • Manual ads and Auto ads (recommended)

Auto ads are a new way to place ads on your pages. Auto ads use machine learning to automatically insert ads at optimal times when they’re likely to perform well for you and provide a good experience for your users. We recommend you use manual ads and Auto ads together to have control over some ad placements but also leverage the automation which is unique to AdSense. Auto ads detect manually placed ads so they only insert ads where there's available space.

Step 1. Export your Ad Manager ad units to a spreadsheet

Export a list of all your ad units that currently use the Google Publisher Tag (GPT tag), by following these steps:

  1. Sign in to Google Ad Manager.
  2. Click Inventory and then Ad units.
  3. Click Download ad units. A spreadsheet in CSV format is automatically downloaded.
  4. Open the spreadsheet to see the list of your ad units including key parameters such as Name, Sizes, Description, etc.

Step 2. Set up ads in your AdSense account

Set up Auto ads (recommended)

Follow these steps to set up Auto ads:

  1. Sign in to your AdSense account.
  2. Click My ads and then Auto ads.
  3. On the "Choose your global settings" page, use the controls to select the ad formats that you'd like to show.
  4. Paste the ad code between the <head> and </head> tags of each page where you want to show Auto ads. If you're not sure how to do this, see the Code implementation guide.
  5. (Optional) If you want to show different ad formats on different parts of your site, see Create a URL group for Auto ads.

Create manual ad units

Follow these steps to generate new AdSense ad code to replace your existing Google Ad Manager ad tags. You can create responsive ads or fixed-sized ads to match the ad units listed in the spreadsheet you created in step 1.

  1. Sign in to your AdSense account.
  2. Click My ads and then Ad units and then + New ad unit.
  3. On the "What type of ad would you like to create?" page, select an ad type. Refer back to your spreadsheet to help you select an ad type that matches your original Ad Manager ad unit.

    In addition to Text & display ads, AdSense offers easy to customize Native ads such as In-feed, In-article and Matched content that are unique to AdSense. This is one of the key benefits of using AdSense. We recommend you try testing a new Native format.

  4. Create all the AdSense ad units you need to replace your Ad Manager ad units. Learn how to get and copy the ad code.
    Note that if you're using responsive ad sizes, you might not need all the sizes that you previously used in your Ad Manager ad units.

Step 3. Retag your site with AdSense ad code

Follow these steps to remove the Ad Manager ad tags from your pages and replace them with AdSense ad code:

  1. Delete the following code from the <head> tag of each page:
    • The boilerplate that loads the ad tag library used by Ad Manager. For example:

      <script async="async" src="">
        var googletag = googletag || {};
        googletag.cmd = googletag.cmd || [];

    • The specifications for the ad. For example:

      googletag.cmd.push(function() {
        googletag.defineSlot("/1234/travel/asia", [728, 90], "div-gpt-ad-123456789-0")
        .setTargeting("interests", ["sports", "music", "movies"]);
        googletag.defineSlot("/1234/travel/asia", [[468, 60], [728, 90], [300, 250]], "div-gpt-ad-123456789-1")
        .setTargeting("gender", "male")
        .setTargeting("age", "20-30");

  2. Delete the following code from the <body> tag of each page:

    <div id="div-gpt-ad-123456789-0" style="width: 728px; height: 90px">
      googletag.cmd.push(function() {
    <div id="div-gpt-ad-123456789-1">
      googletag.cmd.push(function() {

    Note: This is a sample of an asynchronous GPT tag and not every line may be present in your own tag.
  3. Replace the deleted Ad Manager ad tags with the equivalent AdSense ad code from the ad units that you created in step 2.
Turn on Auto ads in addition to manual ads so Google can find additional ad placements to insert optimized ads on your site.

Step 4. (Optional) Create an ads.txt file for your site

Creating an ads.txt file gives you more control over who's allowed to sell ads on your site and helps prevent counterfeit inventory from being presented to advertisers. You don't have to use ads.txt, but we highly recommend that you do. Learn more about ads.txt.

To create an ads.txt file:

  1. Create a text (.txt) file.
  2. Include the following line:, pub-0000000000000000, DIRECT, f08c47fec0942fa0

    Important: Make sure you replace pub-0000000000000000 with your own AdSense publisher ID.
  3. Host your ads.txt on your root domain (for example,
Was this helpful?
How can we improve it?