I think I got the functionality to work correctly but its not returning all the keywords that it should be.
I manually pulled an all time performance report for all our keywords and ran another keyword report for yesterday, and ended up with a combined report that contains all time cost, conversions, and yesterday's avg pos and the MaxCPC by keyword.
There are 39 keywords in the combined report that match the criteria below. But the script is only finding 1 keyword of the 39. Any idea why it wouldnt find the other 38? Is the code below not working as I'm intending it to? Is it not looking through all keywords in our account? I'm surprised that it completes in only 27 seconds.
Have a look:
function lowerKeywordBids() {
var keywordsToLower1 = AdWordsApp.keywords()
.withCondition('Status = ENABLED')
.withCondition('Cost >=50')
.withCondition('ConvertedClicks = 0')
.withCondition('MaxCpc >= 0.20')
.orderBy('Impressions DESC')
.forDateRange('ALL_TIME')
.get();
var keywordsToLower2 = AdWordsApp.keywords()
.withCondition('AveragePosition < 3')
.withCondition('Status = ENABLED')
.orderBy('Impressions DESC')
.forDateRange('YESTERDAY')
.get();
Logger.log('Script|Date|Campaign|Ad Group|Keyword|Previous Bid|New Bid');
while (keywordsToLower1.hasNext()) {
var keyword1 = keywordsToLower1.next();
var keyword1_2 = keyword1.getText();
while (keywordsToLower2.hasNext()) {
var keyword2 = keywordsToLower2.next();
var keyword2_2 =keyword2.getText();
if(keyword2_2==keyword1_2) {
var prevBid = keyword2.getMaxCpc();
var newBid = keyword2.getMaxCpc() * (1 - BID_ADJUSTMENT_COEFFICIENT)
newBid = Math.round(newBid * 100) / 100
Logger.log('Lower Keyword Bids'+'|'+mm+'/'+dd+'/'+yyyy+'|'+keyword2.getCampaign()+'|'+keyword2.getAdGroup()+'|'+keyword2.getText()+'|'+prevBid+'|'+newBid);
keyword2.setMaxCpc(keyword2.getMaxCpc() * (1 - BID_ADJUSTMENT_COEFFICIENT));
} //if
} //while
} //while
} //function