We have a script built to pause all campaigns in an account after the monthly spend reaches a certain threshold. It was tested and worked for a while, but mysteriously, last month, the scripts failed to pause our search campaigns and only paused Pmax campaigns.
Weirdly enough, we recently rewrote this script to make sure pmax got paused, but it randomly stopped pausing the search campaigns this time around.
This is the script:
var monthly_budget =XXXX;
function main() {
var spend=AdsApp.currentAccount().getStatsFor("THIS_MONTH").getCost();
if(spend>monthly_budget){
pauseAllCampaigns()
}
}
function pauseAllCampaigns() {
Logger.log('Monthly budget has been exceeded…pausing')
var campaignIterator = AdsApp.campaigns().get();
var campaignIterator = AdsApp.performanceMaxCampaigns().get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
campaign.pause()
}
}
Any idea what happened and how to fix it?