Parsing error. Please check your selector. (line 103)

451 views
Skip to first unread message

GoCubeYourself

unread,
Mar 14, 2018, 5:04:05 AM3/14/18
to AdWords Scripts Forum
Hi everyone!

Let me start by saying I am not a developer, so please forgive my ignorance here. :)

For the attached script, I am receiving the error: Parsing error. Please check your selector. (line 103)

For the life of me, I can't figure out how to fix this and I've done an extensive online search.


Any solutions would be much appreciated!

(Note that the personal info in the lines 17-21 have been filled out correctly.)

Thanks,
John

/*
// AdWords Script: Put Data From AdWords Report In Google Sheets
// --------------------------------------------------------------
// Copyright 2017 Optmyzr Inc., All Rights Reserved
//
// This script takes a Google spreadsheet as input. Based on the column headers, data filters, and date range specified
// on this sheet, it will generate different reports.
//
// The goal is to let users create custom automatic reports with AdWords data that they can then include in an automated reporting
// tool like the one offered by Optmyzr.
//
//
// For more PPC management tools, visit www.optmyzr.com
//
*/

var DEBUG = 0; // set to 1 to get more details about what the script does while it runs; default = 0
var REPORT_SHEET_NAME = "report"; // the name of the tab where the report data should go
var SETTINGS_SHEET_NAME = "settings"; // the name of the tab where the filters and date range are specified
var SPREADSHEET_URL = "https://docs.google.com/spreadsheets/d/1dttJTb547L81XYKdTQ56LcfO9hHhbb9wm06ZY5mKhEo/edit#gid=0"; // The URL to the Google spreadsheet with your report template
var EMAIL_ADDRESSES = "exa...@example.com"; // Get notified by email at this address when a new report is ready

function main() {
 var currentSetting = new Object();
 currentSetting.ss = SPREADSHEET_URL;
 
 // Read Settings Sheet
 var settingsSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(SETTINGS_SHEET_NAME);
 var rows = settingsSheet.getDataRange();
 var numRows = rows.getNumRows();
 var numCols = rows.getNumColumns();
 var values = rows.getValues();
 var numSettingsRows = numRows - 1;
 
 var sortString = "";
 var filters = new Array();
 for(var i = 0; i < numRows; i++) {
   var row = values[i];
   var settingName = row[0];
   var settingOperator = row[1];
   var settingValue = row[2];
   var dataType = row[3];
   debug(settingName + " " + settingOperator + " " + settingValue);
   
   if(settingName.toLowerCase().indexOf("report type") != -1) {
     var reportType = settingValue;
   } else if(settingName.toLowerCase().indexOf("date range") != -1) {
     var dateRange = settingValue;
   } else if(settingName.toLowerCase().indexOf("sort order") != -1) {
     var sortDirection = dataType || "DESC";
     if(settingValue) var sortString = "ORDER BY " + settingValue + " " + sortDirection;
     var sortColumnIndex = 1;
   }else {
     if(settingOperator && settingValue) {
       if(dataType.toLowerCase().indexOf("long") != -1 || dataType.toLowerCase().indexOf("double") != -1 || dataType.toLowerCase().indexOf("money") != -1 || dataType.toLowerCase().indexOf("integer") != -1) {
         var filter =  settingName + " " + settingOperator + " " + settingValue;
       } else {
         if(settingValue.indexOf("'") != -1) {
           var filter =  settingName + " " + settingOperator + ' "' + settingValue + '"';
         } else if(settingValue.indexOf("'") != -1) {
           var filter =  settingName + " " + settingOperator + " '" + settingValue + "'";
         } else {
           var filter =  settingName + " " + settingOperator + " '" + settingValue + "'";
         }
       }
       debug("filter: " + filter)
       filters.push(filter);
     }
   }
 }
 
 
 // Process the report sheet and fill in the data
 var reportSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(REPORT_SHEET_NAME);
 var rows = reportSheet.getDataRange();
 var numRows = rows.getNumRows();
 var numCols = rows.getNumColumns();
 var values = rows.getValues();
 var numSettingsRows = numRows - 1;
 
 // Read Header Row and match names to settings
 var headerNames = new Array();
 var row = values[0];
 for(var i = 0; i < numCols; i++) {
   var value = row[i];
   headerNames.push(value);
   //debug(value);
 }
 
 
 
  if(reportType.toLowerCase().indexOf("performance") != -1) {
   var dateString = ' DURING ' + dateRange;
 } else {
   var dateString = "";
 }
 if(filters.length) {
   var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + ' WHERE ' + filters.join(" AND ") + dateString + " " + sortString;
 } else {
   var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + dateString + " " + sortString;
 }
 debug(query);
 var report = AdWordsApp.report(query);
 try {
   report.exportToSheet(reportSheet);
   var subject = "Your " + reportType + " for " + dateRange + " for " + AdWordsApp.currentAccount().getName() + " is ready";
   var body = "currentSetting.ss<br>You can now add this data to <a href='https://www.optmyzr.com'>Optmyzr</a> or another reporting system.";
   MailApp.sendEmail(EMAIL_ADDRESSES, subject, body);
   Logger.log("Your report is ready at " + currentSetting.ss);
   Logger.log("You can include this in your scheduled Optmyzr reports or another reporting tool.");
 } catch (e) {
   debug("error: " + e);
 }

}

function debug(text) {
 if(DEBUG) Logger.log(text);
}


Anthony Madrigal

unread,
Mar 14, 2018, 11:13:01 AM3/14/18
to AdWords Scripts Forum
Hi John,

You will need to select the report type you are interested from the "AdWords Data Grabber from Optmyzr" menu of your spreadsheet. Once you do that, you will need to configure what fields you are interested in and any conditions you like.

You can find more details on Step 1 of the third party script's guide.

Cheers,
Anthony
AdWords Scripts Team

Aasim Brelvi

unread,
Apr 11, 2018, 6:34:07 AM4/11/18
to AdWords Scripts Forum
Hi Anthony,

I have a similar problem mentioned above... I am also using "AdWords Data Grabber from Optmyzr' but I have a doubt into which fields i need to configure in the settings sheet for eg to get data of a particular account and for a particular campaign.. Please can you advise which field in settings sheet should be changed with a particular account name.

Thanks & Regards,
Aasim

Anthony Madrigal

unread,
Apr 11, 2018, 11:49:24 AM4/11/18
to AdWords Scripts Forum
Hi Aasim,

The script is designed to be implemented on the account level, not MCC level, so you can just apply it to the particular account you want.

Once you make a copy of the spreadsheet, you can choose the report type as Campaign Performance. From the settings sheet, you can look for the "CampaignName" row and set the field to the particular campaign you are looking for.

If you face any issues, please let me know.

Cheers,
Anthony
AdWords Scripts Team

Nenad

unread,
Feb 12, 2019, 5:19:27 PM2/12/19
to Google Ads Scripts Forum
Hi everyone!

It seems that the filters are not working in this script.

When I'm setting impressions > 0 or cost > 0 I still get data with 0 impressions or cost

Any help will be appreciated 

Thanks
Nenad

googleadsscrip...@google.com

unread,
Feb 13, 2019, 9:27:35 AM2/13/19
to Nenad via Google Ads Scripts Forum, Google Ads Scripts Forum
Hi Nenad,

Since this is an old thread, can you please create a new thread with some details? Is this only happening from this script but for simple report queries?

Regards,
Anthony
Google Ads Scripts Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/2e30c137-a186-4499-87f8-a9e75c114824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages