Good morning,
I am trying to run the following script on an MCC account to set the target ROAS to 100 in all campaigns of all managed accounts:
function main() {
var accountIterator = MccApp.accounts().get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
MccApp.select(account);
setTargetRoas();
}
Logger.log("Target ROAS has been updated for all managed accounts.");
}
function setTargetRoas() {
var TARGET_ROAS = 100; // 100% ROAS
// Get all standard campaigns
var campaignIterator = AdsApp.campaigns().get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var campaignName = campaign.getName();
var biddingStrategy = campaign.bidding().getStrategyType();
// Debug to check the bidding strategy
Logger.log("Campaign: " + campaignName + ", Bidding Strategy: " + biddingStrategy);
if (biddingStrategy == "MAXIMIZE_CONVERSION_VALUE") {
// Set the target ROAS
campaign.bidding().setTargetRoas(TARGET_ROAS);
Logger.log("Target ROAS set to " + TARGET_ROAS + " for campaign: " + campaignName);
}
}
// Get all Performance Max campaigns
var pMaxCampaignIterator = AdsApp.performanceMaxCampaigns().get();
while (pMaxCampaignIterator.hasNext()) {
var pMaxCampaign = pMaxCampaignIterator.next();
var pMaxCampaignName = pMaxCampaign.getName();
var pMaxBiddingStrategy = pMaxCampaign.bidding().getStrategyType();
// Debug to check the bidding strategy
Logger.log("Performance Max Campaign: " + pMaxCampaignName + ", Bidding Strategy: " + pMaxBiddingStrategy);
if (pMaxBiddingStrategy == "MAXIMIZE_CONVERSION_VALUE") {
// Set the target ROAS
pMaxCampaign.bidding().setTargetRoas(TARGET_ROAS);
Logger.log("Target ROAS set to " + TARGET_ROAS + " for Performance Max campaign: " + pMaxCampaignName);
}
}
}
When I click on Preview to see what the script does, it ends up in an infinite loop. In the logs, I see that the target ROAS was changed in 3 campaigns:
28/07/2024 16:26:00 Campaign: XXXXXXX - dsa, Bidding Strategy: MAXIMIZE_CONVERSION_VALUE 28/07/2024 16:26:00 Target ROAS set to 1 for campaign: XXXXXX - dsa 28/07/2024 16:26:01 Performance Max Campaign: XXXXXXX - pmax, Bidding Strategy: MAXIMIZE_CONVERSION_VALUE 28/07/2024 16:26:01 Target ROAS set to 1 for Performance Max campaign: XXXXX - pmax 28/07/2024 16:26:02 Performance Max Campaign: XXXXXXX - pmax, Bidding Strategy: MAXIMIZE_CONVERSION_VALUE
Actually, in the section with the changes made, I see that the changes have been correctly applied to all campaigns.
However, the script keeps running infinitely and logs show only 3 campaigns edit.
Is there a bug?
Thank you,
Salvatore
Hi,
Thank you for reaching out to the Google Ads Scripts support team.
We have tested the below code from our end, and the script is not running an infinite loop. In order to replicate your script from our end, share with us the following details:
![]() |
Google Ads Scripts Team |
Good morning,
Could you please test the script on my account 216-776-7109? The script is called "bug-infinite-loop". If you try to click the "Preview" button, you will see the following:
I am also attaching a video below:
https://drive.google.com/file/d/1DUMIB7NG3btRZr8S4DJktcHBPCPVA92l/view?usp=sharing
Thank you,
Salvatore
Thank you so much for the suggestion. I have modified:
What I see on the last log is:
Does this mean that the Google Ads Script bug might be in pMaxCampaignIterator.hasNext() which selects a campaign?
The strange thing is that if I open the Changes tab, I see all the campaigns correctly modified as ROAS, while the script runs indefinitely.
Do you have any suggestions?
Thank you, Salvatore
Thank you so much for the suggestion. I have modified:
Does this mean that the Google Ads Script bug might be in pMaxCampaignIterator.hasNext() which selects a campaign?
The strange thing is that if I open the Changes tab, I see all the campaigns correctly modified as ROAS, while the script runs indefinitely:
https://drive.google.com/file/d/1DUMIB7NG3btRZr8S4DJktcHBPCPVA92l/view?usp=sharing
Do you have any suggestions?
Thank you,
Salvatore
Hi, I am experiencing the same issue.
The preview keeps loading indefinitely and never completes (mm:ss ...showing the elapsed time).
Has this issue been resolved?
Hi,
Thank you for reaching out to the Google Ads Scripts support team.
You can share the requested details via Reply privately to the author option or a direct private reply to this email.
Thanks,