How to fix a Google Ads script that times out
Why scripts hit the 30-minute execution limit and the changes that bring run time back down.
Google Ads stops a script after 30 minutes. The run ends with a message that it exceeded the maximum execution time, and whatever it had not reached is skipped — usually the same campaigns or accounts every time, because scripts tend to work in the same order.
Find what is slow
Add timestamps to the log around the main steps:
var start = new Date();
// ... a step ...
Logger.log("Step took " + (new Date() - start) / 1000 + "s");Typically one step accounts for nearly all of the time.
The usual causes and fixes
- Fetching statistics entity by entity. Looping through keywords and calling for each one's stats is slow. Replace the loop with one
AdsApp.search()query that returns the metrics for all rows. - Processing everything. Add conditions to the query: enabled entities only, with impressions in the period, above a minimum cost.
- Writing to a spreadsheet row by row. Collect rows in an array and write them once with
setValues. - Changing entities one at a time. Use bulk operations where they exist.
- Calling external URLs in sequence. Fetch in batches with
UrlFetchApp.fetchAll. - Too many accounts in sequence. At manager level, process accounts in parallel instead of one after another.
When the work is simply too big
Split it across runs. Process a slice per run — a set of campaigns, or accounts not yet labelled as done — and continue on the next run. An hourly schedule then works through the whole set over a day.
Catching it early
Run time usually creeps up as an account grows. chiliad shows the average and maximum duration of a script's runs on its History tab and warns when they approach the limit, so you can fix the slow step before runs start being cut off.