Filter Ended Campaigns

184 views
Skip to first unread message

Vlad Popovici

unread,
Aug 30, 2022, 6:48:00 AM8/30/22
to Google Ads Scripts Forum
Hello, my name is Vlad and I would like to know if there is any way for me to select only the campaigns that have the "Ended" status. I have tried "..withCondition("campaign.status = ENDED")" and it didn't work, after some research I have found out that the Status enum only has following items: "Enabled", "Paused", "Removed".
Is there any way for me to filter only the ended campaigns?
If you are wondering what I would like to do with those, I would like to pause any ads that are enabled in ended campaigns (it interferes with another script of mine).

Thank you and looking forward for your solutions :)
Message has been deleted
Message has been deleted

Sigurd Fabrin

unread,
Aug 30, 2022, 8:18:11 AM8/30/22
to Google Ads Scripts Forum
Hi Vlad,

Look for ServingStatus

Btw: it would probably be better to fix your other script so it doesn't look in ended campaigns..

It used to be possible from AdsApp.campaign() - however, now I can only find it in reports. Perhaps I haven't searched thorough enough

Anyway, smth like this will work:
function main() {
   let query =
       'SELECT '+
       'campaign.id '+
       'FROM campaign '+
       'WHERE '+
       'campaign.serving_status IN ("ENDED")';
   let response = AdsApp.search(query)
   let ids = [];
   while (response.hasNext()) {
     let row = response.next();
     ids.push(row.campaign.id);
   }  
   let campIter = AdsApp.campaigns()
    .withIds(ids)
    .get();
   while (campIter.hasNext()) {
   console.log(campIter.next().getName())
   }
}


Cheers
Sigurd

Vlad Popovici

unread,
Aug 30, 2022, 10:05:17 AM8/30/22
to Google Ads Scripts Forum
Hello Sigurd,

Thank you for your response, I have tried the solution that you have given me, the script doesn't appear to crash (so it recognizes the condition) but it does not filter the campaigns the way I want it to, it also adds the paused campaigns. I'll keep searching and return with a solution if I find any.

Regards,
Vlad

Vlad Popovici

unread,
Aug 30, 2022, 10:11:34 AM8/30/22
to Google Ads Scripts Forum
And to clarify the problem that I have with my other script:
My other script is a script that checks each ad for broken URLs and I have conditions for the campaign, adgroup and ad to be enabled, but from what I have seen, Google Ads considers Ended campaigns as Enabled, so I do not think there is any way for me to resolve the issue with the other script. If you have any more ideas Sigurd feel free to respond to this thread.

Thank you,
Vlad

Sigurd Fabrin

unread,
Aug 30, 2022, 10:38:14 AM8/30/22
to Google Ads Scripts Forum
"[...] it also adds the paused campaigns"

Yes, it only filters on ended campaigns ie campaigns that have an end date in the past. These campaigns can be enables, paused or removed.
Just add campaign status to the filter

function main() {
   let query =
       'SELECT '+
       'campaign.id '+
       'FROM campaign '+
       'WHERE '+
       'campaign.serving_status IN ("ENDED") '+
      'AND campaign.status = "ENABLED"';

   let response = AdsApp.search(query)
   let ids = [];
   while (response.hasNext()) {
     let row = response.next();
     ids.push(row.campaign.id);
   }  
   let campIter = AdsApp.campaigns()
    .withIds(ids)
    .get();
   while (campIter.hasNext()) {
   console.log(campIter.next().getName())
   }
}



Cheers
Sigurd

Vlad Popovici

unread,
Aug 30, 2022, 10:42:32 AM8/30/22
to Google Ads Scripts Forum
That fixed my issue, thank you very much for your support Sigurd :).

Regards,
Vlad

Sigurd Fabrin

unread,
Aug 30, 2022, 10:45:20 AM8/30/22
to Google Ads Scripts Forum
"My other script is a script that checks each ad for broken URLs and I have conditions for the campaign, adgroup and ad to be enabled, but from what I have seen, Google Ads considers Ended campaigns as Enabled, so I do not think there is any way for me to resolve the issue with the other script."

Sure, just reverse the logic ie 

let query =
       'SELECT '+
       'campaign.id '+
       'FROM campaign '+
       'WHERE '+
       'campaign.serving_status IN ("PENDING","SERVING")';
   let response = AdsApp.search(query)
   let ids = [];
   while (response.hasNext()) {
     let row = response.next();
     ids.push(row.campaign.id);
   }  
   let campIter = AdsApp.campaigns()
    .withIds(ids)
    .get(); // now you only get active or soon to be active campaigns


Cheers
Sigurd

Google Ads Scripts Forum Advisor

unread,
Aug 31, 2022, 5:46:25 AM8/31/22
to adwords...@googlegroups.com

Hello Vlad,

James here, from the Google Ads scripts support team. Thank you for raising your concern to our forum channel.

I believe that the solutions provided by Sigurd are correct and satisfy the needs of your use-case. However, if you have any further questions or concerns, please let us know. We’re here to assist you.

@Sigurd - Thank you for sharing your insights here. We greatly appreciate your continued support to our users here in our forum channel.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2dtHYd:ref

Vlad Popovici

unread,
Aug 31, 2022, 8:21:01 AM8/31/22
to Google Ads Scripts Forum
Hello James,
Hello Sigurd,

Thank you both for the responses, you have helped me a lot :).
Reply all
Reply to author
Forward
0 new messages