Showing posts with label remove. Show all posts
Showing posts with label remove. Show all posts

Wednesday, December 5, 2012

Automating Maintenance Tasks with AdWords Scripting Part 3

In our final installment of automating the monthly maintenance tasks found in AdWords for Dummies with AdWords scripting, let's end with the end of the month clean up of your account.

Declutter your account by shedding keywords that don't have any conversions.


Similar to the previous post, you will need to have set up conversion tracking for all of this to work.  We can actually use a variation of the previous script to accomplish this.  Really we are doing the same thing just increasing bids instead of decreasing them.

//-----------------------------------
// Pause Keywords That Are Not Performing
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  var THE_VALUE_OF_ONE_CONVERSION = 10;
  var DECREASE_BIDS_BY_PERCENTAGE = .5;
  
  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) {
      if(THE_VALUE_OF_ONE_CONVERSION * 5 > cost) {
        kw.pause();
      }
      else if(THE_VALUE_OF_ONE_CONVERSION * 2 > cost) {
        kw.setMaxCpc(kw.getMaxCpc() * (1-DECREASE_BIDS_BY_PERCENTAGE)); 
      }
    }else{
      //no conversions on this keyword
      //we will deal with that later
      continue;
    }
  }
}

Thanks,
Russ

Tuesday, November 20, 2012

Update Your Keywords for the Holiday Season

The other day, RKGBlog had a great post about updating your keywords for the holiday season. One of the mentions was to update all the years in your Keywords to the current year. Here is a little script that will find all the Keywords with the previous year in them and create new Keywords in the same AdGroup with the current year.

Thanks,
Russ
/*********************************************
* Update Keywords for the New Year
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments 
* Created By: Russ Savage
* FreeAdWordsScripts.com
**********************************************/
function main() {
  var sameDayLastYear = new Date();
  sameDayLastYear.setYear(sameDayLastYear.getYear()-1);
  var oldYearStr = sameDayLastYear.getYear().toString();
  var newYearStr = new Date().getYear().toString();
  
  Logger.log('Updating keywords with old year: '+oldYearStr+' to new year: '+newYearStr);
  
  // Let's start by getting all of the keywords
  var kwIter = AdWordsApp.keywords()
    .withCondition("Text CONTAINS " + oldYearStr)
    .withCondition("Status = ENABLED")
    .withCondition("AdGroupStatus = ENABLED")
    .withCondition("CampaignStatus = ENABLED")
    .get();
 
  // It is always better to store and batch process afterwards
  var toPause = [];
  var toCreate = [];
  while (kwIter.hasNext()) {
    var kw = kwIter.next();
    var ag = kw.getAdGroup();
    var oldText = kw.getText();
    var newText = oldText.replace(oldYearStr,newYearStr);
    // Save the info so that we can create them as a batch later
    toCreate.push({ ag: ag, text: newText, cpc:kw.getMaxCpc(), destUrl : kw.getDestinationUrl() });
    // Same with the ones we want to pause
    toPause.push(kw) 
  }
  // Now we create the new keywords all at once
  for(var i in toCreate) {
    var elem = toCreate[i];
    elem.ag.createKeyword(elem.text, elem.cpc, elem.destUrl);
  }
  // And pause the old ones all at once
  for(var i in toPause) {
    toPause[i].pause();
    //or toPause[i].remove(); to delete the old keyword
  }
}