Link Checker - Only check URLs for enabled ads in active campaigns and active ad groups

300 views
Skip to first unread message

Ian Spencer

unread,
Dec 31, 2014, 10:35:18 AM12/31/14
to adwords...@googlegroups.com
My apologies if this has been asked already...
I have a number of PAUSED ads which are also being checked on a regular basis and as such are eating into my quota.
Can anyone suggest a tweak to the Link Checker script where only enabled ads, in active campaigns and active ad groups are being checked?
Cheers
Ian

Alexander Wang

unread,
Jan 8, 2015, 6:06:45 PM1/8/15
to adwords...@googlegroups.com
Hi Ian,

Sorry for the delay. I'm assuming you're using the link checker solution we've posted on our developer site. In that case, the fix should be pretty straightforward. The snippet of code to focus on is in the main function:
  var anythingChanged = shelper.config.checkKeywords &&
      checkUrls
(AdWordsApp.keywords());
  anythingChanged
= (shelper.config.checkAds && checkUrls(AdWordsApp.ads())) ||
      anythingChanged
;
By default, AdWordsApp.keywords() and AdWordsApp.ads() will return a selector that will fetch all but deleted keywords and ads. The checkUrls method modifies this selector a bit by only returning keywords or ads that have destination urls and haven't been checked yet:
var iterator = selector
   
.withCondition("DestinationUrl STARTS_WITH_IGNORE_CASE 'h'")
   
.withCondition("LabelNames CONTAINS_NONE['" + LABEL_NAME + "']")
   
.orderBy('DestinationUrl')
   
.withLimit(800)
   
.get();
You simply need to modify these selectors so they filter out paused/deleted keywords/ads. You can either modify the selector in main() or in checkUrls().

In the main function, you would adjust the code like:
  var anythingChanged = shelper.config.checkKeywords &&
      checkUrls
(AdWordsApp.keywords()
         
.withCondition("Status = ENABLED")
         
.withCondition("CampaignStatus = ENABLED")
         
.withCondition("AdGroupStatus = ENABLED");
  anythingChanged
= (shelper.config.checkAds && checkUrls(AdWordsApp.ads()
         
.withCondition("Status = ENABLED")
         .withCondition("CampaignStatus = ENABLED")
         
.withCondition("AdGroupStatus = ENABLED"))) ||
      anythingChanged
;

Alternatively, you could just update checkUrls so that you filter out any non-enabled entities that you check:
var iterator = selector
   
.withCondition("Status = ENABLED")
   
.withCondition("CampaignStatus = ENABLED")
   
.withCondition("AdGroupStatus = ENABLED")
   
.withCondition("DestinationUrl STARTS_WITH_IGNORE_CASE 'h'")
   
.withCondition("LabelNames CONTAINS_NONE['" + LABEL_NAME + "']")
   
.orderBy('DestinationUrl')
   
.withLimit(800)
   
.get();

Hope this helps.

Cheers,
Alex

Melissa

unread,
Feb 3, 2015, 3:39:18 PM2/3/15
to adwords...@googlegroups.com
Hi Alex - does your solution below work for the MccApp version of the link checker script instead of just the AdwordsApp version? I attempted to implement the below for the MccApp script but wasn't successful. Also, the data output is in order by destination URL. How can you have it ordered by campaign instead? 

Thanks!

Alexander Wang

unread,
Feb 3, 2015, 3:51:47 PM2/3/15
to adwords...@googlegroups.com
Hi Melissa,

I think I was looking at the non-MCC version. The fix is the same, but the exact code is a bit different. For the MCC version, you'd change:
var keywords = AdWordsApp.keywords()

   
.withCondition("DestinationUrl STARTS_WITH_IGNORE_CASE 'h'")

   
.withCondition("LabelNames CONTAINS_NONE['" + settings.keywordsLabel +
       
"']")
   
.orderBy('DestinationUrl')
   
.get();


To
var keywords = AdWordsApp.keywords()

   
.withCondition("DestinationUrl STARTS_WITH_IGNORE_CASE 'h'")

   
.withCondition("LabelNames CONTAINS_NONE['" + settings.keywordsLabel +
       
"']")

   
.withCondition("Status = ENABLED")
   
.withCondition("CampaignStatus = ENABLED")
   
.withCondition("AdGroupStatus = ENABLED")

   
.orderBy('CampaignName DESC')
   
.get();

Same thing for ads (add the three status conditions and change the orderBy to what you want.

Cheers,
Alex

Melissa

unread,
Feb 3, 2015, 4:04:33 PM2/3/15
to adwords...@googlegroups.com
Thanks for your help & quick reply. Any guidance on how to prevent the response code 200 from appearing? I'd like to only see flags for 404 errors, etc but not for 200. 

Alexander Wang

unread,
Feb 3, 2015, 4:22:07 PM2/3/15
to adwords...@googlegroups.com
Hi Melissa,

I haven't tested this, but I think you could just add a small if-statement to the following block of code:
while (keywords.hasNext()) {
 
var keyword = keywords.next();
 
var status = getUrlStatus(keyword.getDestinationUrl());
  accountSheet
.appendRow(['', keyword.getDestinationUrl(),
                          status
, keyword.getCampaign().getName(),
                          keyword
.getAdGroup().getName(),
                          keyword
.getText(), '', '']);
  keyword
.applyLabel(settings.keywordsLabel);
}

Like this:
while (keywords.hasNext()) {
 
var keyword = keywords.next();
 
var status = getUrlStatus(keyword.getDestinationUrl());
 
if (status != 200) {
    accountSheet
.appendRow(['', keyword.getDestinationUrl(),
                            status
, keyword.getCampaign().getName(),
                            keyword
.getAdGroup().getName(),
                            keyword
.getText(), '', '']);
 
}
  keyword
.applyLabel(settings.keywordsLabel);
}

And then similar for ads and sitelinks. This should make sure good links don't show up in the spreadsheet and that they still get labeled so that you also don't check them again in subsequent executions.

Cheers,
Alex

Melissa

unread,
Feb 4, 2015, 2:38:18 PM2/4/15
to adwords...@googlegroups.com
Thanks Alex. After implementing the if-statement and .withConditions, I'm seeing in the Script dashboard under Summary column that the script was Completed (Logs), where as yesterday I was seeing X-Changes (Details) and was getting an email sent to me each time I re-ran the script. Screenshots attached.

Perhaps there just are no URL errors to report now that we prevented the 200 code from appearing, so is that why I'm not receiving an email and am seeing this? This is all over my head, so I'm doing the best I can here, I appreciate your help.
Screen Shot 2015-02-04 at 2.18.59 PM.png
Screen Shot 2015-02-04 at 2.18.36 PM.png

Alexander Wang

unread,
Feb 4, 2015, 3:30:53 PM2/4/15
to adwords...@googlegroups.com
Hi Melissa,

I think you'll want to check what the logs say. It should say how many entities it's checking (something like "Checking 57 keywords."). I think keywords with urls that result in 200 should still get labeled, so your script should still have changes. There are a few possibilities:

1. You ran the script multiple times today, so all of the keywords had already been labeled already. The solution is set up so that it can be scheduled hourly and will label all entities it's processed. Once it reaches a new day, it will delete the label, create a new one and start over. As such, once it's processed all of the entities (and labeled them all), it won't have any more changes to make. I'd expect the logs to say "Checking 0 keywords." if this is the case.

2. You've left one of the cells in the spreadsheet blank. Specifically, one of the cells in the "Dashboard" sheet. That sheet controls the labels that are used as well as the emails to use. Leaving them blank might cause the script to not perform as you need it.

3. All of the entities you were checking belong to paused campaigns or ad groups. The selector generated by AdWordsApp.keywords() has a bunch of conditions you've added (that it has a url, that is has the appropriate label name, that it is enabled, etc). It's possible that this doesn't match any entities (unlikely, but possible).

My suspicion is that the reason is #1. There might be other reasons, but it's hard to know without looking at the code. If you want to verify, you could clear the "last run date" cell in your script's spreadsheet and run the script again (or wait for it to run again if it's scheduled).

Cheers,
Alex
Reply all
Reply to author
Forward
0 new messages