Thursday, November 29, 2012

Automating Maintenance Tasks With AdWords Scripting Part 1

I'm not ashamed.  I read "for Dummies" books.  And one of my favorites is AdWords for Dummies. Say what you want about these books, but they are easy to read and have great info for getting started quickly.

One of the chapters in the book describes a monthly routine for maintaining your AdWords account.  Using AdWords scripts is a good way to automate these tasks.  Let's start with the first of the month.

"On the first day of the month, deal with all the keywords that are converting too expensively."


Sounds simple enough.  Of course, you will need to have set up conversion tracking for all of this to work. They say pull the last 30 days, which is what we have done here, but you can pull any time range you like.  This follows the example from the book.  You should of course replace the values at the top with ones that make sense for your business.

//-----------------------------------
// Reduce Bids on High Cost per Conversion Keywords
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  //Let's reduce keywords with a CPC greater than $15 by 35%
  var WAY_TOO_HIGH_COST_PER_CONV = 15;
  var WAY_TOO_HIGH_BID_REDUCTION_AMOUNT = .35;
  
  //And keywords with CPC between $10 and $15 by 20%
  var TOO_HIGH_COST_PER_CONV = 10;
  var TOO_HIGH_BID_REDUCTION_AMOUNT = .20;
  
  var kw_iter = AdWordsApp.keywords()
    .withCondition("Status = ENABLED")
    .get();
  
  while(kw_iter.hasNext()) {
    var kw = kw_iter.next();
    var kw_stats = kw.getStatsFor("LAST_30_DAYS");
    var cost = kw_stats.getCost();
    var conversions = kw_stats.getConversions();
    if(conversions > 0) {
      var cost_per_conversion = (cost/(conversions*1.0));
      //Here is the magic.  If it is way too high, reduce it by the way too high amount
      if(cost_per_conversion >= WAY_TOO_HIGH_COST_PER_CONV) {
        kw.setMaxCpc(kw.getMaxCpc() * (1-WAY_TOO_HIGH_BID_REDUCTION_AMOUNT)); 
      }
      //otherwise, if it is still too high, reduce it with just the too high amount
      else if(cost_per_conversion >= TOO_HIGH_COST_PER_CONV) {
        kw.setMaxCpc(kw.getMaxCpc() * (1-TOO_HIGH_BID_REDUCTION_AMOUNT));
      }
    }else{
      //no conversions on this keyword
      //we will deal with that later
      continue;
    }
  }
}
And that's it. Stay tuned for the next installment where we tackle the keywords that are performing well by increasing their bids.

Thanks,
Russ

Wednesday, November 28, 2012

Getting Started with Using These Scripts

Much like the movie that shows the opening title fifteen minutes into the feature, today I'm going to talk a little about actually using the scripts that are posted on this site.  Think of it as a getting started guide for using the information presented on this blog.

Most of the information here comes from working through the developer documentation for AdWords scripting, which can be found here.

How do I actually get to the place where I enter the scripts?

The easiest way I've found to get to the place to enter these scripts is to select the "Create and Manage Scripts >>" option from the "Automate" button on the campaigns tab.
That will land you on a page that allows you to create a new script.

Once you have created a new script, you should be able to copy any of the scripts on this blog directly into the text box (after deleting what is in there for starters).
Google has an awesome feature that allows you to preview the results of the script before actually running it on your account.  In order for anything to run, you must "authorize" the script to access your account.  Just click the "Authorize now" button and follow the prompts.

Once you preview the script, you can name it, save it, and run it for real on your account.  Scheduling it to run is also just a simple matter of clicking on the "Create schedule" link on the scripts page.

And there you have it.  Let me know if you have any trouble setting up one of my scripts by commenting on the post.  If you are having trouble, likely someone else is as well.

Thanks,
Russ


Monday, November 26, 2012

Update Ads for the New Year

This is a companion to one of my earlier posts about updating your keywords for the new year.  You can easily run through each ad you have and update them all for the new year using the script below.  It will also pause the old ad as well, making sure your staying relevant to your customers.  You should schedule this to run every year on January 1st if your advertising relies heavily on dated traffic.

Thanks,
Russ

//-----------------------------------
// Update Ads for 2012
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  var OLD_YEAR = "2011";
  var NEW_YEAR = "2012";
  //You probably shouldn't update destination urls unless you know what you are doing.
  var FIELDS_CONTAINING_YEAR = ["Headline","Description1",
                                "Description2","DisplayUrl"
                                /*,"DestinationUrl"*/
                               ];
  
  for(i in FIELDS_CONTAINING_YEAR) {
    var field_iter = AdWordsApp.ads()
        .withCondition(FIELDS_CONTAINING_YEAR[i] + " CONTAINS " + OLD_YEAR)
        .withCondition("Status = ENABLED")
        .get();
    
    _iterateThroughAds(field_iter);
  }

  //---------------
  // Private Helper Functions
  //---------------  
  function _iterateThroughAds(ad_iter) {
    while (ad_iter.hasNext()) {
      var ad = ad_iter.next();
      var ag = ad.getAdGroup();
      _createNewAdFromOldAd(ag,ad);
    }
  }
  
  function _createNewAdFromOldAd(adgroup, old_ad) {
    //get the updated ad texts replacing all the old years with the new years
    var new_headline = old_ad.getHeadline().replace(OLD_YEAR,NEW_YEAR);
    var new_desc1 = old_ad.getDescription1().replace(OLD_YEAR,NEW_YEAR);
    var new_desc2 = old_ad.getDescription2().replace(OLD_YEAR,NEW_YEAR);
    var new_display_url = old_ad.getDisplayUrl().replace(OLD_YEAR,NEW_YEAR);
    var new_dest_url = old_ad.getDestinationUrl();/*.replace(OLD_YEAR,NEW_YEAR);*/
    
    //now create the new ad and pause the old one.
    adgroup.createTextAd(new_headline,new_desc1,new_desc2,new_display_url,new_dest_url);
    old_ad.pause();
  }
}

Friday, November 23, 2012

Automatically Pause Ads with Low CTR

Recently, Brad over at CertifiedKnowledge.com published some tips about testing at scale.  One of the most common testing techniques he mentions is to create a ton of ads and let Google optimize the rotation for you.  The problem with this technique is that the losers are rarely deleted.  Well, using the script below, you can find the worst performing ads in all your adgroups and pause it (if there is at least one other ad in the adgroup).

Thanks,
Russ


//-----------------------------------
// Pause Ads with Low CTR
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  // Let's start by getting all of the adGroups that are active
  var ag_iter = AdWordsApp.adGroups()
  .withCondition("Status = ENABLED")
  .get();

  // Then we will go through each one
  while (ag_iter.hasNext()) {
    var ag = ag_iter.next();
    var ad_iter = ag.ads()
      .withCondition("Status = ENABLED")
      .forDateRange("ALL_TIME")
      .orderBy("Ctr DESC")
      .get();
    var ad_array = new Array();
    while(ad_iter.hasNext()) {
      ad_array.push(ad_iter.next());
    }
    if(ad_array.length > 1) {
      for(var i = 1; i < ad_array.length; i++) {
        ad_array[i].pause(); //or .remove(); to delete them 
      }
    }
  }
}