Possible .withCondition Bug

20 views
Skip to first unread message

Josh Houghton

unread,
Feb 11, 2020, 7:00:41 AM2/11/20
to Google Ads Scripts Forum
Hi all,

I have the following script to bid adjust locations based on their CTR relative to the campaign CTR and in the initial stage I've tried to add a condition where only campaigns with conversions are selected but this condition doesn't seem to be picked up as in the bid adjust there are adjusts happening on locations in campaigns with conversions.

Not sure if this is a bug or I'm doing something wrong, script is below for reference:


function main() {
 
var enabledCampaigns = AdsApp.campaigns().withCondition("Status =  ENABLED").withCondition("Conversions < 1").forDateRange("LAST_30_DAYS").get();
 
var locations = AdsApp.targeting().targetedLocations(enabledCampaigns).withCondition("Impressions > 99").forDateRange("LAST_30_DAYS").orderBy("Ctr DESC").get();
   
 
while (locations.hasNext()){
   
var location = locations.next();
   
var locationCtr = location.getStatsFor("LAST_30_DAYS").getCtr();
   
Logger.log(locationCtr);


   
var campaign = location.getCampaign();
   
var campaignCtr = campaign.getStatsFor("LAST_30_DAYS").getCtr();
   
Logger.log(campaignCtr);
     
   
var stat = locationCtr / campaignCtr;
   
      location
.setBidModifier(stat);


 
}


}


Thanks,
Josh

Google Ads Scripts Forum Advisor

unread,
Feb 11, 2020, 2:58:22 PM2/11/20
to adwords-scripts+apn2wqfss8hd25-u...@googlegroups.com, adwords-scripts+apn2wqfss8hd25-u...@googlegroups.co, adwords...@googlegroups.com
Hi Josh,

If the desired condition is campaigns with at least 1 conversion, the inequality should be flipped and changed to:

  .withCondition("Conversions > 0")

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UV0SNx:ref

Josh Houghton

unread,
Feb 12, 2020, 3:09:24 AM2/12/20
to Google Ads Scripts Forum
Hi Matt,

Apologies I worded the initial request incorrectly I'm looking to select only campaigns without any conversions but the script I created above still seems to pick up (and then bid adjust) campaigns and locations in those campaigns.

Google Ads Scripts Forum Advisor

unread,
Feb 12, 2020, 4:23:33 AM2/12/20
to adwords...@googlegroups.com
Hi Josh,

Thanks for providing further details.

You may try previewing the updated script below. I modified the script so that the filters that have been applied to the campaign selector will carry over to the targeted locations.
function main() {
  var enabledCampaigns = AdsApp.campaigns()
    .withCondition("Status =  ENABLED")
    .withCondition("Conversions < 1")
    .forDateRange("LAST_30_DAYS").get()
    .next();
  
  var locations = enabledCampaigns.targeting()
    .targetedLocations()
    .withCondition("Impressions > 99")
    .forDateRange("LAST_30_DAYS")
    .orderBy("Ctr DESC")

    .get();
   
  while (locations.hasNext()){
    var location = locations.next();
    var locationCtr = location.getStatsFor("LAST_30_DAYS").getCtr();
    Logger.log(locationCtr);

    var campaign = location.getCampaign();
    var campaignCtr = campaign.getStatsFor("LAST_30_DAYS").getCtr();
    Logger.log(campaignCtr);
     
    var stat = locationCtr / campaignCtr;
    location.setBidModifier(stat);
  }
}


Let me know how it goes with the modified script.

Regards,
Ejay

Josh Houghton

unread,
Feb 12, 2020, 5:15:36 AM2/12/20
to Google Ads Scripts Forum
Worked a dream thanks Ejay!
Reply all
Reply to author
Forward
0 new messages