How to remove specific ads in google ads script

90 views
Skip to first unread message

GoogleLoverse

unread,
May 23, 2023, 6:08:45 AM5/23/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 = 'https://docs.google.com/spreadsheets/d/〜〜〜〜/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 = accountIterator.next();
    AdsManagerApp.select(account);
    Logger.log('Now processing account: ' + account.getName());

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

    while (adIterator.hasNext()) {
      var ad = adIterator.next();
      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

unread,
Jun 2, 2023, 6:06:05 AM6/2/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/EByNRv_a2o8) from the forum as it wasn't routed to our support queue.

Regards,
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Jun 2, 2023, 6:42:46 AM6/2/23
to Google Ads Scripts Forum

Hi,


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 (googleadsscr...@google.com) instead.


Regards,
Google Ads Scripts Team

yuuutarou

unread,
Mar 21, 2024, 5:14:39 AMMar 21
to Google Ads Scripts Forum
This is exactly what I want to know.

I wanna know how dose this problme has solved.

Somebody tell me completed scirpt.

2023年6月2日金曜日 19:42:46 UTC+9 Google Ads Scripts Forum:
Reply all
Reply to author
Forward
0 new messages