User Tools

Site Tools


automatic_negatives
// You can use this approach when you have only minimal processing to
// perform in each of your client accounts.
 
function main(){
 
  // Select the accounts to be processed. You can process up to 50 accounts.
  var accountSelector = MccApp.accounts()
   .withCondition("Impressions > 100")
   .withCondition("Name CONTAINS 'SEARCH'")
   .forDateRange("LAST_30_DAYS")
   .withLimit(50);
 
  // Process the account in parallel. The callback method is optional.
  accountSelector.executeInParallel('processAccount', 'allFinished');
}
 
    // Select the accounts to be processed & the time frame
 
    var account = AdWordsApp.currentAccount();
    var accountName = account.getName();
      Logger.log('%s',accountName);
      MccApp.select(account);
 
      var campaignIterator = AdWordsApp.campaigns()
      .withCondition("Name CONTAINS '{e}'")
      .get();
 
 
      while (campaignIterator.hasNext()) {
        var campaign = campaignIterator.next();
 
 
        var keywordIterator = campaign.keywords()
        .withCondition('Impressions > 5')
        .forDateRange('LAST_30_DAYS')
        .get();
 
        while (keywordIterator.hasNext()) { 
          var keyword = keywordIterator.next();
 
          Logger.log("Campaign: " + campaign.getName() + " - Exact Keyword: " + keyword.getText());          
          var exact_campaign_name = campaign.getName();
          var broad_campaign_name = exact_campaign_name.replace("{e}","{b}");
          var broad_campaign_iterator = AdWordsApp.campaigns()
             .withCondition("Name = "+ "'" + broad_campaign_name + "'" + "")
             .get();
          while (broad_campaign_iterator.hasNext()) {
           var broad_campaign=broad_campaign_iterator.next();
           var negativeKeyword = keyword.getText();
           broad_campaign.createNegativeKeyword(negativeKeyword);
           Logger.log("Campaign: " + broad_campaign + " - Negative: " + negativeKeyword);
          }
          }
}
automatic_negatives.txt · Last modified: 2015/07/28 15:11 by vincenzo