How can is set Target CPA for adGroup via setCpa() of adgroup bidding?

118 views
Skip to first unread message

Khushal

unread,
Dec 2, 2022, 12:16:33 AM12/2/22
to Google Ads Scripts Forum
By default adGroup is showing Target CPA value $80 which is Target CPA of its respective campaign. Now I want to manually set Target CPA of specific adGroup having CPC greater than 0 via script. Below is my code.

var adGroupSelector = AdsApp
    .adGroups()
    .withCondition("ad_group.status = ENABLED")
    .forDateRange(date_range);

while (adGroupIterator.hasNext()) {

  var adGroup = adGroupIterator.next();
 
  var tcpa = adGroup.bidding().getCpa(); // getting $80 here

  var cost_value = adGroup.getStatsFor(date_range).getCost();
  var conversions_value = adGroup.getStatsFor(date_range).getConversions();
  var cpc_value = parseFloat(cost_value/conversions_value);
 

  if(Number.isFinite(cpc_value)){

    var new_target_cpa = Math.floor((cpc_value+tcpa)/2); //For example i get $126
   
    adGroup.bidding().setCpa(Math.floor((cpc_value+tcpa)/2)); // setting value $126 target CPA to this adgroup via setCpa() from adgroup bidding
   
    var get_target_cpa = adGroup.bidding().getCpa(); // again getting the target CPA with getCpa() to check whether it is set or not. Here i am getting value of get_target_cpa as $126 but it is not reflected in adGroup UI.

  }
}

Is my method to set Target CPA to adgroup is correct ? Why does the Target CPA set via setCpa() is not getting reflected in AdGroup UI ?

Google Ads Scripts Forum Advisor

unread,
Dec 4, 2022, 10:02:20 PM12/4/22
to adwords...@googlegroups.com

Hi Khushal,

 

Thank you for reaching out to us. This is Yasmin from the Google Ads scripts team.

 

We would appreciate it if you can provide the following information so that we may check this on our end and assist you with your concern:

  • Google Ads account ID or CID
  • Script name


Regards,

 

Google Logo
Yasmin Gabrielle
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2ghlyt:ref

Khushal

unread,
Dec 8, 2022, 12:31:25 AM12/8/22
to Google Ads Scripts Forum
Account ID - 796-630-1719
Script - abc.js

Google Ads Scripts Forum Advisor

unread,
Dec 9, 2022, 5:43:58 AM12/9/22
to adwords...@googlegroups.com

Hello,

I’m James, also a member of the Google Ads Script Team. Allow me to assist you further.

Based on my testing of the setCpa method with one of my scripts in my test account, I was able to execute it and the changes have reflected in the UI successfully. 

I can see that your script implementation is fine. However, can you please specify what approach you’re doing to execute your script? Please note that when scripts are executed in preview mode, they make no changes to the actual campaign data in the UI. Instead, script execution shows the changes that would have been made had the script been executing. Having said that, can you please run the script instead and let me know if it will make any changes in your Google Ads account?

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2ghlyt:ref

Khushal

unread,
Dec 10, 2022, 4:54:10 AM12/10/22
to Google Ads Scripts Forum
Thanks James. Its working now.

Google Ads Scripts Forum Advisor

unread,
Dec 11, 2022, 10:39:21 PM12/11/22
to adwords...@googlegroups.com

Hello,

Let us know if you have any further questions or concerns. We’re here to assist you.

Regards,

Reply all
Reply to author
Forward
0 new messages