SEMBooster

Script for Amending Active Campaigns Ad Schedule

/*
** Iterates all the active campaigns in the account and amends the schedule for Sunday to be 12PM-12AM
** Users of this script should amend to the relevant day and/or times.
** Bid modifier can be added as the last (optional) parameter in function: addAdSchedule
** Adwords script documentation:
** https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_adschedule?hl=sv-SE
*/

function main() {

var campaignIterator = AdWordsApp.campaigns().withCondition(“Status = ENABLED”).get();

while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var adScheduleIterator = campaign.targeting().adSchedules().get();
var scheduleExists = false;

while (adScheduleIterator.hasNext()) {
scheduleExists = true;
var adSchedule = adScheduleIterator.next();
Logger.log(‘Campaign ‘ + campaign.getName() +’ has a schedule for day ‘ + adSchedule.getDayOfWeek());

// removing the existing schedule for the day downtime is scheduled for
if( adSchedule.getDayOfWeek() == “SUNDAY”){
adSchedule.remove();
Logger.log(‘Removed Schedule for ‘ + adSchedule.getDayOfWeek());
};
};

if( !scheduleExists )
{
/* If there was no schedule (ads running all days/times) then we need to add all other days specifically so that they won’t be excluded */

campaign.addAdSchedule(‘MONDAY’, 0, 0, 24, 0);
campaign.addAdSchedule(‘TUESDAY’, 0, 0, 24, 0);
campaign.addAdSchedule(‘WEDNESDAY’, 0, 0, 24, 0);
campaign.addAdSchedule(‘THURSDAY’, 0, 0, 24, 0);
campaign.addAdSchedule(‘FRIDAY’, 0, 0, 24, 0);
campaign.addAdSchedule(‘SATURDAY’, 0, 0, 24, 0);
};

// Add a schedule for Sunday, 12PM to 12AM, no bid modifier
campaign.addAdSchedule(‘SUNDAY’, 12, 0, 24, 0);
}
}