Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* This function verifies that the keywords already in limbo
* but are no longer a dud have the labels removed as needed.
function checkForRedemption(duds,changes_to_make) {
// An array works well for selectors, but
// it will be much easier to do lookups here if
// we transform the duds array into a map.
var dudsMap = {};
for(var i in duds) {
dudsMap[[duds[i][0],duds[i][1]].join('-')] = true;
var labelIter = AdWordsApp.labels().withCondition("Name STARTS_WITH 'Deleting in '").get();
while(labelIter.hasNext()) {
var label =;
var kwIter = label.keywords().get();
while(kwIter.hasNext()) {
var kw =;
var key = [kw.getAdGroup().getId(),kw.getId()].join('-');
if(!dudsMap[key]) {
// The keyword is no longer a dud. Let's remove the label.
// We have to find the label linked to this keyword though since
// we don't want to delete the label from the entire account.
var newLabelIter = kw.labels().withCondition("Name STARTS_WITH 'Deleting in '").get();
while(newLabelIter.hasNext()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment