Skip to content

Free AdWords Script: Manage Cross Campaign Negatives

Share Button

I can’t stand building out cross campaign negative keywords, it’s time consuming, fiddly work. ¬†Unfortunately it’s a necessary component of success.

A sample campaign would look like this:Home Loans Campaign Structure

Failing to add the negative keywords to the broad and phrase campaigns/ad groups could end up with the incorrect keyword matching a user query and lead sub optimal bid behavior occurring.

When you’re adding dozens or hundreds of new terms to your accounts each day, correctly stacking the negatives can rapidly become a pain, so I developed the script below to quickly add the negatives for you.

The script will also create a log item every time it identifies a keyword that’s missing from your account, for example, if you were currently bidding on “home loans” but your account was missing [home loans].

Because this script only adds negatives it should be safe to run daily or when ever you add new terms to your account.

To use the code, replace the Phrase/Broad campaign designators at the top of the script

function main() {
  
  //BROAD CAMPAIGN DEFINITION
  var broadDef = 'BROAD'
  //PHRASE CAMPAIGN DEFINITION
  var phraseDef = 'PHRASE'
  
  var keywords = AdWordsApp.keywords()
      .withCondition("Status = ENABLED")
      .withCondition("CampaignStatus = ENABLED")
      .withCondition("AdGroupStatus = ENABLED")
      .withCondition("KeywordMatchType = BROAD")
      .withCondition("CampaignName CONTAINS_IGNORE_CASE '"+broadDef+"'")
      .get();
  
  while (keywords.hasNext()) {
    var myKeyword = keywords.next();
    var myKeywordText = myKeyword.getText().replace(/\+/g,' ').trim();
    myKeywordText = myKeywordText.replace(/\s\s/g,' ').trim();
    var thisAdGroup = myKeyword.getAdGroup();
    thisAdGroup.createNegativeKeyword("\""+myKeywordText+"\"");
    thisAdGroup.createNegativeKeyword("["+myKeywordText+"]");
    var checkKeyword = AdWordsApp.keywords()
        .withCondition("KeywordMatchType = PHRASE")
        .withCondition("Text = '"+myKeywordText+"'")
        .get();
    if(checkKeyword.totalNumEntities() == 0){
      Logger.log(myKeywordText +" - PHRASE missing from account");
    }
    var checkKeyword = AdWordsApp.keywords()
        .withCondition("KeywordMatchType = EXACT")
        .withCondition("Text = '"+myKeywordText+"'")
        .get();
    if(checkKeyword.totalNumEntities() == 0){
      Logger.log(myKeywordText +" - EXACT missing from account");
    }
    
  }
  
  var keywords = AdWordsApp.keywords()
      .withCondition("Status = ENABLED")
      .withCondition("CampaignStatus = ENABLED")
      .withCondition("AdGroupStatus = ENABLED")
      .withCondition("KeywordMatchType = PHRASE")
      .withCondition("CampaignName CONTAINS_IGNORE_CASE '"+phraseDef+"'")
      .get();
  
  while (keywords.hasNext()) {
    var myKeyword = keywords.next();
    var myKeywordText = myKeyword.getText().replace(/\"/g,' ').trim();
    var thisAdGroup = myKeyword.getAdGroup();
    thisAdGroup.createNegativeKeyword("["+myKeywordText+"]");
    
    var checkKeyword = AdWordsApp.keywords()
        .withCondition("KeywordMatchType = EXACT")
        .withCondition("Text = '"+myKeywordText+"'")
        .get();
    if(checkKeyword.totalNumEntities() == 0){
      Logger.log(myKeywordText +" - EXACT missing from account");
    }
    
  }
  
}
Published inAdWords Scripts

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *