change tROAS in a specific campaign with a script

416 views
Skip to first unread message

Antoine P

unread,
Jun 27, 2023, 10:16:11 AM6/27/23
to Google Ads Scripts Forum
Hi there,

I would like to change the tROAS of a campaign on Friday to 2.6  and change it again on Monday.
While Google Ads tells me it ran successfully, I see the script made no change to the campaign specified.
Can you please help me?
Here is the script:

function main() {
  var campaignName = 'Campaign A - PMax';
  var campaignIterator = AdsApp.campaigns()
      .withCondition("Name = '" + campaignName + "'")
      .get();
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var biddingStrategy = campaign.bidding().getStrategy();
    if (biddingStrategy instanceof
        GoogleAdsApp.BiddingStrategies.TargetRoasBiddingStrategy) {
      var newTargetRoas = 2.6;
      biddingStrategy.setTargetRoas(newTargetRoas);
    }
  }
}


Thanks,

Sigurd Fabrin

unread,
Jun 28, 2023, 4:30:42 AM6/28/23
to Google Ads Scripts Forum
From your campaign name it appears to be a a pmax campaign. Those cannot be found using AdsApp.campaigns() - use AdsApp.​PerformanceMaxCampaign() instead


Sigurd

Antoine P

unread,
Jun 28, 2023, 9:15:04 AM6/28/23
to Google Ads Scripts Forum
Hi Sigurd,

I just tried this and I got this error (see attached).
Thanks,

function main() {
  var campaignName = 'Campaign A - Performance Max';
  var campaignIterator = AdsApp.PerformanceMaxCampaign()

      .withCondition("Name = '" + campaignName + "'")
      .get();
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var biddingStrategy = campaign.bidding().getStrategy();
    if (biddingStrategy instanceof
        GoogleAdsApp.BiddingStrategies.TargetRoasBiddingStrategy) {
      var newTargetRoas = 2.6;
      biddingStrategy.setTargetRoas(newTargetRoas);
    }
  }
}


Error:  TypeError: AdsApp.PerformanceMaxCampaign is not a function
at main (Code:3:33) at Object.<anonymous> (adsapp_compiled:20174:54)
Capture.PNG

Google Ads Scripts Forum Advisor

unread,
Jun 29, 2023, 3:32:53 AM6/29/23
to adwords...@googlegroups.com

Hi All,

 

Thank you for reaching out to the Google Ads Scripts Forum Channel.

 

@Sigurd - Thank you for providing your insights to this.

 

@Antoine - I believe Sigurd’s recommendation is correct. You would need to use specific selectors for the different types of campaigns Google Ads Scripts supports. You may find them in the documentation here: https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp.

 

Upon checking the error you encountered, I would recommend to follow the sample implementation found in the documentation here <https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_performancemaxcampaignselector>. The structure of the selector (or in your case, the iterator) should have a small `p` at the front of the word `performance`. Kindly refer to the snippet of code below:

var campaignIterator = AdsApp.performanceMaxCampaign()
   .withCondition("Name = '" + campaignName + "'")
   .get();

 

Let us know if you encounter any further issues or have any clarifications. If an error is encountered again, kindly provide your Google Ads account ID as well as the name of the script and a screenshot of the error so we’re able to further assist you. Kindly scrub any private data when posting information or images here as this forum is public.

 

This message is in relation to case "ref:_00D1U1174p._5004Q2mp8gv:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Google Ads Scripts Forum Advisor

unread,
Jun 29, 2023, 3:37:08 AM6/29/23
to adwords...@googlegroups.com

Hi Antoine,

 

Kindly disregard the snippet of code that was previously sent and please refer to the snippet of code below:

var campaignIterator = AdsApp.performanceMaxCampaigns()
   .withCondition("Name = '" + campaignName + "'")
   .get();

 

Again, let us know if you encounter any further issues or have any clarifications. If an error is encountered again, kindly provide your Google Ads account ID as well as the name of the script and a screenshot of the error so we’re able to further assist you. Kindly scrub any private data when posting information or images here as this forum is public.

Sigurd Fabrin

unread,
Jun 29, 2023, 4:26:52 AM6/29/23
to Google Ads Scripts Forum
You're missing an 's'

It's not clear from the documentation, that I linked to before, but if you use autocomplete in the IDE, it will suggest the correct spelling

Screenshot 2023-06-29 at 10.21.58.png

Sigurd

Paulet, Antoine

unread,
Jun 29, 2023, 7:59:10 AM6/29/23
to Google Ads Scripts Forum on behalf of adsscripts
Hi, 

I keep having the same issue.

Here are the info:
- Google Ads ID: 525-952-5808
- Script Name: Pmax TROAS 2.6
- Screenshot of the error
image.png

Thanks for the help,


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/mpG5naLkUsA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/CbHfA000000000000000000000000000000000000000000000RX07TJ00GX1ETyaFQqKRlsiItH3NuA%40sfdc.net.


--

Antoine Paulet | Labelium Senior Director Media

O: +1 438-387-7771

460, rue Saint Catherine O., Suite 510, Montréal, QC H3B 1A7

New York | Miami | Montréal | Toronto | Shanghai | Sydney | London | Frankfurt | Vienna | Paris | Lyon | Bordeaux | Milan | Madrid | Barcelona | Salamanca | Lisbon | Mexico City | Sao Paulo
-------------------------------------------
Please consider the environment before printing this email

Sigurd Fabrin

unread,
Jun 29, 2023, 8:38:39 AM6/29/23
to Google Ads Scripts Forum
This time you have a ReferenceError. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError

The error message tells you what is wrong - This time you are referencing something you call GoogleAdsApp?


Sigurd

Paulet, Antoine

unread,
Jun 29, 2023, 9:19:10 AM6/29/23
to Sigurd Fabrin via Google Ads Scripts Forum
Hi Sigurd,

I have little knowledge of scripts. 
Here is the script. I don't know what is wrong.

function main() {
  var campaignName = 'All Products - TRoAS - Performance Max - pmax';

  var campaignIterator = AdsApp.performanceMaxCampaigns()
    .withCondition("Name = '" + campaignName + "'")
    .get();
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var biddingStrategy = campaign.bidding().getStrategy();
    if (biddingStrategy instanceof
        GoogleAdsApp.BiddingStrategies.TargetRoasBiddingStrategy) {
      var newTargetRoas = 2.6;
      biddingStrategy.setTargetRoas(newTargetRoas);
    }
  }


Thanks,

Martijn Kraan

unread,
Jun 29, 2023, 10:24:31 AM6/29/23
to Google Ads Scripts Forum
Hello Antoine,

I'm not from the official Google Ads Scripts team. However, I may be able to help you out.

If I understood correctly you want to change the target ROAS of a single (pMax) campaign to 260%?
If that is correct, you could try this script:

function main() { var campaignName = 'All Products - TRoAS - Performance Max - pmax'; var campaignIterator = AdsApp.performanceMaxCampaigns() .withCondition("Name = '" + campaignName + "'") .get(); while (campaignIterator.hasNext()) { var campaign = campaignIterator.next(); var biddingStrategy = campaign.bidding().setTargetRoas(260) } }
I've tested this script in one of my accounts, and it seems to work.
However, I do advise you to preview the script first, then execute it.
And once successful, you can schedule to script to run on Friday's.

Good luck!

Gr, Martijn

Paulet, Antoine

unread,
Jun 29, 2023, 11:14:18 AM6/29/23
to Martijn Kraan via Google Ads Scripts Forum
Hi Martijn,

Excellent. It worked!
Thanks a lot for jumping into this.

Wishing you a good day,
Thank you,

Ha Hoang

unread,
Jun 29, 2023, 10:23:11 PM6/29/23
to Sigurd Fabrin via Google Ads Scripts Forum
ok ban

  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var biddingStrategy = campaign.bidding().getS
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/4bd87e90-7eec-48e8-8682-91417b53ca64n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages