Ad Schedules

Add ad schedules for a campaign

function addAdSchedule() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Add a schedule for Monday, 9AM to 5PM, bid modifier = 1.25.
    campaign.addAdSchedule('MONDAY', 9, 0, 17, 0, 1.25);
    // The bid modifier is optional, e.g.
    // campaign.addAdSchedule('MONDAY', 9, 0, 17, 0);

    // You can also add an adSchedule as a JSON object, or using
    // an existing AdSchedule object.
    // Add a schedule for Saturday, 7AM to 11AM, bid modifier = 1.1.
    campaign.addAdSchedule({
      dayOfWeek: 'SATURDAY',
      startHour: 7,
      startMinute: 0,
      endHour: 11,
      endMinute: 0,
      bidModifier: 1.1
    });
  }
}

Get ad schedules for a campaign

function getAdSchedules() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var adScheduleIterator = campaign.targeting().adSchedules().get();

    while (adScheduleIterator.hasNext()) {
      var adSchedule = adScheduleIterator.next();
      Logger.log(formatSchedule(adSchedule));
      Logger.log('Bid modifier : ' + adSchedule.getBidModifier());
    }
  }
}

function formatSchedule(schedule) {
  function zeroPad(number) { return Utilities.formatString('%02d', number); }
  return schedule.getDayOfWeek() + ', ' +
      schedule.getStartHour() + ':' + zeroPad(schedule.getStartMinute()) +
      ' to ' + schedule.getEndHour() + ':' + zeroPad(schedule.getEndMinute());
}

发送以下问题的反馈:

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