<commit_before>// Version: Beta

var CONVERSION_VALUE = 50.0;
var TAG_IGNORE = 'Script Ignore';
var CAMPAIGN_INCLUDE = ''; // Only include Adgroups and keywords in Campaigns with this text string in the name

var BID_INCREMENT = 0.25;

var THRESHOLD_INCREASE = 10;    // Set this to 1 to increase bids more aggressively
var THRESHOLD_DECREASE = 1;    // Set this to 1 to decrease bids more aggressively
var THRESHOLD_SIGNIFICANT = 20; // Extra bid adjustment happens when this many conversions

var HIGH_COST = 100;    // How much is too much

var STOPLIMIT_POSITION = 1.3; // Do not increase bids at this position or better


function main() { 
  ////setAdGroupBids("ALL_TIME");
  
  Logger.log('\n***** 1 YEAR *****');  
  setAdGroupBids(LAST_YEAR(), TODAY());
  setAdGroupBids_highCost(LAST_YEAR(), TODAY());
  setKeywordBids(LAST_YEAR(), TODAY());
  setKeywordBids_highCost(LAST_YEAR(), TODAY());
  
  Logger.log('\n***** 30 DAYS *****');  
  setAdGroupBids("LAST_30_DAYS");
  setAdGroupBids_highCost("LAST_30_DAYS");
  setKeywordBids("LAST_30_DAYS");
  setKeywordBids_highCost("LAST_30_DAYS");

  Logger.log('\n***** 14 DAYS *****');  
  setAdGroupBids("LAST_14_DAYS");
  setAdGroupBids_highCost("LAST_14_DAYS");
  setKeywordBids("LAST_14_DAYS");  
  setKeywordBids_highCost("LAST_14_DAYS");

  Logger.log('\n***** 7 DAYS *****');
  setAdGroupBids("LAST_7_DAYS");
  setAdGroupBids_highCost("LAST_7_DAYS");
  setKeywordBids("LAST_7_DAYS");
  setKeywordBids_highCost("LAST_7_DAYS");
}



// ******************************************************************
// SET ADGROUP BIDS
// ******************************************************************
function setAdGroupBids(dateRange, dateRangeEnd) {
   Logger.log('\nSet Ad Group Bids, > ' + THRESHOLD_SIGNIFICANT + ' Conv : ' + dateRange);
   var adGroupIterator = GetAdGroupSelector(dateRange)
      .withCondition("ConvertedClicks > " + THRESHOLD_SIGNIFICANT)
      .get();
  
  Logger.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
  
  while (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    var stats = adGroup.getStatsFor(dateRange, dateRangeEnd);
    var conv_rate = stats.getClickConversionRate();
    var current_cpc = adGroup.bidding().getCpc();
    var max_cpc = roundDown(conv_rate * CONVERSION_VALUE);
    
    var new_cpc = max_cpc;
    if( max_cpc > current_cpc) { // Increase bids
       new_cpc = Math.min(current_cpc + BID_INCREMENT, max_cpc);
    } else if (max_cpc < current_cpc) { // Decrease bids
       new_cpc = Math.max(current_cpc - BID_INCREMENT, max_cpc);
    }

    //Logger.log('AdGroup Name: ' + adGroup.getName() + ' ConvRate:' + conv_rate + ' MaxCPC:' + max_cpc);   
    adGroup.bidding().setCpc(new_cpc);
  } 
}

// ******************************************************************
// SET ADGROUP BIDS FOR HIGH COST ADWORDS
// ******************************************************************<commit_msg>Missing dateRangeEnd for one function<commit_after>// Version: Beta

var CONVERSION_VALUE = 50.0;
var TAG_IGNORE = 'Script Ignore';
var CAMPAIGN_INCLUDE = ''; // Only include Adgroups and keywords in Campaigns with this text string in the name

var BID_INCREMENT = 0.25;

var THRESHOLD_INCREASE = 10;    // Set this to 1 to increase bids more aggressively
var THRESHOLD_DECREASE = 1;    // Set this to 1 to decrease bids more aggressively
var THRESHOLD_SIGNIFICANT = 20; // Extra bid adjustment happens when this many conversions

var HIGH_COST = 100;    // How much is too much

var STOPLIMIT_POSITION = 1.3; // Do not increase bids at this position or better


function main() { 
  ////setAdGroupBids("ALL_TIME");
  
  Logger.log('\n***** 1 YEAR *****');  
  setAdGroupBids(LAST_YEAR(), TODAY());
  setAdGroupBids_highCost(LAST_YEAR(), TODAY());
  setKeywordBids(LAST_YEAR(), TODAY());
  setKeywordBids_highCost(LAST_YEAR(), TODAY());
  
  Logger.log('\n***** 30 DAYS *****');  
  setAdGroupBids("LAST_30_DAYS");
  setAdGroupBids_highCost("LAST_30_DAYS");
  setKeywordBids("LAST_30_DAYS");
  setKeywordBids_highCost("LAST_30_DAYS");

  Logger.log('\n***** 14 DAYS *****');  
  setAdGroupBids("LAST_14_DAYS");
  setAdGroupBids_highCost("LAST_14_DAYS");
  setKeywordBids("LAST_14_DAYS");  
  setKeywordBids_highCost("LAST_14_DAYS");

  Logger.log('\n***** 7 DAYS *****');
  setAdGroupBids("LAST_7_DAYS");
  setAdGroupBids_highCost("LAST_7_DAYS");
  setKeywordBids("LAST_7_DAYS");
  setKeywordBids_highCost("LAST_7_DAYS");
}



// ******************************************************************
// SET ADGROUP BIDS
// ******************************************************************
function setAdGroupBids(dateRange, dateRangeEnd) {
   Logger.log('\nSet Ad Group Bids, > ' + THRESHOLD_SIGNIFICANT + ' Conv : ' + dateRange);
   var adGroupIterator = GetAdGroupSelector(dateRange, dateRangeEnd)
      .withCondition("ConvertedClicks > " + THRESHOLD_SIGNIFICANT)
      .get();
  
  Logger.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
  
  while (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    var stats = adGroup.getStatsFor(dateRange, dateRangeEnd);
    var conv_rate = stats.getClickConversionRate();
    var current_cpc = adGroup.bidding().getCpc();
    var max_cpc = roundDown(conv_rate * CONVERSION_VALUE);
    
    var new_cpc = max_cpc;
    if( max_cpc > current_cpc) { // Increase bids
       new_cpc = Math.min(current_cpc + BID_INCREMENT, max_cpc);
    } else if (max_cpc < current_cpc) { // Decrease bids
       new_cpc = Math.max(current_cpc - BID_INCREMENT, max_cpc);
    }

    //Logger.log('AdGroup Name: ' + adGroup.getName() + ' ConvRate:' + conv_rate + ' MaxCPC:' + max_cpc);   
    adGroup.bidding().setCpc(new_cpc);
  } 
}

// ******************************************************************
// SET ADGROUP BIDS FOR HIGH COST ADWORDS
// ******************************************************************
{'fraction_non_alphanumeric': 0.21402027027027026, 'fraction_numerical': 0.014864864864864866, 'mean_word_length': 4.682341650671785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92606', 'n_tokens_mistral': 2115, 'n_tokens_neox': 1972, 'n_words': 401}