Course Context: This tutorial is designed for marketing students learning how to leverage publicly available search data for consumer insights, competitive intelligence, and campaign planning.
GitHub: github.com/utjimmyx
Google Trends is a free, publicly available tool from Google that tracks the relative search interest for any keyword or topic over time. Rather than reporting raw search volume, Google normalizes data on a scale of 0 to 100, where 100 represents the peak popularity of a term within the selected time range and geography.
Why does this matter for marketers?
Key Concept: Google Trends data is relative, not absolute. A score of 50 means the term had half the search interest compared to its peak — it does not mean 50 searches occurred.
We will use the following R packages. Install any you don’t already have.
# Run once to install
install.packages(c("gtrendsR", "tidyverse", "ggplot2", "scales",
"lubridate", "knitr", "kableExtra"))library(gtrendsR) # Pull data from Google Trends
library(tidyverse) # Data manipulation and plotting
library(ggplot2) # Visualization
library(scales) # Axis formatting
library(lubridate) # Date handling
library(knitr) # Tables
library(kableExtra) # Enhanced table formattinggtrends() FunctionThe core function in gtrendsR is gtrends().
Here are its key arguments:
| Argument | Description | Example |
|---|---|---|
keyword |
Search term(s), up to 5 at a time | c("Nike", "Adidas") |
geo |
Country or region code (blank = worldwide) | "US", "CA", "GB" |
time |
Time range of the query | "today 12-m", "2020-01-01 2024-12-31" |
gprop |
Search property | "web", "youtube", "news" |
category |
Restrict to a Google topic category (0 = all) | 0 |
Common time values:
"now 1-H" → Past hour
"now 4-H" → Past 4 hours
"today 1-m" → Past 30 days
"today 3-m" → Past 90 days
"today 12-m" → Past 12 months
"today+5-y" → Past 5 years
"all" → Since 2004
Let’s start simple: track search interest for “Starbucks” in the United States over the past 12 months.
# Query Google Trends
starbucks_trend <- gtrends(
keyword = "Starbucks",
geo = "US",
time = "today+5-y"
)
# Extract interest over time
iot <- starbucks_trend$interest_over_timeggplot(iot, aes(x = date, y = hits)) +
geom_line(color = "#00704A", linewidth = 1) +
geom_smooth(method = "loess", se = TRUE, color = "#1E3932",
fill = "#D4E9E2", alpha = 0.3) +
scale_x_datetime(date_labels = "%b %Y", date_breaks = "2 months") +
labs(
title = "Google Search Interest: Starbucks",
subtitle = "United States | Past 5 years | Web Search",
x = NULL,
y = "Relative Interest (0–100)",
caption = "Source: Google Trends via gtrendsR | github.com/utjimmyx"
) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 14),
plot.subtitle = element_text(color = "gray50"),
axis.text.x = element_text(angle = 30, hjust = 1)
)Marketing Insight: Look for dips and spikes. Dips may correspond to off-peak seasons or PR crises. Spikes often align with new product launches, promotions, or viral social media moments.
Jimmy Zhenning Xu, Ph.D., AIS Doctor, Principal Consultant | github.com/utjimmyx