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!

4 Comments

  1. Alex October 19th, 2016

    This works until you have a string containing both double and single quotes.
    Why not just escape the strings:

    function quote( str ){
    return ‘”‘ + str.replace(/”/g, ‘\\”‘ ) + ‘”‘;
    }

    function main(){
    var campaignName = ” just a’ test\” “;
    AdWordsApp
    .keywords()
    .withCondition( ‘CampaignName = ‘ + quote( campaignName ) );
    }

  2. John Doherty March 13th, 2018

    Hi there!

    I’m working with an AdWords script from here: https://searchengineland.com/script-automates-adding-adwords-data-google-spreadsheet-277724

    And keep receiving a parsing error on line 103.

    I’m wondering where exactly in that script I would place your mentioned fix? (Sorry, not much of a dev.)

    Thanks!
    John

  3. Marthijn August 10th, 2018

    Many thanks for this 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.

  4. Andreas September 3rd, 2018

    This tip is awesome!

    Fixed so many errors :)

Leave a Comment

Carl Paradiso
Carl joined 3Q Digital in August 2012 after a yoga-teaching, soul-searching and travel-filled sabbatical. Since joining 3Q, he’s led the team that has built and supported a cloud-native set of services that have scaled with the company as it has grown from 40 to 280 employees and 2 to 9 offices. He’s continually working to refine infrastructure, services, security, and privacy to meet the needs of larger clients and a more complex marketing ecosystem while maintaining the nimble and collaborative environment that younger workforces demand. Prior to joining 3Q, Carl spent 13 years at the various incarnations of Diamond Management and Technology Consultants, where he directed IT infrastructure, security, and support throughout the company’s entire lifecycle of startup, going public, and expanding internationally organically and through acquisitions.