AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Ads
2.6K members online now
2.6K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Applying account label in a script

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi guys,

 

I am quite new to AdWords scripts API, and cannot understand, what i am doing wrongly, I will appreciate any help.

I have a lot more then 50 sub-accounts in my AdWords account, and i have to schedule my script to run multiple times to process everything. To mark the accounts, which are already processed, i want to use account labels.

 

I take another 50 accounts without my label, and execute in parallel. Then after processing i want to add the label.

 

var processedLabel = 'SCR-34 done';

 

function main () {

  var accountIterator = MccApp.accounts().withCondition('LabelNames DOES_NOT_CONTAIN "' + processedLabel + '"').withLimit(50);
  accountIterator.executeInParallel("processClientAccount", "afterProcessAllClientAccounts");

}

 

function processClientAccount() {
  var clientAccount = AdWordsApp.currentAccount();  
  MccApp.select(clientAccount);  

 

  // logic here


  clientAccount.applyLabel(processedLabel);  // line 222

}

 

And everything goes fine before line 222:

TypeError: Cannot find function applyLabel in object Account. (line 222)

 

Please advise how do i apply the label to account when executing in parallel.

 

 

Thank you,

Julia

2 Expert replyverified_user

Re: Applying account label in a script

[ Edited ]
Top Contributor
# 2
Top Contributor


(1) applylabel for accounts is unsupported -- setName is likely what is wanted;

(2) labelnames are sets (arrays) so string conditions are not supported --
the likely options are to either use a more appropriate condition
or, use accountlabels() and labelname so a string can be used;

as opposed to accounts() and labelnames.

generally, be careful when manipulating mcc-account-level labels
and sub-account-level labels -- these are not necessary the same
with respect to the various script-api calls.

also, the scripts forum is currently here:
https://groups.google.com/forum/#!forum/adwords-scripts

Re: Applying account label in a script

Top Contributor
# 3
Top Contributor

Hi @Юлия В I don't think the applyLabel method is the problem.  Unless I'm mistaken this is a valid method for the Account object - it's still shown in the scripts documentation and still appears in the auto-enter prompt for an Account object...

 

I would suspect the problem is that clientAccount is not a valid Account object and this is probably because "DOES_NOT_CONTAIN" is not the correct operator for LabelNames as @Celebird has said.  Use "CONTAINS_NONE" instead and you may find it springs into life.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Applying account label in a script

[ Edited ]
Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hello Celebird,

Thank you for your reply.
As i understand both your suggestions are about renaming accountLabels itself? Which is not what i really need.

But you are right, that applyLabel for accounts is not supported, and thank you for the link, i found out, that it's not only me who is waiting for this method Smiley Happy It is in TODO list since last year.

(Though i just noticed, that it is mentioned in documentation, like it is supported: https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_managedaccount

I am confused now)

As for my case, i'll try to save the list of processed accounts' IDs in a google spreadsheet instead - till applyLabel method is introduced.

Thanks again,
Julia

Re: Applying account label in a script

[ Edited ]
Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi Jon,

 

Thank you for your time.
Everything should be fine with my selector, it works, and returns valid Account objects (at least other account methods work fine). I wrote it based on this:

 

For Array columns (e.g. LabelNames):
CONTAINS  DOES_NOT_CONTAIN
e.g., LabelNames CONTAINS 'ACCOUNT_LABEL'
https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_managedaccountselector#wi...

 

Actually that's weird, as applyLabel is in the documentation: https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_managedaccount
But it doesn't work, and doesn't appear in auto-suggest list:
auto-suggest for account

Re: Applying account label in a script

[ Edited ]
Top Contributor
# 6
Top Contributor

 

first, you're welcome.


the client-account labels are not the same as the mcc-account-labels --
client-accounts cannot directly apply labels to its mcc-account entry.

those api reference (apply) label methods seem to be for mccapp, not adwordsapp;
whereas, the code's (apply) label methods seem to be for adwordsapp, not mccapp --
i believe such account label methods are not currently supported.

the condition filter and mccapp.select do not change those details --
but once called, do effect the ability to call (label) methods on
mcc (app) account-labels, since a client-account is now selected.

assuming what is wanted is to reach-back and effect the mcc-labels,
one possibility is to use the client-id to change the appropriate set.

for example --
// logic here
setMccLabel(clientAccount);

function setMccLabel(aap) {
// assumes required processedLabel exists in the mcc-account-labels database
// note: apply adds the label -- not a replace
// TODO: validation and error checking for aap, map, processedLabel, etc.

var map = MccApp.accounts().withIds([aap.getCustomerId()]).get().next();

Logger.log("setMccLabel:aap: " + aap.getName() + ':' + aap.getCustomerId());
Logger.log("setMccLabel:map: " + map.getName() + ':' + map.getCustomerId());

// uncomment the next line to go live:
// map.applyLabel(processedLabel);
}