Automated Structure Updates: Pausing Campaigns on a Schedule
Wed Feb 21 2024 17:48:33 GMT+0000 (Coordinated Universal Time)
Saved by
@tchives
#javascript
function main() {
// Define your schedule
var dayOfWeek = "MONDAY";
var startTime = "00:00"; // Midnight
var endTime = "06:00"; // 6 AM
// Campaign Selection
var campaignName = "Weekend Campaign";
// Get the current day of the week and time (adjust the timezone if needed)
var timeZone = "America/Los_Angeles";
var date = new Date();
var currentDayOfWeek = Utilities.formatDate(date, "EEEE", timeZone);
var currentTime = Utilities.formatDate(date, "HH:mm", timeZone);
// Pause or enable the campaign based on the schedule
var campaign = AdsApp.campaigns().withCondition("Name = '" + campaignName + "'").get().next();
if (currentDayOfWeek == dayOfWeek && currentTime >= startTime && currentTime <= endTime) {
campaign.pause();
} else {
campaign.enable();
}
}
content_copyCOPY
Comments