AdWords
4.8K members online now
4.8K members online now
Get started with AdWords - learn the basics to get set up for success
Guide Me
star_border
Reply

Ad customizers script modification

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

I am working on Ad customizers script, which is available here: https://developers.google.com/adwords/scripts/docs/solutions/customizer

I would like to add 1 more column in order to specify the color of the flower. Does anyone have any idea of

what changes should be done in the code in order to do that?

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Dionysiοs Z
September 2015

Re: Ad customizers script modification

Top Contributor
# 2
Top Contributor

Hi @Dionysiοs Z the flowerByName variable is built from the rows of the spreadsheet in the section that's titled "What data to use".  This part of the script "opens" the spreadsheet then reads all the rows and columns, with limits set in this line:

 

var data = sheet.getRange(2, 1, sheet.getMaxRows() - 1, 3).getValues();

This line is retrieving data (cell values) from row 2, column 1 (the first 2 numbers), down to the last row (the getMaxRows() -1 bit), and across to column 3 (the last number).  So, to add another column, all you have to do is change this last number from a 3 to a 4 and the cell values in that last column will be read in.

 

Once they're read in, you also need to add them to the variable itself.  This is done in the lines:

 

for (var i = 0; i < data.length; i++) {
   
if (data[i][0]) {
     
var flower = {
        name
: data[i][0],
        quantity
: parseFloat(data[i][1]),
        price
: data[i][2]
     
};

Here "i" is a counter from 0 to the number of rows in the sheet.  So, data[i][0], for the first loop, is the first cell in the first column, which in the example spreadsheet is "Red Roses".  For each row, the second number for the "data" variable is the column, so 0 is the name, 1 is the quantity and 2 is the price.  To add your extra column you'll need to add another line directly after the one that begins "price:".  First, put a comma at the end of the price line, then add the next line formatted as follows:

 

colour: data[i][3]

 

and that should do it! 

 

Anywhere you see the "flower" variable being used (for example, flower.name), you can now use flower.colour.

 

Let us know how you get on.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Dionysiοs Z
September 2015

Re: Ad customizers script modification

Top Contributor
# 2
Top Contributor

Hi @Dionysiοs Z the flowerByName variable is built from the rows of the spreadsheet in the section that's titled "What data to use".  This part of the script "opens" the spreadsheet then reads all the rows and columns, with limits set in this line:

 

var data = sheet.getRange(2, 1, sheet.getMaxRows() - 1, 3).getValues();

This line is retrieving data (cell values) from row 2, column 1 (the first 2 numbers), down to the last row (the getMaxRows() -1 bit), and across to column 3 (the last number).  So, to add another column, all you have to do is change this last number from a 3 to a 4 and the cell values in that last column will be read in.

 

Once they're read in, you also need to add them to the variable itself.  This is done in the lines:

 

for (var i = 0; i < data.length; i++) {
   
if (data[i][0]) {
     
var flower = {
        name
: data[i][0],
        quantity
: parseFloat(data[i][1]),
        price
: data[i][2]
     
};

Here "i" is a counter from 0 to the number of rows in the sheet.  So, data[i][0], for the first loop, is the first cell in the first column, which in the example spreadsheet is "Red Roses".  For each row, the second number for the "data" variable is the column, so 0 is the name, 1 is the quantity and 2 is the price.  To add your extra column you'll need to add another line directly after the one that begins "price:".  First, put a comma at the end of the price line, then add the next line formatted as follows:

 

colour: data[i][3]

 

and that should do it! 

 

Anywhere you see the "flower" variable being used (for example, flower.name), you can now use flower.colour.

 

Let us know how you get on.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Ad customizers script modification

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi @Jon_Gritton and Thank you for your reply! It was much more detailed than I was expecting!
It does seem to work!

Re: Ad customizers script modification

Top Contributor
# 4
Top Contributor

No problem @Dionysiοs Z, when I have time I like to try and explain the "why" as well as the "how" Smiley Happy

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits