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

Wednesday, October 30, 2013

Disable Ads and Keywords For Out of Stock Items

UPDATE 2016-01-26: In response to some common issues, this script has been updated to include some enhancements. Please see the change log notes for v1.2.

As a follow up to my questions about cool scripts for Black Friday / Cyber Monday, today I put together a script to run through your urls and check if the item is out of stock on the website. If it is, we will pause the AdGroup.

This script has some of the same elements of my script on checking for broken links in your account, but it actually pulls the html source of each page and searches for a configurable string that lets it know when it is out of stock.

Let's walk through an example. I love some of the quirky gifts I find on ModCloth.com. But like any online store, some items go out of stock. Here is one I found while testing this script.
In order to get this script to work, I need to find out what is different about the page when it goes out of stock. If I right click and view the page source, and search for the work "stock", I can see a few different places where it is used. One of them is the following that says "in_stock":false.
That looks promising. I check on an in stock item and sure enough, "in_stock":true is on that page.

Alright, so now I know what text I need to use to fill in the OUT_OF_STOCK_TEXT variable in my code. Now each site is going to be a little different, so I have a simple script that uses the same url logic as the complete script that you can use for testing.

Once you find some HTML text in the source of the landing page that identifies if an item is out of stock, you should be good to go on the full script. There are a few other options in the script that allow you to enable or disable various url manipulations in the script. And remember, this will pause only the Ads or Keywords that link to the page with the out of stock item.

Thanks,
Russ

Thursday, April 18, 2013

Pause or Enable Campaigns, Keywords or Ads on a Specific Date

UPDATE 2013-12-13: Added the ability to work on Ads as well.

I've seen some questions posted around the forums asking about enabling or pausing keywords on a given day. It is pretty simple to do using labels and scripts. The following script will run through your account and look for keywords labeled with "Pause on " or "Enable on " and perform that action. If you would like to just use dates, you can set the two prefix values to be empty strings (""). The format of the date is YYYY-MM-DD (2013-05-01).

Thanks,
Russ

/**************************************************
* Pause or Enable Campaigns, Keywords or Ads on a Given Date
* Version 1.2
* Changelog v1.2 - Added ability to pause Campaigns
* Changelog v1.1 - Added ability to run on Ads
* Created By: Russ Savage
* FreeAdWordsScripts.com
**************************************************/
var ENTITY = 'Keyword'; //or Ad or Campaign
var PAUSE_PREFIX = "Pause on "; //look for labels "Pause on 2013-04-11"
var ENABLE_PREFIX = "Enable on "; //look for labels "Enable on 2013-04-11"

  
function main() {
  var todayStr = Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), "yyyy-MM-dd");
  var pauseStr = PAUSE_PREFIX+todayStr;
  var enableStr = ENABLE_PREFIX+todayStr;
  Logger.log("Looking for labels: " + [pauseStr,enableStr].join(' and '));
   
  var labelsArray = buildLabelArray(pauseStr,enableStr);
   
  if(labelsArray.length > 0) { 
    var labelsStr = "['" + labelsArray.join("','") + "']";
    var entityIter;
    if(ENTITY === 'Keyword') {
      entityIter = AdWordsApp.keywords().withCondition("LabelNames CONTAINS_ANY "+labelsStr).get();
    } else if(ENTITY === 'Ad') {
      entityIter = AdWordsApp.ads().withCondition("LabelNames CONTAINS_ANY "+labelsStr).get();
    } else if(ENTITY === 'Campaign') {
      entityIter = AdWordsApp.campaigns().withCondition("LabelNames CONTAINS_ANY "+labelsStr).get();
    } else {
      throw 'Invaid ENTITY type. Should be Campaign, Keyword or Ad. ENTITY:'+ENTITY;
    }
     
    while(entityIter.hasNext()) {
      var entity = entityIter.next();
      pauseEntity(entity, pauseStr);
      enableEntity(entity, enableStr);
    }
  }
}
 
//Helper function to build a list of labels in the account
function buildLabelArray(pauseStr,enableStr) {
  var labelsArray = [];
  try {
    var labelIter = AdWordsApp.labels().withCondition("Name IN ['"+pauseStr+"','"+enableStr+"']").get();
    while(labelIter.hasNext()) {
      labelsArray.push(labelIter.next().getName());
    }
    return labelsArray;
  } catch(e) {
    Logger.log(e);
  }
  return [];
}
 
//Helper function to pause entities
function pauseEntity(entity, pauseStr) {
  var labelIter = entity.labels().withCondition("Name = '"+pauseStr+"'").get();
  if(labelIter.hasNext()) {
    entity.pause();
    entity.removeLabel(pauseStr);
  }
}
 
//Helper function to enable entities
function enableEntity(entity, enableStr) {
  var labelIter = entity.labels().withCondition("Name = '"+enableStr+"'").get();
  if(labelIter.hasNext()) {
    entity.enable();
    entity.removeLabel(enableStr);
  }
}

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

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.");
}