Ad Extensions

Ad extensions including app extensions, call extensions, callout extensions, review extensions and sitelinks are supported through AdWords scripts.

To learn more about ad extensions, visit the help center article.

AdWords scripts allow you to access supported ad extensions in your account. For example, the following code snippet accesses sitelinks:

var sitelinkIterator = AdWordsApp.extensions().sitelinks().get();
while (sitelinkIterator.hasNext()) {
  var sitelink = sitelinkIterator.next();
}

You can retrieve other supported ad extensions similarly using their respective iterators.

Creation

AdWords scripts also allow you to create supported ad extensions. For example, the following code snippet uses a phone number builder to create a phone number in your account:

var phoneNumberBuilder = AdWordsApp.extensions().newPhoneNumberBuilder();
var newPhoneNumber = phoneNumberBuilder
  .withCountry("US")
  .withPhoneNumber("6502530000")
  .withCallOnly(false)
  .build()
  .getResult();

When build() is called, the phone number is created in the account, but it won't show alongside any ads just yet. You need to add it to a campaign or an ad group first:

// Add a phone number to a campaign.
campaign.addPhoneNumber(newPhoneNumber);

// Add a phone number to an ad group.
adGroup.addPhoneNumber(newPhoneNumber);

Other supported ad extensions can be created and associated to campaigns or ad groups in the same way with their respective builders.

Getting stats

AdWords scripts allow you to access stats for supported ad extensions at the account, campaign, or ad group level.

For example, to get sitelink stats:

// Account-level stats
// Get a sitelink in the account.
var sitelinkIterator = AdWordsApp.extensions().sitelinks().get();
var sitelink = sitelinkIterator.next();
var sitelinkStats = sitelink.getStatsFor("LAST_30_DAYS");
Logger.log(sitelinkStats.getClicks());

// Campaign-level stats.
// Get a sitelink in a campaign.
var campaignSitelinkIterator = campaign.extensions().sitelinks().get();
var campaignSitelink = campaignSitelinkIterator.next();
var campaignSitelinkStats = campaignSitelink.getStatsFor("LAST_30_DAYS");
Logger.log(campaignSitelinkStats.getClicks());

// Ad-group-level stats.
// Get a sitelink in an ad group.
var adGroupSitelinkIterator = adGroup.extensions().sitelinks().get();
var adGroupSitelink = adGroupSitelinkIterator.next();
var adGroupSitelinkStats = adGroupSitelink.getStatsFor("LAST_30_DAYS");
Logger.log(adGroupSitelinkStats.getClicks());

Stats for other supported ad extensions can be accessed in a similar way.

Modifying ad extensions

Existing supported ad extensions can be modified with AdWords scripts. For example, the following code snippet will modify an existing sitelink:

// Get a sitelink in the account.
var sitelinkIterator = AdWordsApp.extensions().sitelinks().get();
var sitelink = sitelinkIterator.next();
Logger.log(sitelink.getLinkText()); // "original text"

// Get a sitelink from a campaign. Assume it's the same one as above.
var campaignSitelinkIterator = campaign.extensions().sitelinks().get();
var campaignSitelink = campaignSitelinkIterator.next();
Logger.log(campaignSitelink.getLinkText()); // "original text"

// Get a sitelink from an ad group. Assume it's the same one as above.
var adGroupSitelinkIterator = adGroup.extensions().sitelinks().get();
var adGroupSitelink = adGroupSitelinkIterator.next();
Logger.log(adGroupSitelink.getLinkText()); // "original text"

// Change the sitelink's link text. This change will affect all the campaigns and ad
// groups to which the sitelink belongs.
campaignSitelink.setLinkText("new link text");

// Same text!
Logger.log(campaignSitelink.getLinkText()); // "new link text"
Logger.log(adGroupSitelink.getLinkText()); // "new link text"
Logger.log(sitelink.getLinkText()); // "new link text"

Note: If you modify a Sitelink, it will affect ads serving in all the campaigns and ad groups that the sitelink is associated with. This rule applies whether you retrieved the sitelink directly from the account, from a CampaignSitelink of an associated campaign, or from an AdGroupSitelink of an associated ad group. The preceding code example demonstrates this behavior.

The same concepts apply for other supported ad extensions.

Accessing ad-group-level ad extensions

AdWords scripts allow you to access ad-group-level ad extensions. The following method call will return phone numbers that have been explicitly added to an ad group. Note that if phone numbers have been added to the campaign to which the ad group belongs, the following method call will not return them even when the phone numbers are eligible to appear on ads served from that ad group.

// This will return phone numbers that have been explicitly added to this ad group.
var adGroupPhoneNumberIterator = adGroup.extensions().phoneNumbers().get();

Other supported ad extensions can be accessed at the ad group level in a similar way.

Accessing account-level ad extensions

AdWords scripts allow you to access account-level ad extensions. Callouts, mobile apps, and reviews can be added as account-level ad extensions, but account-level sitelinks and phone numbers are not available. The following method call will return callouts that have been explicitly added to your account.

// This will return callouts that have been explicitly added to your account.
var accountCalloutIterator =
    AdWordsApp.currentAccount().extensions().callouts().get();

Account-level mobile apps and reviews can be accessed in a similar way.

Adding account-level ad extensions is similar to adding campaign-level or ad-group-level ad extensions. The following example demonstrates how to add an account-level callout extension:

// Create a new callout in the account. Without adding the new callout as an ad
// group, campaign or account extension, it won't actually serve.
var calloutBuilder = AdWordsApp.extensions().newCalloutBuilder();
var newCallout = calloutBuilder.withText("Sample Text").build().getResult();

// Add the new callout as an account-level extension. This allows it to serve
// for all campaigns in the account.
AdWordsApp.currentAccount().addCallout(newCallout);

Account-level mobile apps and reviews can be added in a similar way.

Removing campaign, ad group, and account ad extensions

Supported ad extensions can be removed from campaigns and ad groups at the account level. AdWords scripts do not support removing ad extensions from an account all at once.

// Get a mobile app from a campaign.
var campaignMobileAppIterator = campaign.extensions().mobileApps().get();
var campaignMobileApp = campaignMobileAppIterator.next();

// Remove the mobile app.
campaign.removeMobileApp(campaignMobileApp);

// The mobile app still exists in the account and will be returned in the following
// iterator.
var mobileAppIterator = AdWordsApp.extensions().mobileApps().get();

Similarly, to remove an ad-group-level or account-level mobile app:

// Get a mobile app from an ad group.
var adGroupMobileAppIterator = adGroup.extensions().mobileApps().get();
var adGroupMobileApp = adGroupMobileAppIterator.next();

// Remove the mobile app.
adGroup.removeMobileApp(adGroupMobileApp);

// Get an account-level mobile app.
var accountMobileAppIterator =
    AdWordsApp.currentAccount().extensions().mobileApps().get();
var accountMobileApp = accountMobileAppIterator.next();

// Remove the mobile app.
// Note that this removes the mobile app from the account level, so it will
// not serve as an account-level extension, but it will still exist in the
// account. It can still be added to an AdGroup or Campaign, or again as an
// account-level extension in the future.
AdWordsApp.currentAccount().removeMobileApp(accountMobileApp);

If all mobile apps are removed from a campaign, the campaign will no longer have a mobile app extension. To remove all mobile apps from your campaign, you need to retrieve the list of mobile apps for that campaign and remove them one at a time. The procedure is the same for other supported ad extensions.

AdWords scripts and feeds

AdWords scripts can only be used to retrieve extensions in the default feed; items in custom feeds are not supported. All extensions created through the AdWords frontend are created in the default feed. For more information on custom feeds, please visit the AdWords API documentation on feeds.

Send feedback about...

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