Instalacja skryptów. Zepsute linki w kampanii AdWords

Dzisiaj opowiem, w jaki sposób można zautomatyzować sprawdzanie zepsutych linków w AdWords (błąd 404, 500 itd).

W kampanii AdWords klikamy Operacje zbiorcze > Tworzenie skryptów i zarządzanie nimi. Naciskamy na przycisk + Skrypt.

Wpisujemy nazwę skryptu (na przykład: Report on Broken Urls In Your Account). Kopiujemy skrypt:

/****************************
* Find Broken Urls In Your Account
* Version 1.1
* ChangeLog v1.1
*  – Updated to only see Text Ads
* Created By: Russ Savage
* FreeAdWordsScripts.com
****************************/
function main() {
 // You can add more if you want: http://goo.gl/VhIX
 var BAD_CODES = [404,500];
 var TO = [‘test@gmail.com’];
 var SUBJECT = ‘Broken Url Report – ‘ + _getDateString();
 var HTTP_OPTIONS = {
   muteHttpExceptions:true
 };
   
 //Let’s look at ads and keywords for urls
 var iters = [
   //For Ad Level Urls
   AdWordsApp.ads()
     .withCondition(“Status = ‘ENABLED'”)
     .withCondition(“AdGroupStatus = ‘ENABLED'”)
     .withCondition(“CampaignStatus = ‘ENABLED'”)
     .withCondition(“Type = ‘TEXT_AD'”)
     .get(),
   //For Keyword Level Urls
   AdWordsApp.keywords()
     .withCondition(“Status = ‘ENABLED'”)
     .withCondition(“DestinationUrl != ””)
     .withCondition(“AdGroupStatus = ‘ENABLED'”)
     .withCondition(“CampaignStatus = ‘ENABLED'”)
     .get()
   ];
  
 var already_checked = {};
 var bad_entities = [];
 for(var x in iters) {
   var iter = iters[x];
   while(iter.hasNext()) {
     var entity = iter.next();
     if(entity.getDestinationUrl() == null) { continue; }
     var url = entity.getDestinationUrl();
     if(url.indexOf(‘{‘) >= 0) {
       //Let’s remove the value track parameters
       url = url.replace(/\{[0-9a-zA-Z]+\}/g,”);
     }
     if(already_checked[url]) { continue; }
     var response_code;
     try {
       Logger.log(“Testing url: “+url);
       response_code = UrlFetchApp.fetch(url, HTTP_OPTIONS).getResponseCode();
     } catch(e) {
       //Something is wrong here, we should know about it.
       bad_entities.push({e : entity, code : -1});
     }
     if(BAD_CODES.indexOf(response_code) >= 0) {
       //This entity has an issue.  Save it for later.
       bad_entities.push({e : entity, code : response_code});
     }
     already_checked[url] = true;
   }
 }
 var column_names = [‘Type’,’CampaignName’,’AdGroupName’,’Id’,’Headline/KeywordText’,’ResponseCode’,’DestUrl’];
 var attachment = column_names.join(“,”)+”\n”;
 for(var i in bad_entities) {
   attachment += _formatResults(bad_entities[i],”,”);
 }
 if(bad_entities.length > 0) {
   var options = { attachments: [Utilities.newBlob(attachment, ‘text/csv’, ‘bad_urls_’+_getDateString()+’.csv’)] };
   var email_body = “There are ” + bad_entities.length + ” urls that are broken. See attachment for details.”;
     
   for(var i in TO) {
     MailApp.sendEmail(TO[i], SUBJECT, email_body, options);
   }
 }  
}
 
//Formats a row of results separated by SEP
function _formatResults(entity,SEP) {
 var e = entity.e;
 if(typeof(e[‘getHeadline’]) != “undefined”) {
   //this is an ad entity
   return [“Ad”,
           e.getCampaign().getName(),
           e.getAdGroup().getName(),
           e.getId(),
           e.getHeadline(),
           entity.code,
           e.getDestinationUrl()
          ].join(SEP)+”\n”;
 } else {
   // and this is a keyword
   return [“Keyword”,
           e.getCampaign().getName(),
           e.getAdGroup().getName(),
           e.getId(),
           e.getText(),
           entity.code,
           e.getDestinationUrl()
          ].join(SEP)+”\n”;
 }
}
 
//Helper function to format todays date
function _getDateString() {
 return Utilities.formatDate((new Date()), AdWordsApp.currentAccount().getTimeZone(), “yyyy-MM-dd”);
}


Uwaga!

  1. W części kodu function main zmieniamy adres e-mail na swój własny.
  2. W BAD_CODES można dodać inne błędy (błąd 501 itd.).


Potem klikamy Zapisz, Podgląd oraz Uruchom skrypt teraz.

To wszystko. Skrypt zainstalowany. Teraz mamy dwie opcje:

  • klikamy Uruchom i skrypt sprawdza wszystkie linki a kampanii albo
  • tworzymy harmonogram i skrypt sprawdzi wszystkie URL samodzielnie.

 

Izabela Smoter
Wróć do listy