Whale Traffic

Tools06 Broken landing pages

Stop paying for clicks to pages that don’t load.

This script collects the landing pages behind every enabled ad and Performance Max asset group, requests each one, and lists the pages that fail to load along with the campaigns that send traffic to them.

Get the script

Free Google Ads script · Reads only

What it reports

What you get back.

Best run · Daily

  1. 01

    Every landing page that returns an error or no response at all.

  2. 02

    The response code and the campaigns that use the page.

  3. 03

    How many pages were checked, and whether the script stopped at its limit.

The script.

Copy all of it into a new script in Google Ads. The settings sit in the first few lines.

broken-landing-pages.js · 79 lines

const CONFIG = {
  MAX_URLS: 300,
  SHEET_URL: "",
  EMAIL: "",
};

function main() {
  const account = AdsApp.currentAccount();
  const pages = new Map();
  collect(
    pages,
    "SELECT ad_group_ad.ad.final_urls, campaign.name FROM ad_group_ad " +
      "WHERE ad_group_ad.status = 'ENABLED' AND ad_group.status = 'ENABLED' AND campaign.status = 'ENABLED'",
    (row) => row.adGroupAd.ad.finalUrls
  );
  collect(
    pages,
    "SELECT asset_group.final_urls, campaign.name FROM asset_group " +
      "WHERE asset_group.status = 'ENABLED' AND campaign.status = 'ENABLED'",
    (row) => row.assetGroup.finalUrls
  );

  const urls = Array.from(pages.keys());
  const checked = urls.slice(0, CONFIG.MAX_URLS);
  const broken = [];
  checked.forEach((url) => {
    let code = 0;
    let note = "";
    try {
      code = UrlFetchApp.fetch(url, { muteHttpExceptions: true, followRedirects: true }).getResponseCode();
    } catch (error) {
      note = String(error.message || error).slice(0, 120);
    }
    if (code === 0 || code >= 400) {
      broken.push([url, code === 0 ? "No response" : code, note, Array.from(pages.get(url)).join(", ")]);
    }
  });

  const summary = [
    account.getName() + ": checked " + checked.length + " of " + urls.length + " landing pages in enabled ads.",
    broken.length + " did not load.",
  ];
  if (urls.length > checked.length) {
    summary.push("Stopped at " + CONFIG.MAX_URLS + " pages. Raise MAX_URLS to check the rest.");
  }

  const table = [["Landing page", "Response", "Note", "Campaigns"]].concat(broken);
  const lines = broken.map((line) => line[1] + "  " + line[0] + "  (" + line[3] + ")");

  summary.concat([""], lines).forEach((line) => Logger.log(line));
  writeSheet(CONFIG.SHEET_URL, "Broken landing pages", table);
  if (broken.length) {
    sendMail(CONFIG.EMAIL, "Broken landing pages: " + account.getName(), summary.concat([""], lines));
  }
}

function collect(pages, query, finalUrls) {
  const rows = AdsApp.search(query);
  while (rows.hasNext()) {
    const row = rows.next();
    (finalUrls(row) || []).forEach((url) => {
      if (!pages.has(url)) pages.set(url, new Set());
      pages.get(url).add(row.campaign.name);
    });
  }
}

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

MAX_URLSStarts at 300
The most pages to check in one run. The script tells you if it stops here.
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

  1. 01

    Open Scripts

    In Google Ads, open Tools, then Bulk actions, then Scripts.

  2. 02

    Paste it in

    Press the plus button, choose New script, and paste the script over the sample code.

  3. 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.

  4. 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

  • Some sites refuse automated requests and answer 403 to the script while loading normally for people. Open the page yourself before you pause anything.
  • It requests each page once per run, without the parameters your tracking template adds.
  • It emails only when a page fails.

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.

Request a proposal