Ad scheduling script for Performance Max Campaigns

97 views
Skip to first unread message

h7

unread,
Jan 3, 2024, 8:51:49 AM1/3/24
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
  }
}

Google Ads Scripts Forum Advisor

unread,
Jan 3, 2024, 11:28:47 AM1/3/24
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts support team.

By reviewing your concern, I understand that your ad scheduled script is not working. I would recommend you refer to this help center article Scheduling a script to get more information on how to schedule a script.

Kindly provide us with the following details to further investigate your issue: 
  • Google Ads account ID / CID
  • Name of the script
  • Screenshot of the issue
You can send the details via Reply privately to the author option or a direct private reply to this email.

 This message is in relation to case "ref:!00D1U01174p.!5004Q02r53kT:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


h7

unread,
Jan 4, 2024, 2:41:43 AM1/4/24
to Google Ads Scripts Forum
Thank you!
It appears that I do not have the permissions to privately reply to author. What e-mail can I send to?

Nils Rooijmans

unread,
Jan 4, 2024, 3:42:04 AM1/4/24
to Google Ads Scripts Forum
here's the problem:
your script uses a campaign selector that only selects standard campaigns, not pmax campaigns ( var campaigns = AdsApp.campaigns().withCondition("Status = ENABLED").get();) , 
you would need to create a second function with a pmax campaign selector, ie:   var pmaxCampaigns = AdsApp.performanceMaxCampaigns().withCondition("Status = ENABLED").get(); 

BUT then you would also need to access the targeting() method, which isn't available for PMax campaigns (yet?) , see


Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Reply all
Reply to author
Forward
0 new messages