AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

Adwords Script - Broad Match Modified Query Error

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi all, 

I'm having an issue with this SQR script below. Everything works great except for when pulling in the 'Broad Match Modified' keyword terms for column 'KeywordTextMatchingQuery' which all of this data is being exported out into google sheets. The error shows as a '#NAME?' error for this column due to the broad modifier '+' character in the term but when looking in the formula bar, the keyword term is actually visible. I know that a " ' " has to be appended to this broad match modified term within the script but I'm unsure on how to go about this. Any help would be great! Thanks in advance all. 

 

 

var DATE_RANGE = 'LAST_14_DAYS';
var IGNORE_EXACT = false;
var TO = ["xyz@email.com"];
var SPREADSHEET_URL = "GoogleSheetsUrlLink";

function main() {
var columns = ['AccountDescriptiveName',
'CampaignName',
'AdGroupName',
'KeywordTextMatchingQuery',
'QueryMatchTypeWithVariant',
'Query',
'Device',
'Impressions',
'Clicks',
'Cost',
'Conversions',
'AverageCpc',
'CostPerConversion',
'ConversionRate',
'Ctr'];
var columnsStr = columns.join(',') + " ";

var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();
sheet.clear();
sheet.appendRow(columns);

var reportIter = AdWordsApp.report(
'SELECT ' + columnsStr +
'FROM SEARCH_QUERY_PERFORMANCE_REPORT ' +
'DURING ' + DATE_RANGE, {
includeZeroImpressions: false
}).rows();

while(reportIter.hasNext()) {
var row = reportIter.next();
if(IGNORE_EXACT && row['QueryMatchTypeWithVariant'].indexOf('exact') >= 0) { continue; }
var rowArray = [];
for(var i in columns) {
rowArray.push(row[columns[i]]);
}
sheet.appendRow(rowArray); 
}

for(var i in TO) {
MailApp.sendEmail(TO[i], "Search Query Report Ready", SPREADSHEET_URL);
}
}

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author J_S_
July 2017

Adwords Script - Broad Match Modified Query Error

Top Contributor
# 2
Top Contributor

Hi J_S_,

In this loop:

for(var i in columns) {
rowArray.push(row[columns[i]]);
}

add logic to test value of i before the rowArray.push line. something like this:

if (i == "KeywordTextMatchingtQuery" && columns[i].substr(0,1)=="+"){

  columns[i] = "'"+columns[i];

}

 

Best of Luck!

 

Pete

 

petebardo -- Deadhead doing AdWords

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author J_S_
July 2017

Adwords Script - Broad Match Modified Query Error

Top Contributor
# 2
Top Contributor

Hi J_S_,

In this loop:

for(var i in columns) {
rowArray.push(row[columns[i]]);
}

add logic to test value of i before the rowArray.push line. something like this:

if (i == "KeywordTextMatchingtQuery" && columns[i].substr(0,1)=="+"){

  columns[i] = "'"+columns[i];

}

 

Best of Luck!

 

Pete

 

petebardo -- Deadhead doing AdWords

Adwords Script - Broad Match Modified Query Error

Explorer ✭ ✭ ✭
# 3
Explorer ✭ ✭ ✭

Hello,

 

Changing the code is one option but I would first try formatting the column as a text and then run the script. You have to format it just once, then it will work ok and show the values correctly.

 

Best regards,

 

Hana