AdWords
4.9K members online now
4.9K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Quality Score Script Errors

Badged Google Partner
# 1
Badged Google Partner
Hello,
 
I've been running the Quality Score script from FreeAdWordsScripts.com successfully for several weeks and now I'm getting a system error.
 
This is the error I'm receiving
Using date range: LAST_30_DAYS
We're sorry, a server error occurred. Please wait a bit and try again. (line 163)
 
This is line 163
var row = reportIter.next();
 
Does someone know how I can fix this error?
 
Thanks
2 Expert replyverified_user

Re: Quality Score Script Errors

Top Contributor
# 2
Top Contributor

Hi @Sevelia J I've seen this error a number of times and although it says it's server error, in all the cases I've seen it's actually where you're asking something of the script that cannot be done (there's a subtle difference).

 

Programs don't break without there being a change somewhere.  That change can be in the language itself (Google does update and deprecate their scripting language with annoying frequency), with the referenced AdWords Account or with any external resource (such as a spreadsheet used for reporting) but there has to have been a change somewhere.

 

Does this script report conversion data?  One recent change to reports in the API removed the "Conversions" column and replaced it with "ConvertedClicks".  Look at the script and see if there is a call to a report - this will usually be in its own function and may be something like "CAMPAIGN_PERFORMANCE_REPORT".  If you can see a request for "Conversions", that's probably the cause.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Quality Score Script Errors

Badged Google Partner
# 3
Badged Google Partner

Hi @Jon_Gritton,

 

Thanks for replying. I've check the script and it's not requesting conversion data. It's requesting the quality score for the last 30 days at the keyword, adgroup, campaign and account level.

 

I've pasted the script below for reference & highlighted in red the line that has the error.  I'm not sure what caused the script to break.

 

Thanks for your help.

 

Sevelia

 


var DECIMALS = 4; //this will give you 4 decimal places of accuracy
//You can set this to anything in this list: TODAY, YESTERDAY, LAST_7_DAYS,
// THIS_WEEK_SUN_TODAY, THIS_WEEK_MON_TODAY, LAST_WEEK, LAST_14_DAYS,
// LAST_30_DAYS, LAST_BUSINESS_WEEK, LAST_WEEK_SUN_SAT, THIS_MONTH
var DATE_RANGE = 'LAST_30_DAYS';
// Or you can set this to any number of days you like. it overrides the DATE_RANGE set above
var LAST_N_DAYS = 0;

var CSV_FILE_PREFIX = ""; //Set this if you want to write to a set of CSV files, one for each account level.
var SPREADSHEET_URL = ""; //Set this if you have the url of a spreadsheet you want to update
var SPREADSHEET_NAME = ""; //Set this if you want to write to the name of a spreadsheet instead

function main() {
var isCSV = (CSV_FILE_PREFIX !== "");
var allData = getKeywordsReport();
var tabs = ['Account','Campaign','AdGroup','Keyword'];
for(var i in tabs) {
var tab = tabs[i];
var dataToWrite = [];
var cols = getCols(tab);
var rowKeys = getRowKeys(tab,Object.keys(allData));
for(var x in rowKeys) {
var rowArray = [];
var key = rowKeys[x];
var row = allData[key];
for(var y in cols) {
rowArray.push(row[cols[y]]);
}
dataToWrite.push(rowArray);
}
if(isCSV) {
writeDataToCSV(tab,dataToWrite);
} else {
writeDataToSpreadsheet(tab,dataToWrite);
}
}
}

function getRowKeys(tab,allKeys) {
return allKeys.filter(function(e) { return (e.indexOf(tab) >= 0); });
}

function getCols(tab) {
return {
'Account' : ['Date','Account','ImpsWeightedQS'],
'Campaign': ['Date','Account','Campaign','ImpsWeightedQS'],
'AdGroup' : ['Date','Account','Campaign','AdGroup','ImpsWeightedQS'],
'Keyword' : ['Date','Account','Campaign','AdGroup','Keyword','QS','ImpsWeightedQS']
}[tab];
}

// Super fast spreadsheet insertion
function writeDataToSpreadsheet(tab,toWrite) {
//This is where i am going to store all my data
var spreadsheet;
if(SPREADSHEET_NAME) {
var fileIter = DriveApp.getFilesByName(SPREADSHEET_NAME);
if(fileIter.hasNext()) {
var file = fileIter.next();
spreadsheet = SpreadsheetApp.openById(file.getId());
} else {
spreadsheet = SpreadsheetApp.create(SPREADSHEET_NAME);
}
} else if(SPREADSHEET_URL) {
spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
} else {
throw 'You need to set at least one of the SPREADSHEET_URL or SPREADSHEET_NAME variables.';
}
var sheet = spreadsheet.getSheetByName(tab);
if(!sheet) {
sheet = spreadsheet.insertSheet(tab);
sheet.appendRow(getCols(tab));
}

var lastRow = sheet.getLastRow();
var numRows = sheet.getMaxRows();
if((numRows-lastRow) < toWrite.length) {
sheet.insertRowsAfter((lastRow == 0) ? 1 : lastRow,toWrite.length-numRows+lastRow);
}
var range = sheet.getRange(lastRow+1,1,toWrite.length,toWrite[0].length);
range.setValues(toWrite);
}

function writeDataToCSV(tab,toWrite) {
if(!toWrite) { return; }
var fileName = CSV_FILE_PREFIX + '_' + tab + '.csv';
var file;
var fileIter = DriveApp.getFilesByName(fileName);
if(fileIter.hasNext()) {
file = fileIter.next();
} else {
file = DriveApp.createFile(fileName, formatCsvRow(getCols(tab)));
}
var fileData = file.getBlob().getDataAsString();
for(var i in toWrite) {
fileData += formatCsvRow(toWrite[i]);
}
file.setContent(fileData);
return file.getUrl();
}

function formatCsvRow(row) {
for(var i in row) {
if(row[i].toString().indexOf('"') == 0) {
row[i] = '""'+row[i]+'""';
}
if(row[i].toString().indexOf('+') == 0) {
row[i] = "'"+row[i];
}
if(row[i].toString().indexOf(',') >= 0 &&
row[i].toString().indexOf('"""') != 0)
{
row[i] = ('"'+row[i]+'"');
}
}
return row.join(',')+'\n';
}

function getKeywordsReport() {
var theDate = DATE_RANGE;
if(LAST_N_DAYS != 0) {
theDate = getDateDaysAgo(LAST_N_DAYS)+','+getDateDaysAgo(1);
}
Logger.log('Using date range: '+theDate);
var OPTIONS = { includeZeroImpressions : true };
var cols = ['ExternalCustomerId',
'CampaignId','CampaignName',
'AdGroupId','AdGroupName',
'Id','KeywordText','KeywordMatchType',
'IsNegative','Impressions', 'QualityScore'];
var report = 'KEYWORDS_PERFORMANCE_REPORT';
var query = ['select',cols.join(','),'from',report,
'where AdNetworkType1 = SEARCH',
'and CampaignStatus = ENABLED',
'and AdGroupStatus = ENABLED',
'and Status = ENABLED',
'during',theDate].join(' ');
var results = {};
var reportIter = AdWordsApp.report(query, OPTIONS).rows();
while(reportIter.hasNext()) {
var row = reportIter.next();
if(row.IsNegative == true || row.IsNegative === 'true') { continue; }
loadHashEntry('Account:'+row.ExternalCustomerId,row,results);
loadHashEntry('Campaign:'+row.CampaignId,row,results);
loadHashEntry('AdGroup:'+[row.CampaignId,row.AdGroupId].join('-'),row,results);
loadHashEntry('Keyword:'+[row.CampaignId,row.AdGroupId,row.Id].join('-'),row,results);
}
var dateStr = Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), 'yyyy-MM-dd');
for(var i in results) {
results[i]['Date'] = dateStr;
results[i]['ImpsWeightedQS'] = (results[i]['totalImps'] === 0) ? 0 : round(results[i]['ImpsWeightedQS']/results[i]['totalImps']);
}
return results;
}

function loadHashEntry(key,row,results) {
if(!results[key]) {
results[key] = {
QS : 0,
ImpsWeightedQS : 0,
totalImps : 0,
Account : null,
Campaign : null,
AdGroup : null,
Keyword : null
};
}
results[key].QS = parseFloat(row.QualityScore);
results[key].ImpsWeightedQS += (parseFloat(row.QualityScore)*parseFloat(row.Impressions));
results[key].totalImps += parseFloat(row.Impressions);
results[key].Account = row.ExternalCustomerId;
results[key].Campaign = row.CampaignName;
results[key].AdGroup = row.AdGroupName;
results[key].Keyword = (row.KeywordMatchType === 'Exact') ? '['+row.KeywordText+']' :
(row.KeywordMatchType === 'Phrase') ? '"'+row.KeywordText+'"' : row.KeywordText;
}

//A helper function to return the number of days ago.
function getDateDaysAgo(days) {
var thePast = new Date();
thePast.setDate(thePast.getDate() - days);
return Utilities.formatDate(thePast, AdWordsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
}

function round(val) {
var divisor = Math.pow(10,DECIMALS);
return Math.round(val*divisor)/divisor;
}

 

Re: Quality Score Script Errors

Top Contributor
# 4
Top Contributor

Hi @Sevelia J well I can't see any obvious problem with the script, though it does look like the report row iterator that's causing the problem I can't see why.  The query is formed OK, all the fields appear to be valid according to the API reference and the query returns true for a number of rows.

 

I've got scripts myself running the KEYWORDS_PERFORMANCE_REPORT and they're still working, so it's not that.

 

I still think something has changed but rather than me trying to interpret the code, you'd probably do better just to get in touch with Russell himself.  A brief search on Google should find his contact details.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Quality Score Script Errors

Badged Google Partner
# 5
Badged Google Partner
Thanks Jon! I've reached out to @russellsavage.

Sevelia

Re: Quality Score Script Errors

[ Edited ]
Top Contributor
# 6
Top Contributor

Re: Quality Score Script Errors

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Hi Sevelia, we had the same error.
You can make some changes in the script in the getKeywordsReport function, then it should work.
You have to delete 'IsNegative' in var cols, then you add 'AND IsNegative = false', in var query (before 'during',theDate].join(' ')). And finally you delete the row if(row.IsNegative == true || row.IsNegative === 'true') { continue; } (it's in the while loop).
I hope that can help you.
Denise

Re: Quality Score Script Errors

Top Contributor
# 8
Top Contributor

Hi Denise, where did you get that solution?  Do you know why that works?

 

If IsNegative has been deprecated as a field in the report, you shouldn't be able to still test it in the query (so the change from including it as a column to checking it's value shouldn't make any difference).

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Quality Score Script Errors

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Hi Jon, I found it here: https://groups.google.com/forum/#!topic/adwords-scripts/3hYIqiIW_C8
And I don't know why IsNegative as a column causes the error.

Denise

Re: Quality Score Script Errors

Top Contributor
# 10
Top Contributor

Thanks @Denise W weird.  I'll try and find out what the root of the problem is.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits