Parsing error. Please check your selector. (file Code.gs, line 11)

46 views
Skip to first unread message

Rating Point

unread,
Sep 8, 2021, 6:23:23 AM9/8/21
to Google Ads Scripts Forum
Getting this error when I run this script. Can anyone help?


var period = 'LAST_7_DAYS';
function main() {
var periodString = '';

if(period) {
periodString = "DURING " + period;
Logger.log(periodString);
} else {
Logger.log('DURING ALL TIME');
}
var report = AdWordsApp.report("SELECT Domain, Clicks, " +
"FROM AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT " +
periodString);

var rows = report.rows();
var excludePlacementArray = ['gta', 'фиксики', 'детский', 'свинка пеппа', 'а4', 'dota', 'minecraft', 'resheb', 'referat', 'igry','igra', 'igri', 'game', 'flash', 'apk', 'android', 'mp3', 'fb2', 'dating', 'goroskop', 'astro', 'film', 'video', 'movie', 'book', 'download', 'torrent', 'kino', 'radio', 'weather', 'pesni', 'chords', 'anekdot', 'zodiak', 'minusovk', 'knig', 'recept', 'recipe', 'spongebob', 'barbie', 'skyrim', 'ferma', 'dom2', 'mafia', 'gadani', 'mario', 'epub', '2048', 'dendy', 'sega', 'zuma', 'aforizm', 'citat', 'pdf', 'simulat', 'mods', 'play', 'spintires', 'spin-tires'];

while (rows.hasNext()) {
var row = rows.next();
var placement = row['Domain'];
if (containsAny(placement.toString(), exclude) && (row['ConvertedClicks'] < 1)) {
excludePlacementArray[excludePlacementArray.length] = placement.toString();
}

}

addNegativeKeywordToCampaign(excludePlacementArray);

}

function containsAny(str, substrings) {
for (var i = 0; i != substrings.length; i++) {
var substring = substrings[i];
if ((str.indexOf(substring) != - 1) && (str.indexOf('mobileapp::') == - 1)) {
return substring;
}
}
return null;
}

function addNegativeKeywordToCampaign(negativePlacements) {
var campaignIterator = AdWordsApp.campaigns().withCondition("LabelNames CONTAINS_ANY ['PlacementCleaner']").get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();

negativePlacements.forEach(function(entry) {
excludePlacement = campaign.display().newPlacementBuilder();
excludePlacement.withUrl(entry.toString()).exclude();
Logger.log(entry.toString() + ' - Excluded');
});
}
}

Google Ads Scripts Forum Advisor

unread,
Sep 8, 2021, 10:12:08 PM9/8/21
to adwords...@googlegroups.com
Hi, 

Thanks for reaching out. Harry here, from the Google Ads Scripts Team.

Can you try the report query below instead or remove the extra comma (,) after the Clicks field in your script's query? For further details on AWQL, please see Reporting Basics - AdWords API.
SELECT Domain, Clicks FROM AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT
Kindly try and let me know how it goes.

Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2NSL4e:ref

Rating Point

unread,
Sep 9, 2021, 4:33:59 AM9/9/21
to Google Ads Scripts Forum
Actually the error also exits. Could you please send correct code?
Perhaps I am entering incorrectly?

четверг, 9 сентября 2021 г. в 08:12:08 UTC+6, adsscripts:

Google Ads Scripts Forum Advisor

unread,
Sep 9, 2021, 10:07:46 PM9/9/21
to adwords...@googlegroups.com
Hi,

Kindly provide your CID and script's name so I can take a closer look which you send here or privately via the 'reply to author option'. Note that you may need to join the Google Group for you to use this option. If this option is not available at your end still, you may send it through our email (googleadsscr...@google.com) instead.
 
As a side note, if you're having trouble receiving private replies from us, please check your Spam folder. Additionally, please add the 'From address' on that email to your contact list to ensure we aren't flagged as Spam in future messages. If you don't see a message from us in your Spam folder, please email us directly at googleadsscr...@google.com referring to this forum thread.
 
Looking forward to your reply.

Rating Point

unread,
Sep 13, 2021, 1:25:01 AM9/13/21
to Google Ads Scripts Forum

Hey,

I'm a newbie here, tell me where to join the group? link please?
I wrote my request to this address.
Anything else you want from me?
пятница, 10 сентября 2021 г. в 08:07:46 UTC+6, adsscripts:
Hi,

Kindly provide your CID and script's name so I can take a closer look which you send here or privately via the 'reply to author option'. Note that you may need to join the Google Group for you to use this option. If this option is not available at your end still, you may send it through our email (googleadsscripts-support@google.com) instead.
 
As a side note, if you're having trouble receiving private replies from us, please check your Spam folder. Additionally, please add the 'From address' on that email to your contact list to ensure we aren't flagged as Spam in future messages. If you don't see a message from us in your Spam folder, please email us directly at googleadsscripts-support@google.com referring to this forum thread.

 
Looking forward to your reply.

Google Ads Scripts Forum Advisor

unread,
Sep 13, 2021, 4:22:14 AM9/13/21
to adwords...@googlegroups.com
Hi,

Thanks for coming back. You can refer to this link for further details on joining Google Groups but I am confirming that your separate email went through our end. Now, checking further on your script, it does not seem you are encountering the same parsing error but adding a whitespace after the Clicks field should do the trick. Moreover, I would recommend building the whole the query first in a variable, log the built query to verify and supply it to the report method. It would be something like the following:
  var query = "SELECT Domain, Clicks" +
    "FROM AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT " +
    periodString;
  Logger.log(query);
  var report = AdWordsApp.report(query);
Let me know if you need more help.

Rating Point

unread,
Sep 14, 2021, 12:26:16 AM9/14/21
to Google Ads Scripts Forum on behalf of adsscripts
Hi, Harry 

I did everything that you said. 
And now the error comes out:ReferenceError: "periodString" is not defined. (file Code.gs, line 1)
could you help to show the correct script so that I can copy and paste, I am not a programmer and for me this is all difficult.

var query = "SELECT Domain, Clicks" +
    "FROM AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT " +
    periodString;
  Logger.log(query);
  var report = AdWordsApp.report(query);

пн, 13 сент. 2021 г. в 14:22, Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com>:
--
-- 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-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/t6DaQ000000000000000000000000000000000000000000000QZD5WW00P-Gs8HG6RoaEIwK4G-Jo1Q%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
Sep 14, 2021, 4:11:54 AM9/14/21
to adwords...@googlegroups.com
Hello,

Pasting the sample code I provided onto your script won't address the errors you are encountering as it is merely a reference on how you can validate your report query before using it in the report method. Moreover, our team can't really fix scripts for users or write code for you and can only guide you with implementing Google Ads scripts. I highly recommend reaching out to a developer in your team or a colleague in this regard. Nevertheless, I am going to give an exception this time and attaching the updated script here for you.

Let me know if you need anything else.
script.txt

Rating Point

unread,
Sep 14, 2021, 9:16:43 AM9/14/21
to Google Ads Scripts Forum on behalf of adsscripts
Thank you so much, you helped us a lot.

вт, 14 сент. 2021 г. в 14:11, Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com>:
--
-- 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-scrip...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages