exclude an ad group

83 views
Skip to first unread message

DIMITRI

unread,
Feb 27, 2020, 7:34:28 AM2/27/20
to Google Ads Scripts Forum
hi, i'm tryng to filter the placement (like with cost > 50) and if it fulfills these conditions i want to '' exclude from ad group''.
Do you know how i can do this?

Cami

unread,
Feb 27, 2020, 11:20:47 AM2/27/20
to Google Ads Scripts Forum
i found this code but i don't know if is right ....


function main() {
  var adSelector = AdsApp
     .ads()
     .withCondition("Cost < 4")
     .forDateRange("ALL_TIME")
     .orderBy("Cost DESC");

 var adIterator = adSelector.get();
 while (adIterator.hasNext()) {
   var ad = adIterator.next();

Google Ads Scripts Forum Advisor

unread,
Feb 27, 2020, 3:22:51 PM2/27/20
to adwords-scripts+apn2wqcyxapjes0o...@googlegroups.com, adwords...@googlegroups.com
Hi Dimitri,

You'll want to use something similar to the automatic placement report solution. 

Basically, you can use the URL performance report to pull ad group ID and the URL of the placement that meets your metrics requirement (e.g. cost > X), and then use the placement builder for each ad group. Please note that the placement builder can also build exclusions. Your builder may look like (see comments):

   var placementBuilder = adGroup.display().newPlacementBuilder()   //adGroup should be defined above, and retrieved from the URL performance report
     .withUrl(your_url)              //URL retrieved from URL performance report
     .withCpc(some_cpc)          // optional
     .exclude()                           // exclude the placement

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UXTQ3v:ref

cassandra

unread,
Feb 28, 2020, 3:26:31 AM2/28/20
to Google Ads Scripts Forum

i like this code but google a say : 

ReferenceError: "getReportResults" is not defined.
 How can i change this code?? 

function main() {
  var VIEW_RATE_THRESHOLD = '10.00%';
  VIEW_RATE_THRESHOLD = parseFloat(VIEW_RATE_THRESHOLD);
  //The view rate under which placements will be automatically excluded.
  var results = getReportResults(); 
  var ids = [];
  for (var id in results) {
    ids.push(id);
  }
  var videoCampaignIterator = AdsApp.videoCampaigns()
      .withIds(ids)
      .get();
  while (videoCampaignIterator.hasNext()) {
    var videoCampaign = videoCampaignIterator.next();
    var id = videoCampaign.getId();
    if (results.hasOwnProperty(id)) {
      var urls = results[id];
      for (var i = 0; i < urls.length; i++) {
        videoCampaign.videoTargeting().newPlacementBuilder()
            .withUrl(urls[i])
            .exclude();
      }
    }
  }
}

Google Ads Scripts Forum Advisor

unread,
Feb 28, 2020, 6:13:39 AM2/28/20
to adwords...@googlegroups.com
Hi Cassandra,

I am a colleague of Matt and let me provide further support to your concern.

It appears that you were not able to copy the whole code of the Automatic Placement Exclusion solution script. I would recommend that you copy the source code of the said solution script again, and try to re-execute it.

Let me know how it goes after.

Regards,
Ejay
Google Ad Scripts Team

ref:_00D1U1174p._5001UXTQ3v:ref

Cami

unread,
Mar 25, 2020, 8:38:34 AM3/25/20
to Google Ads Scripts Forum
I don't understand how can i ''exclude from ad group'' 
hi, i'm tryng to filter the placement  (where ads show)(like with cost > 50) and if it fulfills these conditions i want to '' exclude from ad group''.
Do you know how i can do this? Can you write for me a code ? Thanks in advance. I'im trying to do this since 1 week but i don't know how to do this.
how, 

Google Ads Scripts Forum Advisor

unread,
Mar 25, 2020, 9:47:17 AM3/25/20
to adwords-scripts+apn2wqcyxapjes0o...@googlegroups.com, adwords-scripts+apn2wqcyxapjes0o...@googlegroups.co, adwords...@googlegroups.com
Hi Cami,

At the moment, scripts does not support the "Where your ads showed" part of the UI. However, the code below could be helpful. I've left comments explaining certain lines of code. I recommend running code in preview mode first to see if the changes make sense.
  var urls = []; //URL of placements array
  var adgroupSelector = AdsApp.adGroups().withCondition("YOUR_CONDITION").get(); //Specify your ad group selection 
  
  if(adgroupSelector.hasNext()) {    
    var adgroup = adgroupSelector.next().display(); //Get that display ad group
    var placementSelector = adgroup.placements().withCondition("Cost > 50").forDateRange("LAST_30_DAYS").get(); //Arbitrary date range
   
    //Get all relevant URLs from filtered placements
    while(placementSelector.hasNext()) {
      var placement = placementSelector.next();
      urls.push(placement.getUrl());
    }

    //Loop through all filtered placement URLS and exclude them from this ad group 
    for(var i = 0; i < urls.length; i++) {
      adgroup.newPlacementBuilder().withUrl(url[i]).exclude();
    }      
  }

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UXWbwX:ref

Cami

unread,
Mar 30, 2020, 5:40:24 AM3/30/20
to Google Ads Scripts Forum
The URL start with http:// and // for the script is like i want to add a comment. How can i change the URl ? can i put http: URL and cut //?

 var adgroupSelector = AdsApp.adGroups().withCondition("YOUR_CONDITION").get(); //Specify your ad group selection 
Give me one exemple of YOUR_CONDITION because i doesn't understand.... is sometinhing about youtube abd display o different'?
Thanks in advance


El jueves, 27 de febrero de 2020, 13:34:28 (UTC+1), Simona escribió:

Google Ads Scripts Forum Advisor

unread,
Mar 30, 2020, 7:04:23 AM3/30/20
to adwords...@googlegroups.com
HI Cami,


I am a colleague of Matt and let me provide further support to your concern.

"The URL start with http:// and // for the script is like i want to add a comment. How can i change the URl ? can i put http: URL and cut //?"
-For the above question, could you provide more details on what you want to achieve?

As for the sample conditions for withCondition() method of the ad group selector, you may refer to this document to see sample filters that you can use for your script.

Regards,
Ejay
Reply all
Reply to author
Forward
0 new messages