r/GoogleAppsScript • u/Old-Awareness-864 • Apr 13 '26
Guide I built a Facebook Ads Effective Status Detector in Google Apps Script — monitors DISAPPROVED/PENDING_REVIEW ads automatically and pings Google Chat + a random song from a playlist on YouTube
Hey everyone! I've been managing multiple Facebook Ads accounts and got tired of manually checking
for disapproved or stuck ads every morning. So I built a fully automated detector inside
Google Sheets using Apps Script. It runs 5 times a day and pings our team in Google Chat
when something breaks — plus recommends a random song from a YouTube playlist its called shark DJ
Sharing it here in case it helps someone else.
Apps Script tool that polls Facebook's Marketing API every few hours,
detects ads/ad sets with problematic effective_status, logs them to Google Sheets
with color-coded severity, and sends a formatted Google Chat notification automatically
🔍 What it Does
- Connects directly to the Facebook Marketing API v21.0 using a personal access token
- Scans all active campaigns → active ad sets → ads across multiple ad accounts
- Flags any object with these statuses:
- 🔴 CRITICAL: "DISAPPROVED", "PENDING_REVIEW"
- ⚠️ WARNING: "WITH_ISSUES", "IN_PROCESS", "PENDING_BILLING_INFO"
- Writes results to a formatted Google Sheet with color-coded rows
- Sends a structured Google Chat notification (splits into multiple messages if needed)
- Handles Facebook API rate limits automatically with exponential backoff
(up to 5 retries, 180s max wait)
- Includes Shark DJ 🦈🎵: picks a random song from your YouTube playlist and
appends it to every report
Before you begin, make sure you have:
- A Google Account with access to Google Sheets and Google Apps Script
- A Facebook Developer App with Marketing API access
- Create one at: https://developers.facebook.com/apps/ - A Facebook Access Token with "ads_read" permission
- Generate it at: https://developers.facebook.com/tools/explorer/
- ⚠️ Long-lived tokens expire after ~60 days — plan to refresh them - Your Ad Account IDs (format: `act_XXXXXXXXXXXXXXXXX`)
- Found in Facebook Business Manager under Account Settings - (Optional) A Google Chat Webhook URL for notifications
- In Google Chat: open a Space → Apps & integrations → Webhooks - (Optional) A YouTube Data API v3 key and a public playlist ID for Shark DJ
- Enable it at: https://console.cloud.google.com/
📦 Installation (Step by Step)
Step 1 — Create the Google Sheet
1. Go to https://sheets.google.com and create a new spreadsheet
2. Note the **Spreadsheet ID** from the URL:
`https://docs.google.com/spreadsheets/d/YOUR_ID_HERE/edit\`
Step 2 — Open Apps Script
1. In your Sheet, click **Extensions → Apps Script**
2. Delete all existing code in `Code.gs`
3. Paste the entire script from this post
Step 3 — Fill in CONFIG
At the top of the script, update the `CONFIG` object with your values:
```js
const CONFIG = {
FB_ACCESS_TOKEN: "your_facebook_access_token", // From Graph API Explorer
AD_ACCOUNT_IDS: [
{ id: "act_XXXXXXXXX", name: "Your Account Name" }
],
SPREADSHEET_ID: "your_spreadsheet_id",
SHEET_NAME: "Problem Detection",
TIMEZONE: "America/New_York", // Your timezone
WEBHOOK_URL: "your_google_chat_webhook", // Optional
SONG_OF_THE_DAY: {
youtube_api_key: "your_yt_api_key", // Optional
playlist_id: "PLxxxxxxxxxx", // Optional — must start with PL
enabled: true
}
};
```
Step 4 — Run it manually first
1. Save the script (Ctrl+S)
2. Reload your Google Sheet
3. A new menu "🔍 Problem Detector" will appear in the top menu bar
4. Click 🔍 Problem Detector → 🚀 Run Detector
5. On first run, Google will ask for permissions — review and accept them
6. The script will populate the "Problem Detection" sheet with results
When you click "⚙️ Enable Automation", the script creates 5 time-based triggers
that call `runDetectorAutomatically()` (which internally calls `detectProblems()`)
at these hours every day (configurable in CONFIG): 7:00 | 10:00 | 13:00 | 15:00 | 17:00
- Detects HTTP 429 and error codes 4, 17, 80004
https://docs.google.com/spreadsheets/d/1YQfu5D9dJygNLVjzXq4Q3k_9JNpXTbrUHafxvWiDzIo/edit?usp=sharing
You’re also welcome to ask me questions or suggest ways to improve this code. If you’d like me to share any other code I use in my daily work, or if you have a script you’d like to implement, feel free to leave me a comment. Thanks! :D
2
u/GrandAnimator8417 Apr 20 '26
“Google Apps” and “Effective Status Detector” sounds like you went full nerd mode. I’ve done a couple of these sheet/Apps Script automations before, and once you wire the status logic cleanly it makes chasing issues way less annoying. Google Ads can be solid, but those “14, 18…” style progress indicators usually need way more context than just a number to actually be useful.
2
u/[deleted] Apr 15 '26
[removed] — view removed comment