Ad Types

AdWords 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 AdWords scripts. For an overview of all ad types supported by AdWords, see the API guide.

Creation

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")
    .withFinalUrl("http://www.example.com")
    .withPath1("path1") // optional
    .withPath2("path2") // optional
    .build();

Inspection

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 = AdWordsApp.ads().withCondition("Type = EXPANDED_TEXT_AD").get();
while (iterator.hasNext()) {
  var ad = iterator.next();
  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();
}

Reporting

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 = AdWordsApp.report(
    "SELECT AdGroupId, Id, HeadlinePart1, HeadlinePart2, Clicks, Impressions, Cost " +
    "FROM   AD_PERFORMANCE_REPORT " +
    "WHERE HeadlinePart1 CONTAINS 'Discount Sales' " +
    "DURING LAST_7_DAYS");

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

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

Send feedback about...

AdWords Scripts
AdWords Scripts
Need help? Visit our support page.