Let’s fix this “Parsing error. Please check your selector. (file Code.gs, line XX)”

“Parsing error. Please check your selector.” 

When you are fiddling with Google Ads scripts and try to run a script that involves AWQL queries and selectors, there is a BIG chance you run into this error.

Errors like this can have many causes and before you know it you are searching all around the web for hours, without having any clue what for the life you is causing the issue.

Here’s a list of potential causes and recommendations for you to fix the issue and move on with your day. It almost certainly has to do with one of the issues below.

 

AWQL is a SQL-like language for performing queries to retrieve data from different Report types. The syntax of AWQL queries can be difficult to grasp if you are not familiar with coding, and even when you are it’s very easy to make mistakes.  But don’t worry, this post should help you solve the most common issues even when you are not a programmer.

Note: this list is work in progress. If none of the solutions is a fix for your situation, please let me know and I will try to help. (Send a copy of the script and screenshot of your error message to nils[at]nilsrooijmans.com).

 

1 – Missing Spaces between components

The number one cause of parsing errors in AWQL queries is the absence of spaces, meaning that there is no space between the different components of the AWQL statement. It’s very easy to make this mistake, especially when you concatenate different parts of the query over multiple lines using the ‘+’ operator.

Be sure to check the following:
– is there a space after SELECT?
– is there a space before and after FROM?
– is there a space before and after WHERE?
– is there a space before and after your AND?
– is there a space before  DURING?

Example with spacing errors:

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 "FROM CAMPAIGN_PERFORMANCE_REPORT" +
 "WHERE Conversions < 1" +
 "AND Cost > 100" +
 "DURINGTHIS_MONTH";
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 " FROM CAMPAIGN_PERFORMANCE_REPORT" +
 " WHERE Conversions < 1" +
 " AND Cost > 100" +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

 

2 – Incorrect use of quotes

The second most common cause of parsing errors is the incorrect use of quotes.

The names (or parts of the names) of campaigns and ad groups should be consistently used and between either single or double-quotes. When you are surrounding your AWQL statement by double-quotes the (part of) names should be surrounded by single quotes, and vice versa.

Let’s say we have a campaign naming structure that contains the name of the geolocation we are targetting and want to filter campaigns targetting Amsterdam. Now pay attention to the details in the following examples.

Example 2.1: Incorrect use (no quotes):

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 " FROM CAMPAIGN_PERFORMANCE_REPORT" +
 " WHERE CampaignName CONTAINS Amsterdam" +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 " FROM CAMPAIGN_PERFORMANCE_REPORT" +
 " WHERE CampaignName CONTAINS 'Amsterdam'" +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

 

Example 2.2: Incorrect use (double-quotes where single quotes are needed):

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 " FROM CAMPAIGN_PERFORMANCE_REPORT" +
 " WHERE CampaignName CONTAINS "Amsterdam"" +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = 
 "SELECT Date, CampaignName, Cost, Conversions" +
 " FROM CAMPAIGN_PERFORMANCE_REPORT" +
 " WHERE CampaignName CONTAINS 'Amsterdam'" +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

 

Example 2.3 : Incorrect use (single quotes where double quotes are needed):

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS 'Amsterdam'' +
 ' DURING THIS_MONTH';
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING THIS_MONTH';
var report = AdsApp.report(awqlQuery);

 

Example 2.4: Inconsistent use of quotes (single quotes and double-quotes are mixed up):

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam'' +
 " DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING THIS_MONTH';
var report = AdsApp.report(awqlQuery);

 

Another more complicated example of where the use of quotes might go wrong is where you have single or double quotes in the campaign name itself. In our example with campaign names containing the names of geo-locations, this might happen when a certain city name contains an apostrophe (ie: Martha’s Vineyard).
This might result in an error message like this: “One of the conditions in the query is invalid.”
The simplest solution is to remove any quotes from the campaign name. If that is not an option you need to “escape the strings” containing quotes.  If you need help, contact me and I will try to help. (Send a copy of the script and screenshot of your error message to nils[at]nilsrooijmans.com)

 

3 – Incorrectly defined period for DURING clause

Most AWQL queries end with a DURING statement like this :

... DURING THIS_MONTH";

The part that says THIS_MONTH is called the DateRangeLiteral and can be replaced by any of the following values  (note, these are CASE SENSITIVE):

TODAY | YESTERDAY | LAST_7_DAYS | LAST_WEEK | LAST_BUSINESS_WEEK | THIS_MONTH | LAST_MONTH | LAST_14_DAYS | LAST_30_DAYS | THIS_WEEK_SUN_TODAY | THIS_WEEK_MON_TODAY | LAST_WEEK_SUN_SAT

Or, you can use custom periods that use a start date and an end date formatted like this:

YYYYMMDD,  YYYYMMDD

An example of where this might go wrong:

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING 2020-1-1, 2020-1-21';
var report = AdsApp.report(awqlQuery);

Correct use :

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING 20200101, 20200121';
var report = AdsApp.report(awqlQuery);

 

Also, please note that the custom date range requires the use of 2 digits for both the month and the day, so even if the number for either the month or day is below ten, it still requires 2 digits (in that case, simply put a zero before the number):

This will throw an error:

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING 2020901, 20211030';
var report = AdsApp.report(awqlQuery);

Correct use :

var awqlQuery = 
 'SELECT Date, CampaignName, Cost, Conversions' +
 ' FROM CAMPAIGN_PERFORMANCE_REPORT' +
 ' WHERE CampaignName CONTAINS "Amsterdam"' +
 ' DURING 20200901, 20211030';
var report = AdsApp.report(awqlQuery);

 

 

So, if you are using a DURING statement in your query, be sure to check that DURING is surrounded by spaces and your DateRangeLiteral  uses correct values as listed below, in ALL_CAPS.

Which brings us to…

 

4 – Capitalization

Note that report names and the queried fields (column names) in AWQL queries are case sensitive.
Here’s an example that contains 4 types of common capitalization errors:

var awqlQuery = "SELECT Date, Campaignid, Cost, conversions FROM campaign_performance_report DURING THIS_Month";
var report = AdsApp.report(awqlQuery);

The correct one is:

var awqlQuery = "SELECT Date, CampaignId, Cost, Conversions FROM CAMPAIGN_PERFORMANCE_REPORT DURING THIS_MONTH";
var report = AdsApp.report(awqlQuery);

So be sure to check capitalization in all your column names, source names, and date ranges.

 


AAAaargh! I’m still getting this damn error message!

If you have checked for all of the issues described above and still get the “Please check your selector parsing error”, fear not.

I’m here to help. Contact me and I will try to help. (Send a copy of the script and screenshot of your error message to nils[at]nilsrooijmans.com)

 


 

Join thousands of PPC geeks who already have access:

If the button above isn’t working for you, you can sign up here to get access.