Google Trends provides free product-level market data.
I also load the tidyverse for data manipulation,
tidytext and textdata for text mining and
sentiment lexicons, lubridate for date handling, and
knitr/kableExtra for nicely formatted
tables.
install.packages(c("remotes", "tidyverse", "tidytext", "textdata", "lubridate", "knitr", "kableExtra", "gtrendsR"))
library(tidyverse)
library(tidytext)
library(textdata)
library(lubridate)
library(knitr)
library(kableExtra)
library(ggplot2)
library(gtrendsR)
I first used the gtrendsR package to query the Google
Trends API for a 3-year window within the United States
(geo = "US").
However, Google’s API appeared to be using aggressive rate-limiting, as I kept receiving a “Status code was not 200” error during complication, despite trying multiple workarounds.
Since it appeared NewsAPI would not provide the historical data
needed for this assignment, I decided to obtain the data from Google
Trends directly. I downloaded the data to
APD_InterestOverTime.csv, and completed the processing and
analysis steps locally in R.
# This chunk is explicitly set to eval=FALSE to prevent compilation crashes, but documents the original scraping code that returned an error.
library(gtrendsR)
library(tidyverse)
library(lubridate)
safe_gtrends <- function(keyword, geo = "US", years = 3) {
# Calculate dates
start_date <- Sys.Date() - years(years)
end_date <- Sys.Date()
# Format exactly as "YYYY-MM-DD YYYY-MM-DD"
time_string <- paste(start_date, end_date, sep = " ")
out <- tryCatch(
{
gtrends(keyword, geo = geo, time = time_string)
},
error = function(e) {
# Changed to warning so you can actually see what the API error was
warning("Google Trends request failed: ", e$message)
return(NULL)
}
)
out
}
# Run the function
trend <- safe_gtrends("Amazon Prime Day")
if (is.null(trend) || is.null(trend$interest_over_time)) {
message("No data returned from Google Trends.")
monthly <- tibble(
month = as.Date(character()),
interest = numeric()
)
} else {
monthly <- trend$interest_over_time %>%
# Clean the 'hits' column before converting to numeric
mutate(hits = if_else(hits == "<1", "0.5", hits)) %>%
mutate(
hits = as.numeric(hits),
month = floor_date(date, "month")
) %>%
group_by(month) %>%
summarize(interest = mean(hits, na.rm = TRUE), .groups = "drop")
}
glimpse(monthly)
library(tidyverse)
library(lubridate)
library(writexl)
library(scales)
# ==========================================
# 1. READ & CLEAN DATA (3-Year Window)
# ==========================================
# Google Trends leaves 2 lines of text at the top, so we skip them.
raw_trends <- read_csv("APD_InterestOverTime.csv", skip = 2, col_names = c("date_str", "hits"))
cleaned_trends <- raw_trends %>%
mutate(
date = as.Date(date_str),
# Handle low-volume '<1' tags safely
hits = if_else(hits == "<1", "0.5", as.character(hits)),
hits = as.numeric(hits)
) %>%
# Filter dynamically to the last 3 years
filter(date >= (Sys.Date() - years(3))) %>%
mutate(month_name = month(date, label = TRUE, abbr = FALSE))
# ==========================================
# 2. EXPORT TO EXCEL
# ==========================================
# Create a clean version for the spreadsheet attachment
excel_data <- cleaned_trends %>%
select(Date = date, Search_Interest = hits)
write_xlsx(excel_data, "APD_3Year_Trends.xlsx")
message("Excel file 'APD_3Year_Trends.xlsx' successfully created!")
# ==========================================
# 3. COMPUTE AVERAGE INTEREST BY MONTH
# ==========================================
monthly_averages <- cleaned_trends %>%
group_by(month_name) %>%
summarize(
avg_interest = mean(hits, na.rm = TRUE),
.groups = "drop"
)
# Display the monthly average table cleanly in your report
knitr::kable(monthly_averages,
col.names = c("Month", "Average Search Interest (0-100)"),
digits = 2,
caption = "Table 1: Average Monthly Search Interest for Amazon Prime Day")
| Month | Average Search Interest (0-100) |
|---|---|
| January | 4.67 |
| February | 4.33 |
| March | 5.33 |
| April | 4.67 |
| May | 7.00 |
| June | 23.67 |
| July | 84.00 |
| August | 5.00 |
| September | 9.33 |
| October | 34.00 |
| November | 6.33 |
| December | 5.00 |
# ==========================================
# 4. PLOT THE SEASONAL PATTERN
# ==========================================
ggplot(monthly_averages, aes(x = month_name, y = avg_interest, group = 1)) +
geom_line(color = "#D95F02", size = 1.2) +
geom_point(color = "#7570B3", size = 3) +
theme_minimal(base_size = 13) +
labs(
title = "Seasonal Search Pattern for 'Amazon Prime Day' (3-Year Average)",
subtitle = "Data Source: Google Trends",
x = "Month",
y = "Average Relative Search Interest"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
I recommend the optimal window to launch a campaign is early to mid June, because this is when search interest in the main Amazon Prime Day event in mid-July begins intensifying, leading up to a spike in interest at the beginning of July of about 84. The benefit of this campaign timing is it capitalizes on the searches people are already doing at that time, which shows they are already interested and would likely be more receptive.
I noted there is a second smaller interest peak of about 34 in early October, which represented Amazon’s second discount event called “Prime Big Deal Days.” It makes sense that this would spike in my data, because it is likely customers also search for that event using the same “Amazon Prime Day” term. They may not understand the difference in the events, since both are heavily discounted sales.
It is important to note that in 2026, Amazon chose to move Prime Day from July to late June. This shows the importance of scanning real-world data as well, and not just historical data. As a result, the optimal campaign window this year would need to move up to May to capitalize on search interest.
Amazon moves Prime Day 2026 event to June. (Jun. 11, 2026). Digital Commerce 360. https://www.digitalcommerce360.com/article/everything-about-amazon-prime-day/
McLymore, Arriana. (Jun. 1, 2026) Amazon moves Prime Day to June, keeps it a four-day event. https://www.reuters.com/business/retail-consumer/amazon-moves-prime-day-back-june-keeps-it-four-day-event-2026-06-02/
The History of Amazon Prime Day. (Aug. 27, 2025). Amazon News. https://www.aboutamazon.com/news/retail/the-history-of-prime-day