This is the legacy documentation for Google Ads scripts. Go to the current docs.

Ad Types

Google Ads supports a variety of ad types, such as text, image, and mobile ads. This guide covers how to create, retrieve, and report on ads using Google Ads scripts. For an overview of all ad types supported by Google Ads, see the API guide.


Scripts can create ads using the newAd() method on AdGroup instances. This returns an AdBuilderSpace, which creates builders for supported ad types.

The following snippet demonstrates how to create an expanded text ad:

var adOperation = adGroup.newAd().expandedTextAdBuilder()
    .withHeadlinePart1("First headline part")
    .withHeadlinePart2("Second headline part")
    .withDescription("Ad description")
    .withPath1("path1") // optional
    .withPath2("path2") // optional


Some information associated with all ad types is immediately available from an Ad, such as an ad's ID and approval status. Additionally, any ad can be paused, enabled, or removed.

To access fields specific to an ad's type, such as an expanded text ad's description, use the asType() method to create an AdViewSpace. This provides access to an extended version of the Ad that exposes type-specific methods.

The following snippet finds the description of every expanded text ad:

var iterator ="Type = EXPANDED_TEXT_AD").get();
while (iterator.hasNext()) {
  var ad =;
  var expandedTextAd = ad.asType().expandedTextAd();
  var description = expandedTextAd.getDescription();

Notice that the condition Type = EXPANDED_TEXT_AD ensures every ad from the iterator is an expanded text ad. Attempting to view an ad with an incorrect type will result in an error that stops your script's execution, so it's important to view type-specific fields only when an ad's type is known.

The following snippet shows how to determine if an ad is of the correct type using the Ad.isType() method:

if (ad.isType().expandedTextAd()) {
  var expandedTextAd = ad.asType().expandedTextAd();
  var headlinePart1 = expandedTextAd.getHeadlinePart1();
  var headlinePart2 = expandedTextAd.getHeadlinePart2();

Handling legacy responsive display ads

Creating an ad iterator with condition Type = RESPONSIVE_DISPLAY_AD will currently iterate over legacy ads only. This condition is deprecated; please update existing code to explicitly use Type = LEGACY_RESPONSIVE_DISPLAY_AD. To create an ad iterator over ads that support multiple text, image, and video assets, use the condition Type = MULTI_ASSET_RESPONSIVE_DISPLAY_AD.

The following snippet illustrates some of the API differences and similarities between the two types of responsive display ads. Please read the Responsive Display Ad reference for more details.

// var legacyRdaIterator ="Type = RESPONSIVE_DISPLAY_AD").get();
var legacyRdaIterator ="Type = LEGACY_RESPONSIVE_DISPLAY_AD").get();
while (legacyRdaIterator.hasNext()) {
  var responsiveDisplayAd =;

  // Legacy responsive display ads have just one long headline.
  var longHeadline = responsiveDisplayAd.getLongHeadline();

  // And they have one short headline, too.
  var shortHeadline = responsiveDisplayAd.getShortHeadline();

  // This call to .getHeadlines() returns null, because the method is not
  // meaningful when called on a legacy responsive display ad.
  assert(responsiveDisplayAd.getHeadlines() === null);

  // ... etc. ...

var rdaIterator ="Type = MULTI_ASSET_RESPONSIVE_DISPLAY_AD").get();
while (rdaIterator.hasNext()) {
  var responsiveDisplayAd =;

  // Responsive display ads have just one long headline.
  var longHeadline = responsiveDisplayAd.getLongHeadline();

  // But they can have multiple short headline text assets.
  var shortHeadlineAssets = responsiveDisplayAd.getHeadlines();

  // This call to .getShortHeadline() returns null, because the method is only
  // meaningful when called on a legacy responsive display ad.
  assert(responsiveDisplayAd.getShortHeadline() === null);

  // ... etc. ...

while (rdaAndLegacyIterator.hasNext()) {
  var responsiveDisplayAd =;
  var longHeadline = responsiveDisplayAd.getLongHeadline();

  // The .isLegacy() method can be used to differentiate between responsive
  // display ad types within an iterator over both.
  if (responsiveDisplayAd.isLegacy()) {
    var shortHeadline = responsiveDisplayAd.getShortHeadline();
    // ... etc. ...
  } else {
    var shortHeadlineAssets = responsiveDisplayAd.getHeadlines();
    // ... etc. ...


The AD_PERFORMANCE_REPORT can also be used to query type-specific ad fields in addition to regular stats, such as expanded text ad fields. The following snippet shows how to retrieve the stats for all expanded text ads that contain "Discount Sales" in headline 1:

var report =
    "SELECT AdGroupId, Id, HeadlinePart1, HeadlinePart2, Clicks, Impressions, Cost " +
    "WHERE HeadlinePart1 CONTAINS 'Discount Sales' " +

var rows = report.rows();
while (rows.hasNext()) {
  var row =;
  var headlinePart1 = row["HeadlinePart1"];
  var headlinePart2 = row["HeadlinePart2"];

See the reports guide for more information on reporting in scripts.