LONDON — In the rapidly evolving landscape of digital marketing, data analysis has transitioned from an optional luxury to an absolute necessity. For months, SEO professionals, data analysts, and developers have followed a definitive masterclass on bridging the gap between statistical programming and search engine optimization: Ben Johnston’s celebrated "R for SEO" series.

Now, in its tenth and final installment, Johnston has delivered a definitive capstone. Part 10 demonstrates how to synthesize Google Analytics 4 (GA4), Google Search Console (GSC), SEMRush, and OpenRouter AI models into a fully automated, dynamic SEO reporting pipeline hosted inside Google Sheets.

While the conclusion marks the end of an era for this specific tutorial run, it provides a master blueprint for modern digital marketers seeking to scale their workflows through programmatic automation.


Main Facts: Building the Ultimate SEO Reporting Pipeline

The final installment of Johnston’s series does not merely suggest theoretical workflows; it offers a production-ready R script designed to pull, process, analyze, and publish enterprise-grade SEO metrics automatically.

At its core, the system achieves four primary objectives:

R For SEO Part 10: SEO Reporting With Google Sheets & OpenRouter | R-bloggers
  1. Unified Authentication: Bypasses legacy API limitations by leveraging googleAuthR to simultaneously authorize GA4 and Google Search Console securely through a custom Google Cloud Console project.
  2. Multi-Source Data Extraction: Pulls organic traffic metrics from GA4, keyword and performance metrics from GSC, and historical rank tracking data from SEMRush.
  3. AI-Driven Commentary: Integrates the OpenRouter API—specifically calling Anthropic’s Claude Sonnet model—to automatically translate raw traffic fluctuations into plain-English, executive-ready analytical summaries.
  4. Automated Cloud Export: Utilizes the googlesheets4 package to automatically generate and populate a multi-tab Google Sheet containing structured datasets and AI commentary, ready for immediate visualization in tools like Looker Studio (formerly Data Studio).

Chronology: The Evolution of R in Modern Digital Marketing

To understand the significance of this final release, one must look at the trajectory of Johnston’s comprehensive series. When the project began, the digital marketing ecosystem was in a state of chaotic transition. Universal Analytics was being sunsetted in favor of GA4, APIs were tightening security protocols, and programmatic SEO was largely siloed behind expensive, proprietary enterprise software.

Over ten detailed installments, Johnston methodically dismantled these barriers:

  • The Foundations: The series began with basic R installations, teaching marketers unfamiliar with coding how to handle data frames, clean dirty CSV files, and write fundamental loops.
  • API Integrations: Mid-tier tutorials tackled the technical hurdles of connecting directly to Google’s developer ecosystems, extracting Search Console queries, and processing algorithm updates programmatically.
  • Advanced Analytics & Scaling: Later installments incorporated keyword cannibalization analysis, internal linking automation, sentiment analysis via Google Sheets, and visibility modeling.
  • The Grand Finale: Part 10 ties these disparate threads together, merging data extraction with modern Large Language Model (LLM) automation to handle the tedious task of executive reporting narrative generation.

Supporting Data & Technical Architecture

The technical execution of the final script relies on a robust stack of R packages, open-source repositories, and cloud APIs. Because the legacy searchConsoleR package was removed from CRAN, Johnston outlines a reliable workaround utilizing the remotes package to install the repository directly from GitHub, accompanied by explicit instructions for configuring OAuth 2.0 Client IDs within the Google Cloud Console.

The Complete Reporting Workflow

Below is the architectural breakdown of the code base utilized in the final tutorial, structured for modern SEO engineers:

# 1. Authenticate GA4 And Search Console Together
install.packages("googleAuthR")
library(googleAuthR)

options(googleAuthR.client_id = "XXXXXXXX.apps.googleusercontent.com")
options(googleAuthR.client_secret = "XXXXXXXX")
options(googleAuthR.scopes.selected = c(
  "https://www.googleapis.com/auth/webmasters",
  "https://www.googleapis.com/auth/analytics.readonly"
))
gar_auth()

# 2. Extract GA4 Organic Search Data
install.packages("remotes")
library(remotes)
install_github("MarkEdmondson1234/searchConsoleR")
library(searchConsoleR)

gaAccounts <- ga_account_list(type = "ga4")
propertyID <- gaAccounts$propertyId[1]

ga4Data <- ga_data(
  propertyId = propertyID, 
  date_range = c("2025-01-01", "2026-03-31"),
  metrics = c("sessions", "screenPageViews", "totalUsers"),
  dimensions = c("date", "pagePath"),
  dim_filters = ga_data_filter("sessionDefaultChannelGroup" == "Organic Search")
)

# 3. Extract Search Console Performance Data
scSiteURL <- "https://www.your-domain.com"
gscData <- search_analytics(
  scSiteURL, 
  startDate = "2025-01-01", 
  endDate = as.character(Sys.Date() - 3),
  searchType = "web", 
  dimensions = c("date", "page")
)
colnames(gscData) <- c("Date", "Page", "Clicks", "Impressions", "CTR", "Average Position")

# 4. Pull SEMRush Visibility History via API
semRushAPI <- "XXXXXXXX"
semRushDomainHist <- function(x, y)
  apiCall <- paste(
    "https://api.semrush.com/reports/v1/projects/0/rank_history?key=", y,
    "&domain=", x, "&export_columns=Dt,Rk,Or,Ot,Oc,Ad,At,Ac&database=uk",
    sep = ""
  )
  apiCall <- gsub(" ", "%20", apiCall)
  semRushHist <- read.csv(apiCall, header = TRUE, sep = ";", stringsAsFactors = FALSE)
  semRushHist$Dt <- as.Date(as.character(semRushHist$Dt), format = "%Y%m%d")
  semRushHist <- subset(semRushHist, Dt >= Sys.Date() - 365)
  semRushHist <- semRushHist[order(semRushHist$Dt),]
  semRushHist$Month <- format(semRushHist$Dt, "%b %Y")
  colnames(semRushHist) <- c(
    "Date", "Rank", "Organic Keywords", "Organic Traffic", 
    "Organic Cost", "Adwords Keywords", "Adwords Traffic", "Adwords Cost", "Month"
  )
  return(semRushHist)

semRushVisibility <- semRushDomainHist("your-domain.com", semRushAPI)

# 5. Automate Executive Commentary with OpenRouter (Claude Sonnet)
install.packages("httr")
install.packages("jsonlite")
library(httr)
library(jsonlite)

openRouterAPI <- "XXXXXXXX"
openRouterCommentary <- function(x)
  requestBody <- list(
    model = "anthropic/claude-sonnet-4.5",
    messages = list(
      list(role = "system", content = "You are an SEO analyst writing a short, plain English commentary on a website's performance data. Keep it to two or three sentences and focus on the most significant trends."),
      list(role = "user", content = x)
    )
  )
  openRouterCall <- POST(
    url = "https://openrouter.ai/api/v1/chat/completions",
    add_headers(Authorization = paste("Bearer", openRouterAPI)),
    content_type_json(),
    body = toJSON(requestBody, auto_unbox = TRUE)
  )
  openRouterResponse <- content(openRouterCall, as = "parsed", simplifyVector = TRUE)
  return(openRouterResponse$choices$message$content)


gaSummary <- paste(
  "Sessions over the last 30 days totalled", sum(tail(ga4Data$sessions, 30)),
  "compared to", sum(tail(ga4Data$sessions, 60)) - sum(tail(ga4Data$sessions, 30)),
  "in the previous 30 days.", sep = " "
)
gaCommentary <- openRouterCommentary(gaSummary)

# 6. Publish Everything Directly to Google Sheets
install.packages("googlesheets4")
library(googlesheets4)
gs4_auth()

reportSheet <- gs4_create(
  "SEO Report", 
  sheets = list(
    "GA4" = ga4Data, 
    "GSC" = gscData, 
    "SEMRush" = semRushVisibility
  )
)
sheet_write(data.frame(Commentary = gaCommentary), ss = reportSheet, sheet = "Commentary")

Official Perspectives and Industry Impact

While Ben Johnston has noted that writing the series took significantly longer than anticipated due to shifting digital marketing paradigms, personal milestones, and hardware failures, the industry response has been overwhelmingly positive. The integration of LLMs into programmatic workflows highlights a major shift in how modern SEO consultants operate.

R For SEO Part 10: SEO Reporting With Google Sheets & OpenRouter | R-bloggers

Rather than spending hours manually formatting pivot tables, copy-pasting CSV exports from multiple platforms, and writing descriptive summaries for stakeholders, practitioners using Johnston’s model can execute the entire workflow in minutes via a single script execution.

Industry experts note that this approach democratizes advanced data science. By routing multiple LLM providers through a unified gateway like OpenRouter, analysts are no longer locked into a single ecosystem, allowing them to experiment with various cognitive architectures for automated data storytelling.


Implications for the Future of SEO Reporting

The conclusion of the "R for SEO" series leaves a profound legacy. As search engines grow increasingly complex and algorithmic volatility becomes the norm, traditional manual auditing and static reporting are rapidly becoming obsolete.

The methodologies outlined across Johnston’s ten-part series point toward an automated future characterized by:

  1. Infrastructure as Code for SEO: Marketers must increasingly think like data engineers, utilizing version control (Git) to manage custom analytics pipelines.
  2. AI Augmentation over Replacement: Rather than replacing the SEO analyst, generative AI models like Claude are deployed as contextual synthesizers—translating dense numerical trends into actionable insights for non-technical stakeholders.
  3. Decoupled Dashboards: By utilizing R as an orchestration engine and Google Sheets as a lightweight data warehouse, teams can bypass the licensing fees and rigidity of closed-source enterprise reporting tools, feeding clean, processed datasets directly into flexible visualization layers.

As Ben Johnston closes the book on this comprehensive instructional series to explore new horizons in digital media, his work remains a foundational pillar for any modern SEO professional looking to elevate their technical capabilities, embrace automation, and future-proof their analytical stack.

By Sagoh

Leave a Reply

Your email address will not be published. Required fields are marked *