h7
unread,Jan 3, 2024, 8:51:49 AM1/3/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Ads Scripts Forum
Hi!
I have a script for ad scheduling that does not work for Performance Max Campaigns. I want to run all campaigns on the account only on Monday-Friday. Ideally I would want an account based rule for this as it applies to all ads, but it does not seem to work.
I would appreciate any help to make the necessary changes for it to work.
function main() {
updateAdSchedules();
}
function updateAdSchedules() {
var campaigns = AdsApp.campaigns().withCondition("Status = ENABLED").get();
while (campaigns.hasNext()) {
var campaign = campaigns.next();
var adSchedule = campaign.targeting().adSchedules().get();
// Remove existing ad schedules
while (adSchedule.hasNext()) {
var schedule = adSchedule.next();
schedule.remove();
}
// Set new ad schedules for Monday to Thursday (whole day)
var days = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY"];
for (var i = 0; i < days.length; i++) {
campaign.addAdSchedule({
dayOfWeek: days[i],
startHour: 0,
startMinute: 0,
endHour: 24,
endMinute: 0
});
}
// Set ad schedule for Friday (from midnight to 4:00 PM)
campaign.addAdSchedule({
dayOfWeek: "FRIDAY",
startHour: 0,
startMinute: 0,
endHour: 16,
endMinute: 0
});
// No ad schedules are set for Saturday and Sunday
}
}