Showing posts with label pause. Show all posts
Showing posts with label pause. Show all posts

Monday, March 11, 2013

Merge Multiple Campaigns Together For Enhanced Campaigns Migration

UPDATE 2013-04-14: Check Merge Labels from Multiple Campaigns for some help on merging labels.

Everyone is getting ready for Enhanced Campaigns and for a lot of people, that means finding an easy way to merge multiple campaigns into a single campaign. You may have a campaign for desktop traffic and one for tablet, or maybe one for each major mobile platform.

Well the beauty and the pain of Enhanced Campaigns is that you can do more with less. I haven't found a great way to easily merge multiple campaigns into one, so I made my own. All you need to do is specify a destination campaign where you want all the keywords, adgroups, and ads to end up and the set of campaigns you want to copy from. This script will pause any keyword and ad it manages to move over so you can see results and make sure everything is set up properly before deleting the old campaigns.

Thanks,
Russ

//-----------------------------------
// Merge Multiple Campaigns Together
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  var DESTINATION_CAMPAIGN_NAME = "dest_camp_name";
  var ORIGIN_CAMPAIGN_NAMES = ["to_merge_camp_name_1","to_merge_camp_name_2"/*,...*/];
  var DEFAULT_KW_BID = 0.01; //used in case we can't get the origin kw bid
  
  //build a list of adgroups in the original 
  var dest_adgroups = [];
  var ag_iter = AdWordsApp.adGroups()
    .withCondition("CampaignName = '"+DESTINATION_CAMPAIGN_NAME+"'")
    .get();
  
  while(ag_iter.hasNext()) {
    dest_adgroups.push(ag_iter.next());
  }
  
  var dest_camp;
  if(dest_adgroups.length > 0) {
     dest_camp = dest_adgroups[0].getCampaign();
  }
  
  for(var i in ORIGIN_CAMPAIGN_NAMES) {
    var camp_name = ORIGIN_CAMPAIGN_NAMES[i];
    var kw_iter = AdWordsApp.keywords()
      .withCondition("CampaignName = '"+camp_name+"'")
      .get();
    while(kw_iter.hasNext()) {
      var kw = kw_iter.next();
      var dest_adgroup = _find_adgroup(dest_adgroups,kw.getAdGroup());
      if(!dest_adgroup) {
        dest_adgroup = dest_camp.newAdGroupBuilder()
          .withName(kw.getAdGroup().getName())
          .withStatus((kw.getAdGroup().isPaused()) ? "PAUSED" : "ENABLED")
          .withKeywordMaxCpc(kw.getAdGroup().getKeywordMaxCpc())
          .create();
        dest_adgroups.push(dest_adgroup);
        //now we move all the ads over
        var ad_iter = kw.getAdGroup().ads().get();
        while(ad_iter.hasNext()) {
          var ad = ad_iter.next();
          dest_adgroup.createTextAd(
            ad.getHeadline(),
            ad.getDescription1(),
            ad.getDescription2(),
            ad.getDisplayUrl(),
            ad.getDestinationUrl(),
            { isMobilePreferred : ad.isMobilePreferred() }
          );
          ad.pause();
        }
      }
      var max_cpc = kw.getMaxCpc() || DEFAULT_KW_BID;
      var dest_url = kw.getDestinationUrl() || "";
      var kw_text = kw.getText();
      dest_adgroup.createKeyword(kw_text,max_cpc,dest_url);

      kw.pause();
    }
  }

  function _find_adgroup(ag_list,ag) {
    for(var i in ag_list) {
      if(ag_list[i].getName() == ag.getName()) {
        return ag_list[i];
      }
    }
    return null;
  }
}

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

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 
      }
    }
  }
}

Wednesday, November 21, 2012

Pause AdGroups With No Active Keywords

This is a quick script to pause all the AdGroups with no active keywords in them. Not sure if this is super useful, but for large accounts, it might help identify AdGroups you can get rid of.

Thanks,
Russ

/*********************************************
* Pause AdGroups With No Active Keywords
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments 
* Created By: Russ Savage
* FreeAdWordsScripts.com
**********************************************/
function main() {
  // Let's start by getting all of the active AdGroups
  var agIter = AdWordsApp.adGroups()
    .withCondition('CampaignStatus = ENABLED')
    .withCondition('Status = ENABLED')
    .get();
 
  // It is faster to store them and process them all at once later
  var toPause = [];
  // Then we will go through each one
  while(agIter.hasNext()) {
    var ag = agIter.next();
    //get all the keywords that are enabled
    var kwIter = ag.keywords()
      .withCondition("Status = ENABLED")
      .get();
    
    //If .hasNext() is true, there is at least 1 kw in the AdGroup
    var hasKw = kwIter.hasNext(); 
    if(!hasKw) {
      toPause.push(ag);
    }
  }
  
  // Now we process them all at once to take advantage of batch processing
  for(var i in toPause) {
    toPause[i].pause();
  }
}

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
  }
}

Monday, November 19, 2012

Pause All Keywords With No Impressions

Let's start with a very simple script. This one will find all of the keywords in your account that has never had an impression, and pause (or delete if you see the comment below) that keyword so that it will not negatively impact your quality score. According to Google, the longer something sits in your account and stagnates, the greater the impact to your quality score. As a reader pointed out, the fourth bullet here seems to contradict this statement. This would be a great script to schedule every few months to make sure you are trimming all the dead weight from your accounts.

Thanks,
Russ
/*********************************************
* Pause Keywords With No Impressions All Time
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments 
* Created By: Russ Savage
* FreeAdWordsScripts.com
**********************************************/
var TO_NOTIFY = "your_email@domain.com";
function main() {
  // Let's start by getting all of the keywords with no impressions
  var kwIter = AdWordsApp.keywords()
    .withCondition("Impressions = 0") // could be "Clicks = 0" also
    .forDateRange("ALL_TIME") // could use a specific date range like "20130101","20131231"
    .withCondition("Status = ENABLED")
    .withCondition("CampaignStatus = ENABLED")
    .withCondition("AdGroupStatus = ENABLED")
    .get();
 
  // It is much faster to store all the keywords you want to process
  // and then make the changes all at once. This takes advantage
  // of the batch processing behind the scenes.
  var toPause = [];
  while (kwIter.hasNext()) {
    var kw = kwIter.next();
    toPause.push(kw);
    // This is to make sure you see things during the preview
    // When you run it for real, you can remove this clause to
    // increase speed.
    if(AdWordsApp.getExecutionInfo().isPreview() &&
       AdWordsApp.getExecutionInfo().getRemainingTime() < 10) {
      break;
    }
  }
  
  // Now go through each one and pause them.
  for(var i in toPause) {
    toPause[i].pause();
    //Or you could use toPause[i].remove(); to delete the keyword altogether
  }
  
  // Sent an email to notify you of the changes
  MailApp.sendEmail(TO_NOTIFY, 
                    "AdWords Script Paused "+toPause.length+" Keywords.", 
                    "Your AdWords Script paused "+toPause.length+" keywords.");
}