Ad Params

Create text ad with ad parameters for an ad group

function setupAdParamsInAdGroup() {
  // If you have multiple adGroups with the same name, this snippet will
  // pick an arbitrary matching ad group each time. In such cases, just
  // filter on the campaign name as well:
  //
  // AdWordsApp.adGroups()
  //     .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
  //     .withCondition('CampaignName = "INSERT_CAMPAIGN_NAME_HERE"')
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    adGroup = adGroupIterator.next();

    adGroup.newAd().expandedTextAdBuilder()
        .withHeadlinePart1('Holiday sale')
        .withHeadlinePart2(
            'Starts in {param1: a few} days {param2: and} hours!')
        .withDescription('Everything must go!')
        .withFinalUrl('http://www.example.com/holidaysales')
        .build();

    var keywordIterator = adGroup.keywords().get();
    if (keywordIterator.hasNext()) {
      keyword = keywordIterator.next();
      // Setup Ad to show as 'Doors open in 5 days, 7 hours!' when searched
      // using this keyword. If the ad is triggered using a keyword
      // without ad param, the ad shows as
      // 'Doors open in a few days, and hours!'
      keyword.setAdParam(1, 5);
      keyword.setAdParam(2, 7);
    }
  }
}

Get ad parameters for a keyword

function getAdParamsForKeyword() {
  // If you have multiple adGroups with the same name, this snippet will
  // pick an arbitrary matching ad group each time. In such cases, just
  // filter on the campaign name as well:
  //
  // AdWordsApp.adGroups()
  //     .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
  //     .withCondition('CampaignName = "INSERT_CAMPAIGN_NAME_HERE"')
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    adGroup = adGroupIterator.next();
    var keywordIterator = adGroup.keywords()
        .withCondition('Text = "Holiday sales"')
        .get();
    if (keywordIterator.hasNext()) {
      keyword = keywordIterator.next();
      var adParamIterator = keyword.adParams().get();
      while (adParamIterator.hasNext()) {
        var adParam = adParamIterator.next();
        logAdParam(adParam);
      }
    }
  }
}

function logAdParam(adParam) {
  Logger.log('Keyword : ' + adParam.getKeyword().getText());
  Logger.log('MatchType : ' + adParam.getKeyword().getMatchType());
  Logger.log('Index : ' + adParam.getIndex());
  Logger.log('Insertion Text : ' + adParam.getInsertionText());
}

发送以下问题的反馈:

此网页
AdWords Scripts
AdWords Scripts
需要帮助?请访问我们的支持页面