Tools04 Budget or rank
Before you raise a budget, check what is holding it back.
A Search campaign misses impressions for one of three reasons. The budget ran out, the ad rank was too low, or there was no more demand to capture. Each one needs a different fix. This script reads impression share for every enabled Search campaign and names the cause.
Free Google Ads script · Reads only
What it reports
What you get back.
Best run · Weekly
- 01
Impression share, share lost to budget, and share lost to ad rank for each campaign.
- 02
A plain verdict for each one: Budget, Ad rank, Budget and ad rank, or Search demand.
- 03
Cost and conversions beside it, so you start with the campaigns that matter.
The script.
Copy all of it into a new script in Google Ads. The settings sit in the first few lines.
budget-or-rank.js · 94 lines
const CONFIG = {
DAYS: 7,
LOST_SHARE: 0.1,
SHEET_URL: "",
EMAIL: "",
};
function main() {
const account = AdsApp.currentAccount();
const currency = account.getCurrencyCode();
const range = dateRange(CONFIG.DAYS, account.getTimeZone());
const rows = AdsApp.search(
"SELECT campaign.name, metrics.search_impression_share, metrics.search_budget_lost_impression_share, " +
"metrics.search_rank_lost_impression_share, metrics.cost_micros, metrics.conversions " +
"FROM campaign " +
"WHERE segments.date BETWEEN '" + range.start + "' AND '" + range.end + "' " +
"AND campaign.advertising_channel_type = 'SEARCH' AND campaign.status = 'ENABLED' AND metrics.impressions > 0 " +
"ORDER BY metrics.cost_micros DESC"
);
const table = [["Campaign", "Cost", "Conversions", "Impression share", "Lost to budget", "Lost to ad rank", "What is holding it back"]];
const counts = {};
while (rows.hasNext()) {
const row = rows.next();
const metrics = row.metrics;
const verdict = holdingBack(metrics.searchBudgetLostImpressionShare, metrics.searchRankLostImpressionShare);
counts[verdict] = (counts[verdict] || 0) + 1;
table.push([
row.campaign.name,
round(Number(metrics.costMicros) / 1e6),
round(Number(metrics.conversions)),
share(metrics.searchImpressionShare),
share(metrics.searchBudgetLostImpressionShare),
share(metrics.searchRankLostImpressionShare),
verdict,
]);
}
const summary = [
account.getName() + ", " + range.start + " to " + range.end + ", " + (table.length - 1) + " Search campaigns",
].concat(Object.keys(counts).map((verdict) => verdict + ": " + counts[verdict]));
const lines = table
.slice(1)
.map((line) => line[0] + ": " + line[6] + " (share " + line[3] + ", budget " + line[4] + ", rank " + line[5] + ", " + currency + " " + line[1].toFixed(2) + ")");
summary.concat([""], lines).forEach((line) => Logger.log(line));
writeSheet(CONFIG.SHEET_URL, "Budget or rank", table);
sendMail(CONFIG.EMAIL, "Budget or rank: " + account.getName(), summary.concat([""], lines));
}
function holdingBack(budgetLost, rankLost) {
if (budgetLost === undefined || rankLost === undefined) return "Not enough data";
const budget = Number(budgetLost);
const rank = Number(rankLost);
if (budget >= CONFIG.LOST_SHARE && rank >= CONFIG.LOST_SHARE) return "Budget and ad rank";
if (budget >= CONFIG.LOST_SHARE) return "Budget";
if (rank >= CONFIG.LOST_SHARE) return "Ad rank";
return "Search demand";
}
function share(value) {
if (value === undefined) return "n/a";
const number = Number(value);
if (number < 0.1) return "under 10%";
if (number > 0.9) return "over 90%";
return Math.round(number * 100) + "%";
}
function dateRange(days, timeZone) {
const day = 24 * 60 * 60 * 1000;
const end = new Date(Date.now() - day);
const start = new Date(end.getTime() - (days - 1) * day);
return {
start: Utilities.formatDate(start, timeZone, "yyyy-MM-dd"),
end: Utilities.formatDate(end, timeZone, "yyyy-MM-dd"),
};
}
function round(value) {
return Math.round(value * 100) / 100;
}
function writeSheet(url, tabName, table) {
if (!url) return;
const book = SpreadsheetApp.openByUrl(url);
const sheet = book.getSheetByName(tabName) || book.insertSheet(tabName);
sheet.clearContents();
sheet.getRange(1, 1, table.length, table[0].length).setValues(table);
}
function sendMail(to, subject, lines) {
if (!to) return;
MailApp.sendEmail(to, subject, lines.join("\n"));
}
Settings
- DAYSStarts at 7
- How many days to look back, ending yesterday.
- LOST_SHAREStarts at 0.1
- How much lost impression share counts as a cap. 0.1 means 10%.
- SHEET_URLStarts empty
- A Google Sheet link to write the full list to. Leave it empty to skip.
- EMAILStarts empty
- Where to send the summary. Leave it empty to skip.
How to install
- 01
Open Scripts
In Google Ads, open Tools, then Bulk actions, then Scripts.
- 02
Paste it in
Press the plus button, choose New script, and paste the script over the sample code.
- 03
Set the values
Edit the settings at the top. Add a Google Sheet link or an email address if you want the report sent somewhere.
- 04
Preview, then schedule
Authorize the script, press Preview to read the report in the log, then save it and choose how often it runs.
Good to know
- More budget only helps a campaign capped by budget. For ad rank, work on bids, ad relevance, and the landing page.
- Google reports shares under 10% and over 90% as ranges, so the script does too.
- Campaigns with too little traffic show as Not enough data.
Free to use and to change. The script only reads your account. It is provided as it is, with no warranty, so run Preview before you schedule it.
Work with us
Tell us what you’re trying to grow.
Start with a quick conversation about your goals and current spend. We’ll come back with a plan and a straight answer on whether we’re the right fit.