QS script

161 views
Skip to first unread message

Edoardo

unread,
Feb 21, 2020, 9:50:43 AM2/21/20
to Google Ads Scripts Forum
Hi I've being trying to build my own QS script (don't have any experience with java unfortunately), any help would be much appreciated.
here's the script:

function main () {
var report = AdsApp.report(
    "SELECT Criteria, CampaignName, AdGroupName, Clicks, Impressions, Cost, Conversions, QualityScore, SearchPredictedCtr, CreativeQualityScore, PostClickQualityScore, CriteriaDestinationUrl" +
    "FROM   KEYWORDS_PERFORMANCE_REPORT " +
    "WHERE Status IN [ENABLED, PAUSED] and HasQualityScore='TRUE' " +
    "AND CampaignName DOES_NOT_CONTAIN_IGNORE_CASE 'Brand'" +
    "AND Impressions > 25" +
    "AND Clicks > 5" +
    "AND QualityScore <= '6'" +    
    "DURING LAST_30_DAYS");

var rows = report.rows();
while (rows.hasNext()) {
    var row = rows.next();
    var query = row["Query"];
    var impressions = row["Impressions"];
    var Clicks = row["Clicks"];
    var QualityScore = row["QualityScore"];
 }
}


It's giving as error ---- why?
Parsing error. Please check your selector. (file Code.gs, line 7)

Google Ads Scripts Forum Advisor

unread,
Feb 21, 2020, 11:41:55 AM2/21/20
to adwords-scripts+apn2wqeao9zb5afh...@googlegroups.com, adwords-scripts+apn2wqeao9zb5afh...@googlegroups.co, adwords...@googlegroups.com
Hi Edoardo,

Your query is a series of concatenated strings, so you should leave a space at the end of each string. Otherwise, the strings will be joined incorrectly. I recommend changing your query to following:


    "SELECT Criteria, CampaignName, AdGroupName, Clicks, Impressions, Cost, Conversions, QualityScore, SearchPredictedCtr, CreativeQualityScore, PostClickQualityScore, CriteriaDestinationUrl " +
    "FROM   KEYWORDS_PERFORMANCE_REPORT " +
    "WHERE Status IN [ENABLED, PAUSED] and HasQualityScore='TRUE' " +
    "AND CampaignName DOES_NOT_CONTAIN_IGNORE_CASE 'Brand' " +
    "AND Impressions > 25 " +
    "AND Clicks > 5 " +
    "AND QualityScore <= '6' " +    
    "DURING LAST_30_DAYS");

Please let me know if you have any other questions.

Regards,
Matt
Google Ads Scripts Team


ref:_00D1U1174p._5001UV1nx0:ref

Edoardo

unread,
Feb 21, 2020, 12:03:06 PM2/21/20
to Google Ads Scripts Forum
Thanks for the reply Matt, I'm not sure I understand the issue... I did try adding spaces at the end of each string but nothing chanced.
The log is flagging an error at line 7 which is // var report = AdsApp.report(

Google Ads Scripts Forum Advisor

unread,
Feb 21, 2020, 3:12:01 PM2/21/20
to adwords-scripts+apn2wqeao9zb5afh...@googlegroups.com, adwords-scripts+apn2wqeao9zb5afh...@googlegroups.co, adwords...@googlegroups.com
Hi Edoardo,

This query is running fine for me. Though the error states line 7, it is referring to the full query. Could you please provide me your CID and script name so I can verify that the query is structured properly in your account?

Thanks,

Edoardo

unread,
Feb 24, 2020, 4:59:16 AM2/24/20
to Google Ads Scripts Forum
Thanks for looking into it Mat:
825-917-5969
Name: "QS Edo"

Google Ads Scripts Forum Advisor

unread,
Feb 24, 2020, 12:46:30 PM2/24/20
to adwords-scripts+apn2wqeao9zb5afh...@googlegroups.com, adwords-scripts+apn2wqeao9zb5afh...@googlegroups.co, adwords...@googlegroups.com
Hi Edoardo,

I saw in your script that the query does not have the correct spacing. Please copy the query below that has the correct spacing:

var report = AdsApp.report(

    "SELECT Criteria, CampaignName, AdGroupName, Clicks, Impressions, Cost, Conversions, QualityScore, SearchPredictedCtr, CreativeQualityScore, PostClickQualityScore, CriteriaDestinationUrl " +
    "FROM KEYWORDS_PERFORMANCE_REPORT " +
    "WHERE Status IN [ENABLED, PAUSED] and HasQualityScore='TRUE' " +
    "AND CampaignName DOES_NOT_CONTAIN_IGNORE_CASE 'Brand' " +
    "AND Impressions > 25 " +
    "AND Clicks > 5 " +
    "AND QualityScore <= '6' " +    
    "DURING LAST_30_DAYS");

Regards,

Edoardo

unread,
Feb 25, 2020, 4:45:57 AM2/25/20
to Google Ads Scripts Forum
You were right indeed Matt and now the script is running.
One last thing, how can I make the script returning in a g-sheet all selected entities? 

Google Ads Scripts Forum Advisor

unread,
Feb 25, 2020, 3:23:17 PM2/25/20
to adwords-scripts+apn2wqeao9zb5afh...@googlegroups.com, adwords-scripts+apn2wqeao9zb5afh...@googlegroups.co, adwords...@googlegroups.com
Hi Edoardo,

I recommend using the exportToSheet method from the report class. Here is a sample code that creates a spreadsheet, outputs the report to the sheet, and then logs the URL -- be sure to replace your report with the sample report given:

   var spreadsheet = SpreadsheetApp.create("Report output");
   var report = AdsApp.report("SELECT Clicks, Impressions, AverageCpc, HourOfDay " +
       "FROM ACCOUNT_PERFORMANCE_REPORT " +
       "DURING LAST_MONTH");
   report.exportToSheet(spreadsheet.getActiveSheet());
   Logger.log("Report available at " + spreadsheet.getUrl());

Edoardo

unread,
Feb 28, 2020, 11:33:11 AM2/28/20
to Google Ads Scripts Forum
Simply amazing! Thank you!
Reply all
Reply to author
Forward
0 new messages