Whale Traffic

Tools03 Junk placements

See where your display budget actually went.

This script reads where your Display and Video ads ran, adds each website, app, and channel up across campaigns, and lists the ones that spent over your threshold with no conversions. It also compares share of spend with share of conversions for each placement type.

Get the script

Free Google Ads script · Reads only

What it reports

What you get back.

Best run · Weekly

  1. 01

    Every website, mobile app, and YouTube channel with spend and zero conversions.

  2. 02

    Cost, clicks, and impressions for each, ready to paste into an exclusion list.

  3. 03

    Share of spend beside share of conversions for websites, apps, and YouTube.

The script.

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

junk-placements.js · 141 lines

const CONFIG = {
  DAYS: 30,
  MIN_COST: 10,
  MAX_ROWS: 50000,
  SHEET_URL: "",
  EMAIL: "",
};

const TYPES = {
  WEBSITE: "Website",
  MOBILE_APPLICATION: "Mobile app",
  MOBILE_APP_CATEGORY: "App category",
  YOUTUBE_VIDEO: "YouTube video",
  YOUTUBE_CHANNEL: "YouTube channel",
  GOOGLE_PRODUCTS: "Google product",
};

function main() {
  const account = AdsApp.currentAccount();
  const currency = account.getCurrencyCode();
  const range = dateRange(CONFIG.DAYS, account.getTimeZone());
  const rows = AdsApp.search(
    "SELECT group_placement_view.placement, group_placement_view.display_name, group_placement_view.placement_type, " +
      "group_placement_view.target_url, metrics.cost_micros, metrics.clicks, metrics.impressions, metrics.conversions " +
      "FROM group_placement_view " +
      "WHERE segments.date BETWEEN '" + range.start + "' AND '" + range.end + "' AND metrics.cost_micros > 0 " +
      "ORDER BY metrics.cost_micros DESC LIMIT " + CONFIG.MAX_ROWS
  );

  const placements = new Map();
  const types = new Map();
  let read = 0;
  let totalCost = 0;
  let totalConversions = 0;
  while (rows.hasNext()) {
    const row = rows.next();
    const view = row.groupPlacementView;
    const type = TYPES[view.placementType] || view.placementType;
    const key = type + " " + view.placement;
    const cost = Number(row.metrics.costMicros) / 1e6;
    const conversions = Number(row.metrics.conversions);
    if (!placements.has(key)) {
      placements.set(key, {
        placement: view.placement,
        name: view.displayName || view.placement,
        type: type,
        url: view.targetUrl || "",
        cost: 0,
        clicks: 0,
        impressions: 0,
        conversions: 0,
      });
    }
    const placement = placements.get(key);
    placement.cost += cost;
    placement.clicks += Number(row.metrics.clicks);
    placement.impressions += Number(row.metrics.impressions);
    placement.conversions += conversions;
    if (!types.has(type)) types.set(type, { cost: 0, conversions: 0 });
    types.get(type).cost += cost;
    types.get(type).conversions += conversions;
    totalCost += cost;
    totalConversions += conversions;
    read++;
  }

  const junk = Array.from(placements.values())
    .filter((placement) => placement.conversions === 0 && placement.cost >= CONFIG.MIN_COST)
    .sort((a, b) => b.cost - a.cost);
  const junkCost = junk.reduce((sum, placement) => sum + placement.cost, 0);

  const summary = [
    account.getName() + ", " + range.start + " to " + range.end,
    junk.length + " placements spent " + money(junkCost, currency) + " with no conversions.",
    "That is " + percent(junkCost, totalCost) + " of the " + money(totalCost, currency) + " of placement spend read.",
    "",
    "Share of spend and share of conversions by type:",
  ];
  Array.from(types.entries())
    .sort((a, b) => b[1].cost - a[1].cost)
    .forEach((entry) => {
      summary.push(
        entry[0] + ": " + percent(entry[1].cost, totalCost) + " of spend, " + percent(entry[1].conversions, totalConversions) + " of conversions"
      );
    });
  if (read >= CONFIG.MAX_ROWS) {
    summary.push("Stopped at " + CONFIG.MAX_ROWS + " rows. Raise MAX_ROWS to read the rest.");
  }

  const table = [["Placement", "Name", "Type", "Cost", "Clicks", "Impressions", "URL"]].concat(
    junk.map((placement) => [
      placement.placement,
      placement.name,
      placement.type,
      round(placement.cost),
      placement.clicks,
      placement.impressions,
      placement.url,
    ])
  );
  const top = table.slice(1, 21).map((line) => money(line[3], currency) + "  " + line[2] + "  " + line[1]);

  summary.concat([""], top).forEach((line) => Logger.log(line));
  writeSheet(CONFIG.SHEET_URL, "Junk placements", table);
  sendMail(CONFIG.EMAIL, "Junk placements: " + account.getName(), summary.concat([""], top));
}

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 money(value, currency) {
  return currency + " " + round(value).toFixed(2);
}

function percent(part, whole) {
  return whole > 0 ? Math.round((part / whole) * 100) + "%" : "0%";
}

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 30
How many days to look back, ending yesterday.
MIN_COSTStarts at 10
The smallest spend, in your account currency, before a placement is listed.
MAX_ROWSStarts at 50000
The most report rows to read. 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

  • Read the type split before you block every app. In some accounts apps convert as well as websites do.
  • It reports and excludes nothing. You decide what to block.
  • Performance Max placements are left out, because Google reports impressions for them and not cost.

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