Skip to content

Instantly share code, notes, and snippets.

@neeksor
Forked from ddaws/excludePlacements.js
Last active November 1, 2018 18:58
Show Gist options
  • Save neeksor/f77a2f7603273d2cf4bb4505cb8364b4 to your computer and use it in GitHub Desktop.
Save neeksor/f77a2f7603273d2cf4bb4505cb8364b4 to your computer and use it in GitHub Desktop.
AdWords Negative Match Placements Term
/*
* Removes placements containing string
* Exclusions are per campaign.
* single account - no mcc support.
* badPatterns = csv list of words to filter.
* ex:
* var badPatterns = 'meowshareen, someotherspam';
*/
function main() {
// csv list of words
var badPatterns = 'meowshareen';
badPatterns.split(',').map(function (s) {return s.trim();})
.forEach(function (domain) {
var placementSelector = AdWordsApp.display().placements().withCondition("PlacementUrl CONTAINS '" + domain + "'").withCondition("CampaignStatus != REMOVED");
var placementIterator = placementSelector.get();
while (placementIterator.hasNext()) {
var placement = placementIterator.next();
var placementUrl = placement.getUrl();
Logger.log("Matching URL: " + placementUrl);
var campaign = placement.getCampaign();
var excludeOperation = campaign.display().newPlacementBuilder().withUrl(placementUrl).exclude();
if (!excludeOperation.isSuccessful()) {
Logger.log("Could not exclude : " + placementUrl);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment