This is the legacy documentation for Google Ads scripts. Go to the current docs.

Automatic Placement Exclusion

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.

The Automatic Placement Exclusion script allows you to automatically identify and exclude placements (not YouTube URLs) that just aren't resulting in the views you'd expect on 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.

  1. Find statistics on video performance, specifically view rate, for the given campaign over the past week.
  2. 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 should take a stab at updating the script to use a set of parameters that you value more highly when determining which placements do and don't work for you.


The only parameter in this script is VIEW_RATE_THRESHOLD. It specifies the target percentage of times that people view your ad through. Placements under this threshold will be excluded.


  • Create a new script with the source code below.
  • Don't forget to update VIEW_RATE_THRESHOLD in the pasted code.
  • Take a careful look at the conditions used to determine when to exclude a placement, and consider updating them to stats that may be more relevant for your business.
  • Schedule the script 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 1.0
 * @changelog
 * - version 1.0
 *   - Released initial version.

// The view rate under which placements will be automatically excluded.
var 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() {
  var results = getReportResults();
  var ids = [];
  for (var id in results) {
  var videoCampaignIterator = AdsApp.videoCampaigns()
  while (videoCampaignIterator.hasNext()) {
    var videoCampaign =;
    var id = videoCampaign.getId();
    if (results.hasOwnProperty(id)) {
      var urls = results[id];
      for (var i = 0; i < urls.length; i++) {

function getReportResults() {
  var query = 'SELECT CampaignId, Url' +
    ' WHERE Impressions >= ' + MIN_IMPRESSIONS +
    ' AND VideoViewRate < ' + (VIEW_RATE_THRESHOLD / 100) +
  var report =;
  var rows = report.rows();
  var results = {};
  while (rows.hasNext()) {
    var row =;
    var campaignId = row['CampaignId'];
    var url = row['Url'];
    if (!results.hasOwnProperty(campaignId)) {
      results[campaignId] = [];
    if (results[campaignId].indexOf(url) < 0) {
  return results;