Parsing Error. Please check your selector. (Line 9)

29 views
Skip to first unread message

santiag...@gmail.com

unread,
Jan 12, 2018, 4:10:10 PM1/12/18
to AdWords Scripts Forum
Hello people! I have problems with script that I found in the forum, what I added adding some conditions to the first part. But tells me that I'm using a parameter wrong. Could you tell me what the problem is? I already probe changing the order of things, and checking the syntax, but I can not find the error. Thanks in advance!

// Cantidad mínima de clicks para considerar estadísticamente probado un término de búsqueda
var CLICKS_MINIMOS =100;
// Costo por conversión máximo que toleramos de un término de búsqueda (en moneda local de la cuenta)
var COSTO_POR_CONVERSION_MAXIMO = 50;
// Cantidad minima de conversiones para agregar como palabra clave.
var CONVERSIONES = 2;

function main(){
  var report = AdWordsApp.report(
    "SELECT Query,Clicks,Cost,CostPerConversion,Conversions,CampaignId,AdGroupId "+
    "FROM SEARCH_QUERY_PERFORMANCE_REPORT "+
    "WHERE "+
          "Clicks >"+ CLICKS_MINIMOS +
          "AND CostPerConversion < "+ COSTO_POR_CONVERSION_MAXIMO +
          "AND Conversions >" + CONVERSIONES + 
      " DURING LAST_MONTH"); // podemos poner el período que queramos
  var rows = report.rows();
// creamos las variables para las palabras negativas y positivas
var PalabrasNegativas ={};
  var PalabrasPositivas ={};
  var allAdGroupIds ={}
  // Evaluamos cada uno de los términos de búsqueda para decidir
  // cuáles ignorar o agregar a nuestras listas.
  while(rows.hasNext()){
    var row = rows.next();
// comenzamos evaluando si una palabra se agrega como negativa.
    if(parseFloat(row['Conversions'])= 0){
      addToMultiMap(negativeKeywords, row['AdGroupId'], row['Query']);
      allAdGroupIds[row['AdGroupId']]=true;
// ahora, evaluamos si una palabra se agrega como positiva.
    }else if(parseFloat(row['CostPerConversion'])< COSTO_POR_CONVERSION_MAXIMO){
      addToMultiMap(positiveKeywords, row['AdGroupId'], row['Query']);
      allAdGroupIds[row['AdGroupId']]=true;
    }
  }
// Toma los nombres de los grupos de anuncios de nuestra campaña y los convierte en un "array", es decir, en una lista ordenada de valores (para ir agregando palabras clave a cada uno)
  var adGroupIdList = [];
  for (var adGroupId in allAdGroupIds) {
    adGroupIdList.push(adGroupId);
  }
 
// ¡Lo que todos estábamos esperando! Copiar a los grupos todas las palabras claves positivas y negativas:
  var adGroups = AdWordsApp.adGroups().withIds(adGroupIdList).get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    if (negativeKeywords[adGroup.getId()]) {
      for (var i = 0; i < negativeKeywords[adGroup.getId()].length; i++) {
// ¡Atención con la línea que viene! Agrega la palabra negativa con concordancia exacta. Más abajo, explicaremos cómo modificar esto.        adGroup.createNegativeKeyword('[' + negativeKeywords[adGroup.getId()][i] + ']');
      }
    }
    if (positiveKeywords[adGroup.getId()]) {
      for (var i = 0; i < positiveKeywords[adGroup.getId()].length; i++) {
// Aquí se agregan las palabras positivas. En este ejemplo, la palabra clave se agrega con concordancia exacta. Sin embargo, podemos no solamente agregar la palabra con otro tipo de concordancia (reemplazando los corchetes por comillas para concordancia de frase o borrándolos para tener concordancia amplia) sino que también podemos copiar esta línea y pegarla abajo modificada para agregar la misma palabra clave con varias concordancias distintas.
        adGroup.createKeyword('[' + positiveKeywords[adGroup.getId()][i] + ']');
      }
    }
  }
}
 
function addToMultiMap(map, key, value) {
  if (!map[key]) {
    map[key] = [];
  }
  map[key].push(value);
}


Adrian Catambay (AdWords Scripts Team)

unread,
Jan 14, 2018, 10:41:07 PM1/14/18
to AdWords Scripts Forum
Hello,

I have tested the script you provided and the problem is in your report query. Since you concatenated variables in your query, you should add a space prior to the AND keyword to separate it from the concatenated variable. Please change your report query to the following:

var report = AdWordsApp.report(
   
"SELECT Query,Clicks,Cost,CostPerConversion,Conversions,CampaignId,AdGroupId " +
   
"FROM SEARCH_QUERY_PERFORMANCE_REPORT " +

   
"WHERE Clicks > " + CLICKS_MINIMOS +

   
" AND CostPerConversion < " + COSTO_POR_CONVERSION_MAXIMO +
   
" AND Conversions > " + CONVERSIONES +
   
" DURING LAST_MONTH");

For debugging purposes, you may try logging your query string with the Logger.log() function to check if you have properly constructed it.

If this error still persists, please Reply privately to author with your CID and script name so I can further check this issue.

Thanks,
Adrian
AdWords Scripts Team

santiag...@gmail.com

unread,
Jan 15, 2018, 9:26:40 AM1/15/18
to AdWords Scripts Forum
Thank you very much! The script no longer shows me the error, the preview runs without any problem. Now, it only remains to prove if it works ... It is one last time to have to apply it directly on the campaign, without being able to prove it before ...
Reply all
Reply to author
Forward
0 new messages