This is the subhead for the blog post

At 3Q Digital, we use AdWords scripts for a variety of admin and monitoring tasks, such as changing ad group names in bulk, discovering broken destination URLs, and alerting us to campaigns that are consuming their budget faster than planned.  We’ve built scripts from scratch as well as made use of the amazing libraries of free scripts that are available.

One problem that comes up frequently is that scripts will fail suddenly with a  “Parsing error. Please check your selector” error after running successfully many times.  

ii_14a1afe0e506cd21

This error means that the parser (which reads and interprets your instructions and the data) can no longer determine where the selection strings begin and end.  This happens because a string contains an apostrophe, which is the same as a single quote, and now the selection no longer has paired quotes.

For example, here’s a selector condition that works fine until the variable containing the desired headline contains an apostrophe:

.withCondition(“Headline = ‘” + desiredHeadline +”‘”)

The double quotes tell the parser to use the text within them, and that text includes an apostrophe, which is the same as a single quote, and a pair of them are already being used to delineate the text in the variable for the condition statement.  This works fine with variables that don’t contain single quotes, because the resulting condition looks like this:

.withCondition(Headline = ‘Amazing Deals’)    // VALID 

However, when the headline variable itself contains an apostrophe, it fails because now there are three single quotes, which should only exist in pairs, and that confuses the parser:

.withCondition(Headline = ‘Today’s Deals’)   // INVALID 

To fix this, just switch the double and single quotes (they are equivalent as long as they are paired correctly), using the single quotes to enclose the double quotes:

.withCondition(‘Headline = “‘ + desiredHeadline +'”‘)

Now the

.withCondition(Headline = “Today’s Deals”)   // VALID 

Conversely, if you have double quotes in your variable text strings, then you’ll have to reverse this approach, so that you have the strings enclosed in single quotes. 

Good luck!