Skip to content

Instantly share code, notes, and snippets.

@russorat
Created November 13, 2015 19:12
Show Gist options
  • Save russorat/b5c096f9fe9cf6a0c483 to your computer and use it in GitHub Desktop.
Save russorat/b5c096f9fe9cf6a0c483 to your computer and use it in GitHub Desktop.
/***********
* 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 = labelIter.next();
var kwIter = label.keywords().get();
while(kwIter.hasNext()) {
var kw = kwIter.next();
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()) {
changes_to_make.labels_to_delete.push(newLabelIter.next());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment