0

just wondering if there is a script to import data from google trends into a google sheet. Basically, I would like to trigger such script daily to know the rising trends for a given topic and I am not sure if there is such solution available.

Else, is there any solution to perform this task?

Many thanks!

Stefano
  • 169
  • 6
  • 16

1 Answers1

0

You may refer with this sample code snippet on how to use Google Apps Script for querying Google trends. For example, this function read input from the spreadsheet and sanitize it, then call up queryGoogleTrends to perform actual query and finally display the actual result:

function startQuery() {
  sheet = SpreadsheetApp.getActiveSpreadsheet();

  // start the query
  var result = buildQueryString(sheet.getRangeByName("q").getValue(),
    sheet.getRangeByName("cat").getValue(),
    sheet.getRangeByName("geo").getValue(),
    sheet.getRangeByName("gprop").getValue(),
    sheet.getRangeByName("cmpt").getValue(),
    sheet.getRangeByName("date").getValue()
                    );

  // display the resulting link in a cell
  sheet.getRangeByName("Query_Result").setValue(result).setBackground("yellow");

  var csv_result = generateCsvDownload(sheet.getRangeByName("q").getValue(),
    sheet.getRangeByName("cat").getValue(),
    sheet.getRangeByName("geo").getValue(),
    sheet.getRangeByName("gprop").getValue(),
    sheet.getRangeByName("cmpt").getValue(),
    sheet.getRangeByName("date").getValue()
                    );

sheet.getRangeByName("CSV_Download_Link").setValue(csv_result).setBackground("yellow");

}
abielita
  • 13,147
  • 2
  • 17
  • 59
  • thank you for your answer, I just ran your suggested code, it just created link instead of actual data, can you please guide me on this? –  Oct 29 '22 at 04:58