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
function main() {
  var kw_iter = AdWordsApp.keywords()
    .withCondition("Status = ENABLED")
  while(kw_iter.hasNext()) {
    var kw =;
    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) {
      else if(THE_VALUE_OF_ONE_CONVERSION * 2 > cost) {
        kw.setMaxCpc(kw.getMaxCpc() * (1-DECREASE_BIDS_BY_PERCENTAGE)); 
      //no conversions on this keyword
      //we will deal with that later


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.

* Update Keywords for the New Year
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments 
* Created By: Russ Savage
function main() {
  var sameDayLastYear = new Date();
  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")
  // It is always better to store and batch process afterwards
  var toPause = [];
  var toCreate = [];
  while (kwIter.hasNext()) {
    var kw =;
    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
  // Now we create the new keywords all at once
  for(var i in toCreate) {
    var elem = toCreate[i];, elem.cpc, elem.destUrl);
  // And pause the old ones all at once
  for(var i in toPause) {
    //or toPause[i].remove(); to delete the old keyword