Ads

  • Google Ads scripts provide functions to add and manage different types of ads, including expanded text ads, image ads, and responsive display ads.

  • You can pause an ad in an ad group by retrieving the ad and calling the pause() method.

  • Scripts can be used to retrieve iterators for specific ad types within an ad group, such as expanded text ads, text ads, and responsive display ads.

  • Ad statistics for a specific ad group can be retrieved using the getStatsFor() method on an ad object, specifying a date range.

Add a responsive search ad

function addResponsiveSearchAd(adGroupName, campaignName) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${campaignName}"`)
      .get();
  if (!campaignIterator.hasNext()){
      throw new Error(`No campaign found with name: "${campaignName}"`);
  }

  const adGroupIterator = AdsApp.adGroups()
      .withCondition(`ad_group.name = "${adGroupName}"`)
      .get();
  if (!adGroupIterator.hasNext()){
      throw new Error(`No ad group found with name: "${adGroupName}"`);
  }

  const adGroup = adGroupIterator.next();
  adGroup.newAd().responsiveSearchAdBuilder()
    .withHeadlines([
      'First headline',
      'Second headline',
      'Third headline'
    ])
    .withDescriptions([
      'First description',
      'Second description'
    ])
    .withFinalUrl('http://www.example.com')
    .build();
  // ResponsiveSearchAdBuilder has additional options.
  // For more details, see
  // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_responsivesearchadbuilder
}

Add an image ad

function addImageAd(adGroupName,imageUrl,imageName) {
   const imageBlob = UrlFetchApp.fetch