Automatic Placement Exclusion

Tools icon

Sometimes there are videos which have a different target audience than your ads, but you might not know that until you start accruing stats. Once you see that a specific placement just isn't performing the way you want, you can eliminate it from your targeting.

This script automatically identifies and excludes placements (not YouTube URLs) that aren't meeting the view threshold you've set for your video ads.


The script considers the last 7 days of statistics. Schedule it to run Weekly.

How it works

For each campaign in your account, the script runs through the same process:

  • Find statistics on video performance, specifically view rate, for the given campaign over the past week.
  • For each URL under a specific threshold of view rate (configurable), add a targeting exclusion for that placement to prevent your ads from showing there anymore.

If view rate is not the most important statistic for you, you can modify the script to use a set of parameters that you value more highly when evaluating placements.


The only parameter in this script is VIEW_RATE_THRESHOLD. It specifies the target percentage of times users view the ad. Placements under this threshold are to be excluded.


  • Create a new script with the source code below.
  • Update VIEW_RATE_THRESHOLD in the pasted code.
  • Examine the criteria used to determine when to exclude a placement, and update them if necessary.
  • Schedule the script to run Weekly.

Source Code

// Copyright 2016, Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

 * @name Automatic Placement Exclusions
 * @overview The Automatic Placement Exclusions script analyzes the
 *     performance of your video ads across various placements, and then
 *     automatically excludes them from appearing for URLs that have
 *     underperformed based on VideoViewRate.
 *     See
 *     for more details.
 * @author Google Ads Scripts Team []
 * @version 2.0
 * @changelog
 * - version 2.0
 *   - Updated to use new Google Ads scripts features.
 * - version 1.0
 *   - Released initial version.

// The view rate under which placements will be automatically excluded.
let VIEW_RATE_THRESHOLD = '10.00%';

// Exclude any placements that don't have at least this many impressions in the
// last 7 days to reduce noise.

function main() {
  const results = getReportResults();
  const ids = [];
  for (const id in results) {
  const videoCampaignIterator = AdsApp.videoCampaigns()
  for (const videoCampaign of videoCampaignIterator) {
    const id = videoCampaign.getId();
    if (results.hasOwnProperty(id)) {
      const urls = results[id];
      for (const url of urls) {

function getReportResults() {
  const query = `SELECT, ` +
        `detail_placement_view.target_url ` +
        `FROM detail_placement_view ` +
        `WHERE metrics.impressions >= ${MIN_IMPRESSIONS} ` +
        `AND metrics.video_view_rate < ` +
        `${(VIEW_RATE_THRESHOLD / 100)} ` +
  const report =;
  const rows = report.rows();
  const results = {};
  for (const row of rows) {
    const campaignId = row[''];
    const url = row['detail_placement_view.target_url'];
    if (!results.hasOwnProperty(campaignId)) {
      results[campaignId] = [];
    if (results[campaignId].indexOf(url) < 0) {
  return results;