AdWords
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

Labeling Keywords from MCC loop using Adwords Script

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

EDIT: SORRY MISPLACED IMAGES!

 

Hello everyone,

 

I have the following code:

 

...
var accountIterator = MccApp.accounts()
    .withIds(accountIds)
    .get();
  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    Logger.log(account.getName());
    MccApp.select(account);
    setLabels(t1, 'T1');
}
...

function setLabels(ids, label) {
  var keywordIterator = AdWordsApp.keywords()
    .withIds(ids)
    .withCondition("Status = ENABLED")
    .withCondition("CampaignStatus = ENABLED")
    .get();
  while (keywordIterator.hasNext()) {
    var keyword = keywordIterator.next();
    keyword.removeLabel("T1");
    keyword.removeLabel("T2");
    keyword.removeLabel("T3");
    keyword.removeLabel("T4");
    keyword.applyLabel(label);
  }
}

When I run it, and add some logging functions on the loop,, everything looks fine, but then the preview changes look like this: 

 

Capture.PNG

 

While if I run the function at the account level directly, no MCC involved, I get the following, which is correct:

 

Capture2.PNG

 

What am I missing here? why is this not working?


Cheers,

 

 

 

1 Expert replyverified_user

Re: Labeling Keywords from MCC loop using Adwords Script

Top Contributor
# 2
Top Contributor

Hi @Pablo T I can't see anything unusual about that preview output.  You're removing the Label named "T1" in one step, then a few lines later are applying a Label named "T1" and that's what the preview is showing.  If you're looking for the removal of Labels T2, T3 and T4, first you'd need to be sure those Labels are actually applied to any Keywords, and specifically that those Keywords are being picked up in your selector (I presume t1 is an array of Keyword ids?).

 

Jon

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

Re: Labeling Keywords from MCC loop using Adwords Script

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Jon,

Really sorry, I messed up the pictures. Please refer to my edited posts, i'm not getting the correct output when I do that at a MCC level.

And you're right, T1 is an array of Keyword Ids.

Cheers,

Re: Labeling Keywords from MCC loop using Adwords Script

Top Contributor
# 4
Top Contributor

Hi @Pablo T no problem, kinda glad I was right in identifying that your original pictures didn't show a problem Smiley Happy

 

I'd have to check (I can't right now) but I suspect the "empty" changes you're seeing are the removal of the Labels from Keywords that don't have those Labels applied.  What I'd need to check is whether attempting to remove a non-applied Label produces this empty output, but I'm sure you can do that.  I'd try adding a condition to your Keyword selector so it only selects Keywords that have any of T1, T2, T3 or T4 applied, this will not only stop the null changes but also speed the script up a little.

 

.withCondition("LabelNames CONTAINS_ANY ['T1','T2','T3','T4']")

should do it.

 

Why you're seeing something different at the MCC level than at the Account is more difficult to answer without knowing your structure, but it could be as simple as the first Account processed has some of these unlabelled Keywords whereas the one you choose to test individually doesn't have any (or as many).  Try some more Logging to check which Accounts are producing which results.

 

Jon

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

Re: Labeling Keywords from MCC loop using Adwords Script

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

Capture.PNG

 

Even when using your condition (which indeed speeds up the script, thanks), it still shows that. even if this keywords should be relabeled.

 

If i run the exact same code without the Account Iterator, direct at the account level, it works perfectly, so I'm wondering why it's not working.

 

 

Re: Labeling Keywords from MCC loop using Adwords Script

Top Contributor
# 6
Top Contributor

Hi @Pablo T are you letting the preview finish or stopping it early?

 

Jon

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

Re: Labeling Keywords from MCC loop using Adwords Script

[ Edited ]
Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hello Jon,

Just letting it run til the end.

I got tired of previewing and seeing nothing so I actually ran the script.

 

Gladly, the problem is only in the changes log(which still shows no changes made, even when I ran it for real) but changes actually happen in the account, so it's a bug on Google Adwords Script Changes Log.

How could I report this bug?

Cheers,

Re: Labeling Keywords from MCC loop using Adwords Script

Top Contributor
# 8
Top Contributor

Hi @Pablo T I've seen odd things too when running scripts at the MCC level, most notably logs being delayed (not outputting as they happen).

 

Probably the best thing to do is head over to the AdWords Scripts Google Group (just search for that).  You can check if the issue has already been discussed/reported and if not start a new thread there.  There's a Google script guy who'll pick it up.

 

Jon

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