Google Ads Script To Export All Disapproved Ads In A Google Sheet

Google Ads Script

This script checks all ads in your Google Ads account individually and finds the disapproved ads. Next, it exports them in your Google Sheet with Ad ID, Campaign Name, Ad Group Name, and Disapproval Reasons.

Here’s how it’s going to work.

Initialize Script Parameters:

  • SPREADSHEET_ID: Replace ‘YOUR_SPREADSHEET_ID’ with your actual Google Sheet ID.
  • SHEET_NAME: The name of the sheet within the spreadsheet where the data will be stored.

Open the Google Sheet:

The script opens the Google Sheet using the SpreadsheetApp.openById method.

Check and Create Sheet:

The script checks if the sheet with the specified name exists using spreadsheet.getSheetByName(SHEET_NAME).
If the sheet does not exist (!sheet), it creates a new sheet with spreadsheet.insertSheet(SHEET_NAME).

Clear Existing Content:

Clears any existing data in the sheet to ensure it’s up-to-date.

Set Up Headers:

Adds headers for the columns: Ad ID, Campaign Name, Ad Group Name, and Disapproval Reason.

Fetch All Ads:

Queries for all ads using AdsApp.ads().get().

Process Each Ad:

Iterates through each ad, checks for policy topics to identify disapproved ads, and fetches the campaign and ad group details.
Uses PolicyTopic.getId() to fetch the policy topic IDs (disapproval reasons) and appends this data to the Google Sheet.

function main() {
  // Replace with your Google Sheets ID
  var SPREADSHEET_ID = 'YOUR_SPREADSHEET_ID';
  var SHEET_NAME = 'Disapproved Ads';
  
  // Open the Google Sheet
  var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
  var sheet = spreadsheet.getSheetByName(SHEET_NAME);
  
  // Create the sheet if it doesn't exist
  if (!sheet) {
    sheet = spreadsheet.insertSheet(SHEET_NAME);
  }
  
  // Clear the existing content
  sheet.clear();
  
  // Set up headers
  sheet.appendRow(['Ad ID', 'Campaign Name', 'Ad Group Name', 'Disapproval Reason']);
  
  // Fetch all ads
  var adIterator = AdsApp.ads().get();
  
  while (adIterator.hasNext()) {
    var ad = adIterator.next();
    var policyTopics = ad.getPolicyTopics();
    
    if (policyTopics.length > 0) {
      var campaign = ad.getCampaign();
      var adGroup = ad.getAdGroup();
      var disapprovalReasons = policyTopics.map(function(policyTopic) {
        return policyTopic.getId();
      }).join(', ');

      // Append data to the sheet
      sheet.appendRow([
        ad.getId(),
        campaign.getName(),
        adGroup.getName(),
        disapprovalReasons
      ]);
    }
  }
}

Enjoy! Do let me know if it helped.

If you need any help with Google Ads, let’s connect.

Sharing is caring!

About the author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top