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

AdWords Script - Pause ad groups with Redirected URL's

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭
I'm running a script that pauses ad groups with redirected URL's. Basically on my company's website, products that are discontinued have their pages redirected to the main page. 
For example, 
redirected to 
The script should:
- apply to only campaigns with the label "checkRedirects_test"
- pause AD GROUPS - not ads - within those campaigns
- pause the ads inside those ad groups 
- pause the keywords inside those ad groups 
Can someone check my code to see if I'm doing it correctly?
function main() {
 var campaignSelector = AdWordsApp.campaigns()
    .withCondition('Labels CONTAINS_ANY "checkRedirects_test"')
 var ad =;
 var adGroupSelector = AdWordsApp.adGroups().get();
 while (adGroupSelector.hasNext()) {
  var adGroup =;
 var recipient = ***hidden email***;
 var url = ad.urls().getFinalUrl();
 var response = UrlFetchApp.fetch(url);
 Logger.log(url + ' : ' + response.getResponseCode());
 if (response.getResponseCode() == 301 || response.getResponseCode() == 302) {
  MailApp.sendEmail(recipient, 'URL with redirects', url);
1 Expert replyverified_user

Re: AdWords Script - Pause ad groups with Redirected URL's

Top Contributor
# 2
Top Contributor

Hi @Vy N sorry for the delay in replying.  I haven't test run this script, but there's a few problems with what you have so far.  Firstly, if you want to check/act upon only the Ad Groups, Ads and Keywords within the Campaigns with that label, all your selectors will need to be taken from the Campaign objects produced by your first selector of Campaigns.  What you have right now is selecting all Ad Groups, Ads, etc.  You'll also need to iterate through all the Keywords and Ads to pause them, and I'd recommend storing the URLs in a variable, sending the email only once at the end of the script.

There's quite a bit of change needed here, have you made any progress since originally posting?







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