Unexpected error: https://www.xxxx.com (line 66)

681 views
Skip to first unread message

Jose Miguel Latorre Ballester

unread,
Feb 24, 2017, 2:58:51 PM2/24/17
to AdWords Scripts Forum
Hello,

Please, I need some help because the script to check the status of the KW URL always says in Logs "Unexpected error: https://www.xxxx.com (line 66)"

The line always is 66, but the URL of our site is different each time. 

Here you can find the script I'm using for:

function main() {
 
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
 
  var split = true; //true or false
 
  var type = "keywords"; //choose "keywords" or "ads"
 
  //Campaign name filters
  //Leave as [] to skip
  var containsArray = []; // enter like ["hey", "jude"]
  var excludesArray = []; // enter like ["hey", "jude"]
 
  //keyword labels
  //Leave as [] to skip
  var labelArray = ["LT Script"]; // enter like ["hey", "jude"]
 
  //leave as "" to skip
  var status = "ENABLED"; //Choose from "ENABLED" or "PAUSED"
  var campaignStatus = "ENABLED"; //Choose from "ENABLED" or "PAUSED"
  var adGroupStatus = "ENABLED"; //Choose from "ENABLED" or "PAUSED"
 
  //300 301, 302 are redirects
  var allowedCodes = [301,404]; //enter like [200,301]
 
  //leave as "" to skip
  var recipients = "mye...@myemail.com"; //enter like "a...@b.com,c...@d.com,e...@g.co.uk"
 
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
 
  var urls = [];
  var bad_urls = [];
  var urlFetchOptions = {muteHttpExceptions: true};
 
  var string = iteratorConstructor(type, containsArray, excludesArray, labelArray, status, campaignStatus, adGroupStatus);
  eval(string);
 
  while(iterator.hasNext()){
    var object = iterator.next();
    var url = object.urls().getFinalUrl();
    if (url === null || url === undefined || url === ""){
      var url = object.getDestinationUrl();
    }
    if(url !== null && url !== undefined){
      if(split){
        url = url.split('?')[0];
      }
      if(urls.indexOf(url) === -1) {
        urls.push(url);
      }
    }
  }
 
  //Logger.log(urls);
 
  for(var x in urls){
    var response = UrlFetchApp.fetch(urls[x],urlFetchOptions);
    var code = response.getResponseCode();
    if(allowedCodes.indexOf(code) === -1){
      bad_urls.push(urls[x]);
    }
  }
 
  Logger.log(bad_urls.join("\n"));
 
  if(recipients.length > 0){
 
    var name = AdWordsApp.currentAccount().getName();
    var subject = name + " URL checking";
    var body = bad_urls.join("\n");
    MailApp.sendEmail(recipients,subject,body);
  }
 
  function iteratorConstructor(type, containsArray, excludesArray, labelArray, status, campaignStatus, adGroupStatus){
 
    var string = "var iterator = AdWordsApp."+type+"()";
    for(var i = 0; i < containsArray.length; i++){
      string = string + ".withCondition('CampaignName CONTAINS_IGNORE_CASE " + '"' + containsArray[i] + '"' + "')";
    }
    for(var i = 0; i < excludesArray.length; i++){
      string = string + ".withCondition('CampaignName DOES_NOT_CONTAIN_IGNORE_CASE " + '"' + excludesArray[i] + '"' + "')";
    }
    if(labelArray.length > 0){
      string = string + ".withCondition('LabelNames CONTAINS_ANY " + '["' + labelArray.join('","') + '"]' + "')";
    }
    if(status.length > 0){
      string = string + ".withCondition('Status = " + status + "')";
    }
    if(campaignStatus.length > 0){
      string = string + ".withCondition('CampaignStatus = " + campaignStatus + "')";
    }
    if(adGroupStatus.length > 0){
      string = string + ".withCondition('AdGroupStatus = " + adGroupStatus + "')";
    }
 
    string = string + ".orderBy('Cost DESC').forDateRange('LAST_30_DAYS')";
    string = string + ".withLimit(50000)";
 
    string = string + ".get();"
 
    return string;
 
  }
 
}

Have you had someone of you the same problem or knows what's wrong?

Thank you for your help and time.

Regards
Jose Miguel

Anthony Madrigal

unread,
Feb 24, 2017, 4:25:24 PM2/24/17
to AdWords Scripts Forum
Hi Jose,

Could you please provide me with your CID and script name so that I can take a look at what is going wrong?

Please use reply privately to author.

Thanks,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages