Google adwords script if statements segund fields and inserting an id

318 views
Skip to first unread message

Aitor Udabe

unread,
Aug 5, 2016, 3:44:31 AM8/5/16
to AdWords Scripts Forum

Hello again.

He came to me further questions .

I google adwords script in if statements can perform once spat upon full report on the sheet can do the following :

if the gclid = a column X (we have the gclid customer )

I add in that row from column A dats the report.

That is to seek the customer gclid comparing it with the gclid the report first and if one just put in that row example row 25 add fields that gclid the report fields .

Not if I have expressed myself well?

Thanks

Tyler Sidell (AdWords Scripts Team)

unread,
Aug 5, 2016, 4:55:03 PM8/5/16
to AdWords Scripts Forum
Hi Aitor,

I believe that something got lost in translation.  My understanding is that you are trying to set up an if-statement based on the results of gclid in a report.  If so, you can get started with the following code:
function main() {
 
var report = AdWordsApp.report("SELECT GclId from CLICK_PERFORMANCE_REPORT DURING YESTERDAY").rows();
   
 
while (report.hasNext()) {
   
var row = report.next();
   
var gclid = row["GclId"];
   
Logger.log(gclid);
   
if (gclid = 'REPLACE WITH GCLID') {
     
// run process
   
}
 
}
}

Thanks,
Tyler Sidell
AdWords Scripts Team

Aitor Udabe

unread,
Aug 16, 2016, 7:14:33 AM8/16/16
to AdWords Scripts Forum
Hi Tyler,

Forgive the tardanz was on vacation, and went back to work .

What I want to do is the following :

I dump the data sheet where I have already user data and gclid obtained by php.

What quieor do is that when you can dump the dump report filtering , although I think that we 'll have to perform once this report dump and then make a script in the spreadsheet you?

Because I can not compare a gclid with an identifier of a column of the sheet?

Anash Oommen

unread,
Aug 16, 2016, 3:07:48 PM8/16/16
to AdWords Scripts Forum
Hi Aitor,

You could use the SpreadsheetApp API to work with spreadsheets. So assuming you already have the data in the spreadsheet with one column as gClid, the logic goes something like this.

var SPREADSHEET_URL = "SPREADSHEET_URL_HERE";

var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getSheetByName("MySheet");

for (var i = 0; i < sheet.getMaxRows(); i++) {
 
// Assuming you have 5 cells per column, the first column is gClid,
 
// second column is cost and you want to process cost where gClid
 
// matches some condition.

 
var data = sheet.getRange(i, 1, 1, 5).getValues();
 
 
var gClid = data[0][0]; // Column A
 
var cost = data[0][1]; // Column B


 
// do your stuff
 
...
}

sheet
.getRange(outputRow, outputColumn).setValue(someprocessedvalue);

Hope this helps. Let me know if you have more questions.

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

On Friday, August 5, 2016 at 3:44:31 AM UTC-4, Aitor Udabe wrote:
Message has been deleted
Message has been deleted
Message has been deleted

Aitor Udabe

unread,
Aug 17, 2016, 6:08:48 AM8/17/16
to AdWords Scripts Forum
Hi Anash thanks for your respond


I have found the solution to my problem.

I share code in case someone needs it .

function myFunction() { 
function Lento() { 
var h1 = SpreadsheetApp.getActive().getSheetByName('Hoja 1'); 
var h2 = SpreadsheetApp.getActive().getSheetByName('Hoja 2'); 
var rowsh1 = h1.getDataRange(); 
var valuesh1 = rowsh1.getValues(); 
var numColsh1 = rowsh1.getNumColumns(); 
var numRowsh1 = rowsh1.getNumRows(); 
var rowsh2 = h2.getDataRange(); 
var valuesh2 = rowsh2.getValues(); 
var numColsh2 = rowsh2.getNumColumns(); 
var numRowsh2 = rowsh2.getNumRows(); 
var idusuario = []; 
var identificador = []; 
//recorremos fila a fila y cogemos los datos de la hoja1 
for (var r=1; r<valuesh2.length; r++) { 
var rowh2 = valuesh2[r], 
nombre = rowh2[1], 
email = rowh2[2], 
telefono = rowh2[3], 
mensaje = rowh2[4], 
urllanding = rowh2[5], 
fechausuario = rowh2[6]; 
idusuario[r] = rowh2[0];//Guardamos los gclid del usuario en un array 

//recorremos fila a fila y cogemos los datos de la hoja2 
for (var r=1; r<valuesh1.length; r++) { 
var rowh1 = valuesh1[r], 
palabraclave = rowh1[1], 
ciudad = rowh1[2], 
fecha = rowh1[4], 
pais = rowh1[5]; 
identificador[r] = rowh1[0];//Guardamos los gclid en un array 



for (var i=identificador.length-1;i>0;i--) 
var encontrado = false; 
for (var y=1;y<idusuario.length;y++) 

if (identificador[i]== null || idusuario[y] == null) continue; 
if (identificador[i] == idusuario[y]) 
Logger.log("encontramos el " + i); 
Logger.log("identificador " + identificador[i]); 
Logger.log("idusuario " + idusuario[y]); 
encontrado = true; 
break; 

if (!encontrado) { 

Logger.log("eliminamos el " + i); 
h1.deleteRow(i+1); 


Lento(); 
}

Thank 
Reply all
Reply to author
Forward
0 new messages