Campaigns

Get all campaigns

function getAllCampaigns() {
  // AdWordsApp.campaigns() will return all campaigns that are not removed by
  // default.
  var campaignIterator = AdWordsApp.campaigns().get();
  Logger.log('Total campaigns found : ' +
      campaignIterator.totalNumEntities());
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    Logger.log(campaign.getName());
  }
}

Get a campaign by name

function getCampaignsByName() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    Logger.log('Campaign Name: ' + campaign.getName());
    Logger.log('Enabled: ' + campaign.isEnabled());
    Logger.log('Bidding strategy: ' + campaign.getBiddingStrategyType());
    Logger.log('Ad rotation: ' + campaign.getAdRotationType());
    Logger.log('Start date: ' + formatDate(campaign.getStartDate()));
    Logger.log('End date: ' + formatDate(campaign.getEndDate()));
  }
}
function formatDate(date) {
  function zeroPad(number) { return Utilities.formatString('%02d', number); }
  return (date == null) ? 'None' : zeroPad(date.year) + zeroPad(date.month) +
      zeroPad(date.day);
}

Get a campaign's stats

function getCampaignStats() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // You can also request reports for pre-defined date ranges. See
    // https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_campaign#getStatsFor_1,
    // DateRangeLiteral section for possible values.
    var stats = campaign.getStatsFor('LAST_MONTH');
    Logger.log(campaign.getName() + ', ' + stats.getClicks() + 'clicks, ' +
        stats.getImpressions() + ' impressions');
  }
}

Pause a campaign

function pauseCampaign() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    campaign.pause();
  }
}

Get a campaign's device bid modifiers

function getCampaignBidModifiers() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    Logger.log('Campaign name: ' + campaign.getName());

    var platformIterator = campaign.targeting().platforms().get();
    while (platformIterator.hasNext()) {
      var platform = platformIterator.next();
      Logger.log(platform.getName() + ' bid modifier: ' +
          platform.getBidModifier());
    }
  }

发送以下问题的反馈:

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