How to remove specific ads in google ads script

Skip to first unread message


May 23, 2023, 6:08:45 AMMay 23
to Google Ads Scripts Forum
I am trying to remove a specific ad with the code below,
I am not getting any errors, but it is not complete after 50 minutes.

If I cut removeads(), it takes about 1 minute to complete.

Do you know the cause of this problem?
Thank you very much in advance for your help.

function main() {
  var SPREADSHEET_URL = '〜〜〜〜/edit#gid=〜〜〜';
  var SHEET_NAME = 'data';

  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = spreadsheet.getSheetByName(SHEET_NAME);
  var range = sheet.getRange('C:C');
  var values = range.getValues();

  var accountIterator = AdsManagerApp.accounts().get();
  Logger.log('アカウント件数 : ' + accountIterator.totalNumEntities());

  while (accountIterator.hasNext()) {
    var account =;;
    Logger.log('Now processing account: ' + account.getName());

    // Get all the video ads
    var adIterator = AdsApp.videoAds().get();

    while (adIterator.hasNext()) {
      var ad =;
      var adUrl = ad.urls().getFinalUrl();

      // Check if the ad's URL matches any URL from the spreadsheet
      for (var i = 0; i < values.length; i++) {
        var spreadsheetUrl = values[i][0];

        if (spreadsheetUrl !== "" && adUrl === spreadsheetUrl) {
          Logger.log('Account Name: ' + account.getName() + ', Ad ID: ' + ad.getId() + ', Final URL: ' + adUrl);
          ad.remove(); // Removing the ad

Google Ads Scripts Forum

Jun 2, 2023, 6:06:05 AMJun 2
to Google Ads Scripts Forum
Reposting the last inquiry ( from the forum as it wasn't routed to our support queue.

Google Ads Scripts Team

Google Ads Scripts Forum

Jun 2, 2023, 6:42:46 AMJun 2
to Google Ads Scripts Forum


I understand you’ve encountered an issue with your script. Kindly provide us with the following details below so that we can check first:

You may send it privately via the reply to author option. If this option is not available on your end, you may send it through our email ( instead.

Google Ads Scripts Team
Reply all
Reply to author
0 new messages