Google Ads Scripts with AI
Google Ads Scripts are short JavaScript programs that run inside a Google Ads account to read data, make changes and send alerts on a schedule. This tutorial writes, previews and schedules a simple script that flags campaigns spending money without any conversions, and shows how AI assistants help write scripts safely.
- Language: JavaScript, with Google's own objects such as AdsApp for the account.
- Queries: Data is read with Google Ads Query Language, which looks like SQL.
- Actions: Scripts can log, email, write to Google Sheets, or change bids and statuses.
- Scheduling: They can run hourly, daily, weekly or monthly without your computer.
- Assistance: Assistants can draft scripts from a plain description, but every line needs checking.
This tutorial follows one example: an online furniture store from Jodhpur that sells sheesham wood beds, dining sets and chairs across India. It runs about fifteen campaigns, and the owner wants a daily email whenever a campaign spends money but records no sales, before the waste adds up.
Prerequisites for Google Ads Scripts
- Access: Admin or standard access to the Google Ads account.
- Conversions: Working purchase tracking, set up in Google Ads conversion tracking. A script that counts conversions is useless if conversions are not recorded.
- Naming: Campaigns named by a pattern, as in Google Ads account structure, so script output is easy to read.
- JavaScript: Knowing what a variable, an if statement and a loop are is enough for this script.
- Inbox: A shared inbox that the marketing team reads daily.
Setup: Open the Scripts Page
- In Google Ads, open Tools, then Bulk actions, then Scripts.
- Select the plus button to create a new script and give it a name, such as "Daily: spend with no conversions".
- Delete the sample code in the editor so it is empty.
Scripts suit jobs that are repetitive, rule-based and easy to check. Here are common ideas, starting with the safest ones that only read data and report:
| Script idea | What it does | Risk level |
|---|---|---|
| Spend with no conversions | Emails campaigns that spent money without any sales | Low, read-only |
| Broken link checker | Visits each final URL and reports pages that return errors | Low, read-only |
| Budget pacing alert | Compares month-to-date spend with the monthly plan and warns early | Low, read-only |
| Search terms to Sheets | Copies search terms into a Google Sheet for weekly review | Low, read-only |
| Pause out-of-stock ads | Pauses ads for products the store marks as sold out | Medium, changes the account |
| Bid changes by rule | Raises or lowers bids when a condition is met | High, changes the account |
The furniture store starts with the first idea, because it only reads data and sends an email, so a mistake cannot damage any campaign. Scripts that change the account come later, once the team is confident reading and testing code.
Step-by-Step: Write and Run the Script
Step 1: Describe the Rule in Plain Words
Before writing any code, the owner writes down the exact rule in plain language: "Every morning, find enabled campaigns that spent at least Rs 1,000 in the last 7 days and have zero conversions. Email me the list." A clear rule makes the script, and any AI prompt, much easier to get right.
Step 2: Paste the Script
This script only reads data, writes a log and sends one email, so it cannot change any campaign, budget or bid in the account.
// Flags enabled campaigns that spent money in the last 7 days
// but recorded zero conversions. Read-only: it changes nothing.
var MIN_COST = 1000; // in account currency (INR here)
var EMAIL = "marketing@example.com"; // who gets the alert
function main() {
var query =
"SELECT campaign.name, metrics.cost_micros, metrics.clicks, metrics.conversions " +
"FROM campaign " +
"WHERE campaign.status = 'ENABLED' " +
"AND segments.date DURING LAST_7_DAYS";
var rows = AdsApp.search(query);
var flagged = [];
while (rows.hasNext()) {
var row = rows.next();
var cost = Number(row.metrics.costMicros) / 1000000;
var conversions = Number(row.metrics.conversions);
if (cost >= MIN_COST && conversions === 0) {
flagged.push(
row.campaign.name + ": Rs " + cost.toFixed(0) + " spent, " +
row.metrics.clicks + " clicks, 0 conversions"
);
}
}
if (flagged.length === 0) {
Logger.log("No campaigns with spend and zero conversions.");
return;
}
flagged.forEach(function (line) {
Logger.log(line);
});
MailApp.sendEmail(
EMAIL,
"Google Ads: campaigns with spend but no conversions (last 7 days)",
flagged.join("\n")
);
}Step 3: Understand Each Part
- Settings: MIN_COST ignores tiny spends, and EMAIL sets who receives the alert, so change both values to suit your own account before running anything.
- Query: The query asks for each enabled campaign's name, cost, clicks and conversions over the last 7 days. It works like the queries in SQL for marketers.
- Micros: Google Ads returns cost in micros, so dividing by 1,000,000 gives rupees.
- Rule: The if statement keeps only campaigns above the spend limit with zero conversions.
- Output: Logger.log writes to the run log, and MailApp sends one email with the whole list.
Step 4: Authorise
Select Authorise and approve the permissions with the same Google account. The script needs permission to read the account and send email.
Step 5: Preview
Select Preview. Preview runs the script without making changes and shows the logs. For this read-only script, check that the logged campaigns and rupee amounts match what the Campaigns page shows for the last 7 days.
Step 6: Schedule
Save the script, then set its frequency to Daily at a time before the team starts work, such as 7 am, remembering that scheduled scripts follow the account's own time zone rather than your computer's.
Step 7: Check the Run History
After the first scheduled run, open the script's run history and read the log. It shows whether the script finished, how long it took and any error messages, such as a field name that Google no longer supports. Checking this for the first few days catches problems before the team starts relying on the email.
Step 8: Act on the Email
When a campaign appears, the owner checks, in order: is tracking working, did a product go out of stock, is the landing page broken, and are the search terms relevant. The script finds the problem; a person decides the fix.
Common Mistakes
- Rushing: Running a changing script without preview can pause or edit the wrong things.
- Overtrust: Assistants sometimes invent functions or field names that do not exist in Google Ads Scripts.
- Units: Forgetting the micros conversion makes Rs 1,000 look like a billion.
- Tracking: If conversions stop recording, every campaign gets flagged, which is itself a useful alarm.
- Limits: Scripts that change bids should cap how many changes they make per run.
- Privacy: Never send customer names or phone numbers to email or Sheets from a script.
Next Steps
- Reports: Send results to a Google Sheet and build a dashboard, as in automate marketing reports with AI.
- Budgets: Add a second script that warns when a campaign spends faster than its monthly plan, useful alongside Smart Bidding.
- Coding: Use an AI coding assistant, covered in Claude Code for marketers, to extend scripts with tests and comments.
How AI Changes Google Ads Scripts
What AI Automates Now
AI assistants can turn a plain description into a working first draft of a script, explain unfamiliar code line by line, and suggest queries. This is a simple form of the tool calling idea: the AI writes code that then acts on a system.
What Still Needs a Human
A person must define the rule, check every field name against Google's documentation, run preview, and decide what to do with the results. The AI does not know that the store deliberately runs one awareness campaign with no conversion goal.
Risk to Watch
AI-written scripts can look correct and still contain an invented method or a wrong unit. A script that changes bids with such a bug can waste a month's budget overnight. Keep new scripts read-only until they are proven.
Do It with AI
Use this prompt to draft a new read-only script. It works in ChatGPT, Claude or Gemini.
You are a Google Ads Scripts developer. Rule I want: [describe in plain words, e.g. find ad groups with more than 50 clicks and no conversions in 14 days] Output: [log only, email to an address, or write to a Google Sheet URL] 1. Write a read-only Google Ads Script that uses AdsApp.search with a GAQL query. 2. Convert cost from micros to account currency. 3. Add a comment above each block explaining what it does in simple words. 4. List every Google Ads Scripts object and GAQL field you used, so I can check each one in the official documentation. Do not change bids, budgets or statuses. Do not use functions you are not sure exist.
- Write your rule in one or two plain sentences.
- Run the prompt and check each listed object and field in Google's documentation.
- Paste the script, authorise it and run preview.
- Compare the logs with the Google Ads interface before scheduling it.
Check Before You Use It
- Facts: Numbers in the logs must match the Google Ads interface for the same date range.
- Brand fit: Email subjects and messages should be clear enough for the whole team to act on.
- Compliance: Keep customer personal data out of scripts, and limit who can edit scripts in the account.
Quick Quiz
Pick an answer to check yourself. Nothing is saved.
Question 1 / 3
1. The furniture store's script should only report problems, not change anything. What makes it safe?
Frequently Asked Questions
What are Google Ads Scripts?
They are short JavaScript programs that run inside a Google Ads account. They can read reports, change bids or pause ads, and send emails or write to Google Sheets, on a schedule you choose, without any separate server.
Do I need to know programming to use Google Ads Scripts?
Basic JavaScript helps, but many useful scripts are short. AI assistants can draft a script from a plain description, and you can learn by reading each line. Always run a new script in preview first, which shows what it would do without changing anything.
Can a Google Ads Script break my account?
A script that changes bids, budgets or statuses can cause real damage if it has a mistake. Start with read-only scripts that only log or email, use preview mode, and add limits such as a maximum number of changes per run.
How often can a script run?
Scripts can be scheduled hourly, daily, weekly or monthly, and each run has a time limit. Check the current limits in the Google Ads Scripts documentation before building anything large.
What is the difference between Google Ads Scripts and the Google Ads API?
Scripts run inside Google Ads with no setup beyond pasting code, and suit single accounts or small agencies. The Google Ads API is for developers building software, needs a developer token and approval, and handles large-scale work.
Related Articles
- Google Ads Account StructureGoogle Ads account structure explained: account, campaigns, ad groups and ads, with a copyable template and a dental clinic example that keeps spend tidy.
- Smart Bidding (AI Bidding)Smart Bidding in Google Ads explained: target CPA, target ROAS, maximize conversions and value, and the learning period, with a Surat saree brand example.
- Automate Marketing Reports with AIAutomate marketing reports with AI: pull GA4, ads and Shopify data into one sheet each week and get a checked summary, shown for a Surat saree brand.
- Claude Code for MarketersClaude Code for marketers: clean ad exports, build a UTM builder page and analyse campaign data on your own computer, shown for an Indore home decor brand.
- Google Ads Conversion TrackingSet up Google Ads conversion tracking: the Google tag, purchase values in INR, GA4 imports and enhanced conversions, with a Coimbatore UPI store example.
- SQL for Marketers with AISQL for marketers: learn SELECT, WHERE, GROUP BY, CASE and JOIN on sample lead data and use AI to draft queries safely, with a Bengaluru SaaS example.