I want script to calculate roas and adjust bid on keyword level

412 views
Skip to first unread message

mohit.me...@tcs.com

unread,
Jan 2, 2018, 5:11:08 PM1/2/18
to AdWords Scripts Forum
I want script to calculate roas and adjust bid on keyword level .The bid is on basis of ROAS of keywords and do bid adjusment  for same 

Thea Vega (AdWords Scripts Team)

unread,
Jan 3, 2018, 2:17:15 AM1/3/18
to AdWords Scripts Forum
Hi,

Please see below sample code on how to calculate Target ROAS and set bid on a keyword level to help you get started.

function main() { 
  
  
var report = AdWordsApp.report(
    
'SELECT Id, AdGroupId, Criteria, ConversionValue, Cost ' + //You may add more columns. See this documentation for columns supported by Keywords Performance Report
    
'FROM   KEYWORDS_PERFORMANCE_REPORT ');
  
  
var rows = report.rows();
  
while (rows.hasNext()) {
    
var row = rows.next();
    
var kw = row['Criteria'];
    
var conversionValue = parseFloat(row['ConversionValue']);
    
var cost = parseFloat(row['Cost']);
    
var roas = conversionValue/cost; //See this documentation for details on how to calculate Target ROAS
    
var ids =[];
    ids
.push(row['AdGroupId'],row['Id']);
    
Logger.log("Keyword: %s | Conversion Value: %s | Cost: %s | Roas: %s",kw,conversionValue,cost,roas);

    var keyword = AdWordsApp.keywords().withIds([ids]).get().next();

    
//do something here before you call keyword.bidding().setCpc(INSERT_VALUE_HERE)
  
}
    
}

Hope this helps. I would suggest for you to Preview the script on your end to see if it fits your requirements.

Thanks,
Thea
AdWords Scripts Team



mohit.me...@tcs.com

unread,
Jan 3, 2018, 3:39:47 AM1/3/18
to AdWords Scripts Forum

This is Error i am getting as of now 
Error: Cannot retrieve the next object: iterator has reached the end. (line 19)
and am not getting and data in changes this all info reflected in logs 

Note : can you please provide script which will segregate my adgroup which have mutile ads and which has single ads in it  in spreadsheet. Rply ASAP need this urgent 

Thea Vega (AdWords Scripts Team)

unread,
Jan 3, 2018, 4:51:47 AM1/3/18
to AdWords Scripts Forum
Hi,

Could you try to update the previous code I sent with the code block below starting from line 19? Take note of the emphasized part of the code snippet below as these are the ones that need to be updated on your previous script.

    var keywordIterator = AdWordsApp.keywords().withIds([ids]).get() //line 19
   
if (keywordIterator.hasNext()) {
     
var keyword = keywordIterator.next();

     
     
//do something here before you call keyword.bidding().setCpc(INSERT_VALUE_HERE)
   
}

The update above checks if there is still a keyword to be fetched. As for data not changing, this may be due to the fact that your keywords don't have cost and conversion value (based on your logs).

If you are still facing issues after applying the solution above, please give me your CID and script name via Reply privately to author for further investigation.

For your other inquiry about spreadsheet, please create a new forum thread for better tracking of this new concern.

mohit.me...@tcs.com

unread,
Jan 4, 2018, 2:39:00 AM1/4/18
to AdWords Scripts Forum
can you please provide script which will segregate my adgroup which have mutile ads and which has single ads in it  in spreadsheet with performance data
Reply all
Reply to author
Forward
0 new messages