res <- gtrends(c("tim hortons", "starbucks"), geo = c("CA", "US"))
plot(res)Assignment5_GoogleTrendsAPI
Assignment 5: Google Trends API
1. Service Intent & Explanation
The service I intend to demonstrate through this tutorial is Google Trends.
- Google trends has a public API for reporting trends in search behavior.
A person would want to interact with this API if they were interested in seeing what consumers are searching for online, and where geographically they may be searching from. This allows us to understand trending topics in different areas. As you’ll see in this tutorial, insights from this API can be very informative when analyzing competitors, geographic pain points, consumer preferences, and brand awareness.
2. Set up Tutorial
- The gtrendsR package can interface with the Google Trends API from within R.
To access this data, you will first need to install the package using install.packages(’gtrendsr”) and run a library command to access its different features:
This installation process is suitable for the purposes of this class, however:
- If you want to access the development version (less stable) or
- If gtrendsr should be used behind a proxy
you can learn more about how to set proxy parameters and install development versions on GitHub at this link: https://github.com/PMassicotte/gtrendsR
3. Demonstration of Features
One of the features of gtrends is being able to track topic interest (or search hits) over time.
I wanted to compare Tim Hortons search hits in Canada and Starbucks’ search hits in the United States. Personally, Tim Hortons is my favorite coffee chain, but my fellow friends and roommates are Starbucks addicts. I’m interested in testing if my friends’ assertions hold true beyond my personal experience. In other words, I’m curious if Canadian citizens search for Tim Hortons as much as American citizens do with Starbucks to determine if where the chain was founded affects interest or if I’m simply the oddball out.
Below is the code string I ran and the visualization I analyzed to test this hypothesis. However, you can input the countries of your choice and use any keyword to search for/compare topics!
As we can see interest for both Tim Hortons and Starbucks is staggered over time which makes sense; promotions or external factors may increase search hits at certain times. Overall, Tim Hortons in Canada appears just as popular as Starbucks in the United States aside from during 2020. I wonder if Tim Hortons’ mobile options in Canada during Covid may have affected the amount people were searching for the company.