Removing Labels in Keyword Labeler (MCC) Script

389 views
Skip to first unread message

Kelly Konechny

unread,
Jul 21, 2016, 4:10:49 PM7/21/16
to AdWords Scripts Forum
Hi everyone!

We are using the Keyword Labeler script to apply a label based on a few different metrics to client accounts from our MCC account. The script is set to run once daily and the metrics it's basing the label application on will change day to day. We use the labels as a current days' status to examine.

One metric will have the potential to have any one of a total of 6 different labels applied at the keyword level. The script applies the label as intended, but what we're finding is the need to have any of the 6 potential labels, that might have been applied previously, removed before applying the new label. 

The issue is producing one keyword with multiple labels applied, of those, only one being valid for the daily run. We need to wipe the slate blank before applying the labels with the rules defined in the script. 

Does anyone have any suggestions on how to best create the addition to the script so that it would remove any label from a pre-defined set of labels before running and processing the accounts?

Thanks in advance!
Kelly

Trevor

unread,
Jul 21, 2016, 6:06:57 PM7/21/16
to AdWords Scripts Forum
Hi Kelly,

You could simply filter by keywords with each label and remove them. This script is one I run nightly to remove a label I use to track whether the client has received a notification about a campaign being out of budget. It could be adjusted to do what you need to do, though you'd of course also need to configure it as an MCC script.

function main() {
   
var SENTLABEL = "Sent";

// Get existing campaigns with this label
   
var alreadyLabeled = AdWordsApp.campaigns()
       
.withCondition('Status = ENABLED')
   
.withCondition("LabelNames CONTAINS_ANY [" + SENTLABEL + "]")
       
.get();


//Remove label from campaigns
 
while (alreadyLabeled.hasNext())
 
{
   
var adG = alreadyLabeled.next();
    adG
.removeLabel(SENTLABEL);
 
}
}

Jaren Callo (AdWords Scripts Team)

unread,
Jul 21, 2016, 10:23:15 PM7/21/16
to AdWords Scripts Forum
Thanks Trevor!

Hi Kelly,

Let us know if the solution provided by Trevor solved your problem. 

Thanks,
Jaren P. Callo
AdWords Scripts Team

Kelly Konechny

unread,
Jul 27, 2016, 2:42:28 PM7/27/16
to AdWords Scripts Forum
Great idea - thanks for the help Trevor!

Kelly

Kelly Konechny

unread,
Jul 27, 2016, 2:42:51 PM7/27/16
to AdWords Scripts Forum
Works great - thanks for the follow up too Jaren!

Andrea Testa

unread,
Jul 28, 2016, 4:48:12 AM7/28/16
to AdWords Scripts Forum
Hi Kelly,
maybe it could be useful also this script, discussed a few weeks ago in this Group.

function main() {
 
// Get an iterator for the labels
 
  var labelIterator = AdWordsApp.labels()
  .withCondition("LabelName IN ['LabelName1', 'LabelName2', 'LabelName3']")

  .get()


// Gather the labels you want to delete into an array
var labels_to_delete = [];
while (labelIterator.hasNext()) {
  var label = labelIterator.next();
  labels_to_delete.push(label);
}
// Actually delete the labels
for (var i = 0; i < labels_to_delete.length; i++) {
  var label = labels_to_delete[i];
  label.remove();
}

}

Thanks to this script, you can also select which label you want to remove.

Run at account level, an hour before the "Keyword Labeler".
Andrea
Reply all
Reply to author
Forward
0 new messages