Reputation: 560
I want to make an Adwords Script for a MCC account which contains several child-accounts labeled with multiple labels. I am looking for a Loop of all child-accounts and retrieving all labels per each child-account.
Here I will simulate an example how it is structured:
Root: (MCC Account)
Child-accounts:
1) English_Account (id: 1111-1111-111, labels: Priority-high; 60%)
2) Spanish_Account (id: 2222-2222-222, labels: Priority-medium; 30%)
3) German_Account (id: 3333-3333-333, labels: Priority-low; 10%)
Now, I am doing a Loop of all accounts and I want to retrieve all labels per each account (just to mention that labels are dynimically set according to budget spent). That`s why I need to retrieve them, in order to apply some functions for next steps according to Label Name.
var accountIds = ['1111-1111-111', '2222-2222-2222-222', '3333-3333-3333-333'];
var accounts = MccApp.accounts().withIds(accountIds).get();
while (accounts.hasNext()) {
var account = accounts.next();
// here should be something to retrieve all child-account labels
}
I would much appreciate all your suggestions or tips how to achieve this task.
Upvotes: 0
Views: 269
Reputation: 36
var accountIterator = MccApp.accounts().withIds(accountIds).get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
MccApp.select(account);
var accountLabelIterator = account.labels().get();
while (accountLabelIterator.hasNext()) {
var accountLabel = accountLabelIterator.next();
// Do whatever.
}
}
Check out https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_accountlabel for the methods you can run on the label.
Upvotes: 1