Excluded Placement Lists

  • The provided code snippets demonstrate how to retrieve all placements within a specified excluded placement list using getPlacementsFromExcludedPlacementList function.

  • The addPlacementToList function enables adding a new placement to an existing excluded placement list by utilizing its URL and list name.

  • Both functions utilize the AdsApp.excludedPlacementLists() method for accessing and manipulating excluded placement lists within Google Ads, throwing an error if the specified list name isn't found.

Get all the placements in an excluded placement list

function getPlacementsFromExcludedPlacementList(name) {
  const excludedPlacementListIterator =
      AdsApp.excludedPlacementLists()
          .withCondition(`shared_set.name = '${name}'`)
          .get();

  if (!excludedPlacementListIterator.hasNext()) {
    throw new Error(`No excluded placement list with name '${name}' found.`);
  }

  const excludedPlacementList = excludedPlacementListIterator.next();
  return excludedPlacementList.excludedPlacements().get();
}

Add a placement to an excluded placement list

function addPlacementToList(url, name) {
  const excludedPlacementListIterator =
      AdsApp.excludedPlacementLists()
          .withCondition(`shared_set.name = '${name}'`)
          .get();

  if (!excludedPlacementListIterator.hasNext()) {
    throw new Error(`No excluded placement list with name '${name}' found.`);
  }
  const excludedPlacementList = excludedPlacementListIterator.next();
  excludedPlacementList.addExcludedPlacement(url);
}