Google Trends API Work-around – The Right Way

Google does not have an easy way to grab data from google/trends, I think they had an API awhile ago but this has long been deprecated. There are handful of posts online that show you how to make calls and get the raw data but this will get you banned very quickly.

What I ended up doing is embedding the  script, that google provides, in a view and embedding ruby into the script and escaping the js. This way it will be dynamically updated depending on what value I am pulling from my database.

It looks like this:

<script type="text/javascript" src='//<%=escape_javascript @profile.firstname %>+<%=escape_javascript @profile.lastname %>&content=1&cid=GEO_MAP_0_0&export=5&w=400&h=430'></script>

This is great solution that will not get you banned and allow you to show data.
There is one major downside to this solution. You’re stuck with the google design and logo.

Leave a Reply