Extract site data on ad google ads

36 views
Skip to first unread message

Nathan Alfa

unread,
Sep 25, 2019, 4:08:01 AM9/25/19
to Google Ads Scripts Forum

Hello I would like to know if it is possible to make a Google ads ad with data from Google SpreadSheets ?

Basically, I have a website with a welcome page that shows the number of customers on the site, and I'd like to extract that data and make an AdWords ad with the number of customers.


I manage to import the data from the website on a google spreadsheets but after I do not know how to put it on a google ads script to create an ad automatically.


If you have an idea, or you know how to do it, I'm a thank you in advance !


Google Ads Scripts Forum Advisor

unread,
Sep 25, 2019, 6:35:31 AM9/25/19
to adwords...@googlegroups.com
Hi Nathan,

Thanks for posting your concern.

With regard to your question on how to get the information of ads from the spreadsheet, we have SpreadsheetApp sample codes that you can use for this instance. Moving forward, we also have sample codes for creating different types of ads. You can supply the information that you retrieve from the spreadsheet to the necessary fields of specific ads that you are going to create.

You can specify what type of ad you want to create so that I can provide further details about it on how it will be done.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5001UHHson:ref

Nathan Alfa

unread,
Sep 25, 2019, 10:18:01 AM9/25/19
to Google Ads Scripts Forum
Hello and thank you for your quick return,
I would like to create an ad Expanded text ad and connect cell A1 of a spreadsheets on HeadLinePart2?

thank you in advance !

Google Ads Scripts Forum Advisor

unread,
Sep 25, 2019, 11:07:14 PM9/25/19
to adwords...@googlegroups.com
Hi Nathan,

Thanks for providing further details.

If you want to get the data of the headline part 2 from a specific cell of the spreadsheet, you can specify the cell address of this cell in the getRange() method of SpreadsheetApp.

In your case, you can refer to the sample code below to have an idea with the provided suggestion.
function main() {
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'INSERT_SHEET_NAME_HERE';

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);

  var cell = sheet.getRange('A1');
  var cellValue = cell.getValue();
  Logger.log(cellValue);
}


Furthermore, for you convenience, you can refer to the sample script below if you want to create multiple expanded text ads.
function main() {
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'INSERT_SHEET_NAME_HERE';

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);

  var range = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn());//Get the data of the spreadsheet from second row to the last row
  var values = range.getValues();

  for (var i = 0; i < sheet.getLastRow()-1; i++) {
      var adGroupSelector = AdsApp
         .adGroups().withIds(INSERT_ADGROUP_ID_HERE);//Put the ad group ID where you want to create expanded text ads

      var adGroupIterator = adGroupSelector.get();
      while (adGroupIterator.hasNext()) {
        var adGroup = adGroupIterator.next();

        adGroup.newAd().expandedTextAdBuilder()
            .withHeadlinePart1(values[i][0])
            .withHeadlinePart2(values[i][1])
            .withDescription(values[i][2])
            .withPath1(values[i][3])
            .withPath2(values[i][4])
            .withFinalUrl(values[i][5])
            .build();
      }
  }
}


If you are going to use the sample script, I would suggest to format the spreadsheet based on the screenshot below. The script is constructed based on the format of the spreadsheet below.
spreadsheetsample

Lastly, this script is working on my end. However, I would recommend to preview this script to see if it will execute successfully and if the simulated results are fine.

Let me know if you have further questions.

Nathan Alfa

unread,
Sep 26, 2019, 4:55:08 AM9/26/19
to Google Ads Scripts Forum

Hello and thank you for this information.

I copied pasted the script, I made the same spreadsheet as you.

However, I still have an error:
TypeError: Cannot find function map in object 78570126124. (file Code.gs, line 13)

For line 13 I tried with these two lines but I still have the error:
     
.adGroups().withIds(78570126124);//Put the ad group ID where you want to create expanded text ads
.adGroups().withIds("78570126124");//Put the ad group ID where you want to create expanded text ads


Thank you in advance !




Google Ads Scripts Forum Advisor

unread,
Sep 26, 2019, 5:46:39 AM9/26/19
to adwords...@googlegroups.com
Hi Nathan,

Thanks for the reply.

The IDs that you will put inside the withIds() method should be enclosed in [] (square bracket).

You can preview the script with the provided suggestion. Let me know how it goes after trying it.

Nathan Alfa

unread,
Sep 26, 2019, 5:49:14 AM9/26/19
to Google Ads Scripts Forum
Thank you !
Now it's working !

Nathan Alfa

unread,
Sep 26, 2019, 10:16:21 AM9/26/19
to Google Ads Scripts Forum
I have a new problem,

I modify and adapt your code to add more elements however I have an error with the Ad ID

I wanted to put in a cell of my spreadsheet all Ad ID but it only works for the preview

error: One of the conditions in the query is invalid. (file Code.gs, line 23)

code :

function main() {
  var SPREADSHEET_URL = '[HIDDEN]';
  var SHEET_NAME = '[HIDDER]';

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);

  var range = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn());
  var values = range.getValues();
  var nb = 0
  
  for (var i = 0; i < sheet.getLastRow()-1; i++) {
      Logger.log(values[i][8]);
      nb = values[i][8];
      var adGroupSelector = AdsApp
         .adGroups().withIds([nb]);
    
      var adGroupIterator = adGroupSelector.get();
      while (adGroupIterator.hasNext()) {
        var adGroup = adGroupIterator.next();

        adGroup.newAd().expandedTextAdBuilder()
            .withHeadlinePart1(values[i][0])
            .withHeadlinePart2(values[i][1])
            .withHeadlinePart3(values[i][2])
            .withDescription1(values[i][3])
            .withDescription2(values[i][4])
            .withPath1(values[i][5])
            .withPath2(values[i][6])
            .withFinalUrl(values[i][7])
            .build();
      }
  }
}


Thank for the help !



Le jeudi 26 septembre 2019 11:46:39 UTC+2, adsscriptsforumadvisor a écrit :

KARSSON PATRiK

unread,
Sep 26, 2019, 10:03:11 PM9/26/19
to Google Ads Scripts Forum

KARSSON PATRiK

unread,
Sep 26, 2019, 10:04:14 PM9/26/19
to Google Ads Scripts Forum


On Wednesday, 25 September 2019 10:08:01 UTC+2, Nathan Alfa wrote:

Google Ads Scripts Forum Advisor

unread,
Sep 26, 2019, 10:25:00 PM9/26/19
to adwords...@googlegroups.com
Hi Nathan,

So that I can further investigate, could you provide the customer ID and the name of the script where you encountered the error via Reply privately to author option? Also, please provide an access to the spreadsheet that the script is using so I can check it as well.

ARIEL AB ARRABIS AM

unread,
Sep 29, 2019, 1:47:13 PM9/29/19
to Nathan Alfa via Google Ads Scripts Forum, Google Ads Scripts Forum
ARIES 

--
-- 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/c6624999-1bcf-444c-ada1-f9258bce5ebd%40googlegroups.com.


--
1905 per TRANSACTION
Reply all
Reply to author
Forward
0 new messages