Is there an API for Google Trends?

A few weeks ago, we launched a new dataset into Google Clouds public dataset program: Google Trends. If youre not familiar with our datasets program, we host a variety of datasets in BigQuery and Cloud Storage for you to access and integrate into your analytics. Google pays for the storage of these datasets and provides public access to the data, e.g., via the bigquery-public-data project. You only pay for queries against the data. Plus, the first 1 TB per month is free! Even better, all of these public datasets will soon be accessible and shareable via Analytics Hub.

Show

The Google Trends dataset represents the first time were adding Google-owned Search data into the program. The Trends data allows users to measure interest in a particular topic or search term across Google Search, from around the United States, down to the city-level. You can learn more about the dataset here, and check out the Looker dashboard here! These tables are super valuable in their own right, but when you blend them with other actionable data you can unlock whole new areas of opportunity for your team. You can view and run the queries we demonstrate here.

It looks like `Spain vs Croatia` was recently trending because of the Euro Cup. This might be a great opportunity to create a new campaign and capitalize on momentum: Spain beat Croatia and is on to the next round, show your support by celebrating with some authentic Spanish ham!

Now going a bit further, if we take a look at the top rising search terms from yesterday (as of writing this on 6/30), we can see that there are a lot of names for people. But its unclear who these people are or why theyre trending. What we do know is were looking for a singer to strike up a brand deal with. More specifically, we have a great new jingle for our authentic ham and were looking for some trendy singers to bring attention to our company.

Using the Wikipedia Open API you can perform an open search for the term, for example Jamie Lynn Spears:

https://en.wikipedia.org/w/api.php?action=opensearch&search=jamie+lynn+spears&limit=1&namespace=0&format=json

This gives you a JSON response that contains the name of first wikipedia page returned in the search, which you can then use to perform a query against the API:

https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&titles=Jamie_Lynn_Spears&format=json

From here you can grab the first sentence on the page (hint: this usually tells us if the person in question is a singer or not): Jamie Lynn Marie Spears (born April 4, 1991) is an American actress and singer.

Putting this together, we might create a Google Cloud function that selects new BigQuery search terms from the table, calls the wikipedia API for each of them, grabs that first sentence and searches for the word singer. If we have a hit, then we simply add the search term to the table. Check out some sample code here! Not only does this help us keep track of who the most trendy singers are, but we can use the historical scores to see how their influence has changed over time.

Staying notified

These queries, plus many more, can be used to make various business decisions. Aside from looking at product names, you might want to keep tabs on competitor names so that you can begin a competitive analysis against rising challengers in your industry. Or maybe youre interested in a brand deal with a sports player instead of a singer, so you want to make sure youre aware of any rising stars in the athletic world. Either way you probably want to be notified when new trends might influence your decision making.

With another Google Cloud Function, you can programmatically run any interesting SQL queries and return the results in an email. With Cloud Scheduler, you can make sure the function runs each morning, so you stay alert as new trends data is added to the public dataset. Check out the details on how to implement this solution here.

Ready to get started?

You can explore the new Google Trends dataset in your own project, or if youre new to BigQuery spin up a project using the BigQuery sandbox. The trends data, along with all the other Google Cloud Public Datasets, will be available in Analytics Hub - so make sure to sign up for the preview, which is scheduled to be available in the third quarter of 2021, by going to cloud.google.com/analytics-hub.