1

To keep analyse and track of the demand within the tourism industry I am using Google Trends very often. The problem is it is a lot of work that we have to do manually. The current process is:

  • Go to Google Trends
  • Fill in search query, change filter
  • Download .csv
  • Upload to a Google sheet
  • Change data to columns
  • Add a formula
  • Create a graph

It would be wonderful if it was / is possible to preform a part of this process automatically on a weekly basis for one or multiple search terms. In another post I've found this script but I constantly get a error.

TypeError: Cannot read property 'getValue' of nullDetails

or

TypeError: Cannot read property 'getValue' of null (line 45, file "Code")

How can I implement this script in my google sheet (I've already added it in Google scrips and the menu button is there) and what kind of data do I have to add in the sheet itself?

UPDATE: Link to spreadsheet https://docs.google.com/spreadsheets/d/1ElTr2UsBaZdZse6-LcD3inST-Sp5vOHOZQSKESpmDcM/edit#gid=0

Hope that some can help me :) Thanks!

Kind regards, Sami

Sami Chouchane
  • 195
  • 1
  • 11
  • Did you try to adjust the code you shared to your specific scenario? The errors indicate that you haven't defined the variables right and they contain null values. For example, the code you shared might have a sheet with the name `nullDetails` but your file does not have a sheet with that name. I would advice you to take line by line the example you shared and try to adjust it to your own file. Then, edit your question to add the code you tried and maybe share a sample copy of your spreadsheet file or a couple of screenshots to help isolate the issues. – Marios Oct 12 '20 at 15:02
  • Is the script you are using a [bounded Google Sheet script](https://developers.google.com/apps-script/guides/bound)? If not, you are getting those errors because you are using ```SpreadsheetApp.getActiveSpreadsheet();``` which only will work for bounded scripts. If that is the case you could replace that for ```SpreadsheetApp.openByUrl('YOUR SPREDSHEET URL').getSheetByName('SHEET NAME');``` which will get your desired sheet in your desired Spreadsheet. – Mateo Randwolf Oct 13 '20 at 07:58
  • 1
    Thanks both of you! I will try to change the script to my needs. I've already added the columns in the spreadsheet but it is still not working. @MateoRandwolf I've added the script within the Google Sheet itself (so via script editior). So it should be a bounded script right? I was also thinking that it didn't used the active spreadsheet but I just tried it via openByURL (and Sheet Name) (+ link on edidable) but it is still not working. Could it also be something with the characters that have been used like: "text" or ==> 'text', in this script? [i've added the spreadsheet link in the post] – Sami Chouchane Oct 13 '20 at 08:43
  • Are you intending to use [named ranges](https://support.google.com/docs/answer/63175?co=GENIE.Platform%3DDesktop&hl=en) or do you just want to retrive the values under the headers of ``q``,```cat```, etc ? I think you are trying to do the second option, let me know what you want :D – Mateo Randwolf Oct 15 '20 at 09:21
  • Hi @MateoRandwolf, I'm sorry for the late reply but yes, I'm looking for the values... :) – Sami Chouchane Oct 25 '20 at 07:34

0 Answers0