SHARE
TWEET

Untitled

a guest Jun 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function main() {
  2.     var ag_iter = AdsApp.adGroups()
  3.         .withCondition("Status = ENABLED")
  4.         .withCondition("CampaignName CONTAINS_IGNORE_CASE 'MyCampaignName'")
  5.         .withCondition("Impressions > 1000")
  6.         .forDateRange("LAST_30_DAYS")
  7.         .get();
  8.  
  9.     while (ag_iter.hasNext()) {
  10.         var ag = ag_iter.next();
  11.         Logger.log(ag.getName())
  12.  
  13.         var ad_iter = ag.ads()
  14.             .withCondition("Status = ENABLED")
  15.             .forDateRange("LAST_30_DAYS")
  16.             .orderBy("Ctr ASC")
  17.             .get();
  18.  
  19.  
  20.         var ad_array = new Array();
  21.         while (ad_iter.hasNext()) {
  22.             ad_array.push(ad_iter.next());
  23.  
  24.         }
  25.  
  26.         var ads_to_leave = 1;
  27.  
  28.         if (ad_array.length > ads_to_leave ) {
  29.             for (var i = 0; i < ad_array.length - (ads_to_leave + 1); i++) {
  30.                 ad_array[i].pause();
  31.             }
  32.         }
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top