Keywords

Add a keyword to an existing ad group

function addKeyword() {
  // 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()) {
    var adGroup = adGroupIterator.next();

    adGroup.newKeywordBuilder()
        .withText('Hello world')
        .withCpc(1.25)                          // Optional
        .withFinalUrl('http://www.example.com') // Optional
        .build();

    // KeywordBuilder has a number of other options. For more details see
    // https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_keywordbuilder
  }
}

Pause an existing keyword in an ad group

function pauseKeywordInAdGroup() {
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    var keywordIterator = adGroup.keywords()
        .withCondition('Text="INSERT_KEYWORDS_HERE"').get();
    while (keywordIterator.hasNext()) {
      var keyword = keywordIterator.next();
      keyword.pause();
    }
  }
}

Get all keywords in an ad group

function getKeywordsInAdGroup() {
  var keywordIterator = AdWordsApp.keywords()
      .withCondition('AdGroupName = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (keywordIterator.hasNext()) {
    while (keywordIterator.hasNext()) {
      var keyword = keywordIterator.next();
      Logger.log(formatKeyword(keyword));
    }
  }
}

function formatKeyword(keyword) {
  return 'Text : ' + keyword.getText() + '\n' +
      'Match type : ' + keyword.getMatchType() + '\n' +
      'CPC : ' + keyword.bidding().getCpc() + '\n' +
      'Final URL : ' + keyword.urls().getFinalUrl() + '\n' +
      'Approval Status : ' + keyword.getApprovalStatus() + '\n' +
      'Enabled : ' + keyword.isEnabled() + '\n';
}

Get stats for all keywords in an ad group

function getKeywordStats() {
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    var keywordIterator = adGroup.keywords().get();
    while (keywordIterator.hasNext()) {
      var keyword = keywordIterator.next();
      // You can also request reports for pre-defined date ranges. See
      // https://developers.google.com/adwords/api/docs/guides/awql,
      // DateRangeLiteral section for possible values.
      var stats = keyword.getStatsFor('LAST_MONTH');
      Logger.log(adGroup.getName() + ', ' + keyword.getText() + ', ' +
          stats.getClicks() + ', ' + stats.getImpressions());
    }
  }
}

发送以下问题的反馈:

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