CANVAS METRO EDITION
Friday, September 18, 2026
Magicgame.Metro
AI & ML

Mastering R for SEO: Essential Techniques for Data Analysis and Reporting

Published Sep 03, 2026 Reads 438 Desk Ben Johnston

Explore practical skills from our R for SEO series, culminating in a hands-on approach to creating SEO reports with R and Google Sheets.

Mastering R for SEO: Essential Techniques for Data Analysis and Reporting

Wrapping Up the R for SEO Series

As we reach the conclusion of this R for SEO series, it's hard not to reflect on the depth and breadth of what we’ve explored. From the foundational elements of R to the intricate details of generating an SEO report through Google Sheets and OpenRouter, we've come a long way. This finale isn’t just a summary; it's a culmination of skills and techniques that can empower practitioners in the SEO space. For those who’ve just joined or may have missed out on earlier posts, let’s take a moment to recap our journey. Each segment of this series has been designed to build upon the last, ensuring that regardless of your starting point, you could pick up the essentials of using R for SEO analysis.

Highlights of Our Journey

If you’re a fan of storytelling akin to that found in *Supernatural*, then you might appreciate this series wrap-up—it feels much like a season finale. And for those who might not share that affinity, I promise there’s no need to worry; you can skip the references. Throughout our exploration, we dug into diverse topics, including: - **Part 1 – The Basics**: We laid the groundwork by discussing R and RStudio installation alongside fundamental data operations. - **Part 2 – Data Acquisition**: Techniques for extracting meaningful insights from platforms like Google Analytics and Search Console followed, employing the Tidyverse suite. - **Part 3 – Visualization**: We elevated our data presentation skills by crafting informative charts with GGPlot2. - **Part 4 to Part 9**: We then moved through function creation, common Excel manipulations in R, API data pulls, and even ventured into web scraping. Each part sharpened our skills and shaped our understanding. The series has indeed been a significant endeavor. I genuinely hope that every step has equipped you with practical knowledge. While I enjoyed this rigorous exploration, evolutionary shifts in digital practices suggest it's time to pivot towards fresh topics worth discussing.

What Lies Ahead

Today, we’ll synthesize this collective knowledge into a practical SEO report using R. We will focus on specific data from: - **Google Analytics**: Extracting data over the past year, with a mechanism to continually update. - **Google Search Console**: Analyzing metrics such as clicks, impressions, and CTR. - **SEMRush**: Integrating visibility metrics for sharp market insights. - **OpenRouter**: Adding AI-generated commentary to contextualize our findings. - **Google Sheets**: Finally, we’ll transfer all data into Google Sheets for seamless sharing and further analysis. The task seems ambitious, but if you've been following along, I trust you’ll find value in the process. Be prepared; this session will involve implementing a range of functions and advanced features. If you're inclined to manage your iterations effectively, consider branching with Git. Should you need guidance on that, my guide on [Git for Data Analysts](https://www.ben-johnston.co.uk/git-for-data-analysts-the-complete-guide/) could be insightful. Let’s dive into the practicalities of writing some R code and start building that SEO report!

Extracting Organic Search Data from GA4 Using R

As part of our exploration of R for SEO, we’ll begin by retrieving key metrics like Sessions, Pageviews, and Total Users filtered for organic searches. You’re welcome to customize this by adding any additional metrics as specified in the API schema for Google Analytics.

While I’d typically incorporate Key Events, my site has been dormant for over a year, and let's just say my email list isn’t getting new sign-ups at the moment!

I've set the date range from the start of last year to the present, laying a solid foundation for our upcoming analyses. Feel free to adjust the date range based on your needs.

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"))

Let’s dissect this segment to appreciate its components:

  • ga4Data <-: This statement assigns the resultant data to a new object called ga4Data, facilitating future retrieval and analysis.
  • ga_data: This command is part of the googleAnalyticsR package, specifically formulated for the GA4 Data API. If you’ve previously worked with the older google_analytics function, think of this as its upgraded counterpart.
  • propertyId = propertyID: Here, we specify the GA4 property from which data is sourced. In contrast to Universal Analytics, which utilized an eight-digit “View ID”, GA4 now operates with a nine-digit Property ID. Using a variable for propertyID enhances the code's flexibility for updates.
  • date_range: The actual span for which you wish to gather data; be sure to format the dates as strings in the YYYY-MM-DD format for proper API interpretation.
  • metrics: This segment outlines the quantitative measurements to be reported.
  • sessions: Captures the total number of sessions during the specified timeframe.
  • screenPageViews: This replaces the traditional “pageviews” metric in GA4 terminology.
  • totalUsers: Represents the count of unique visitors during the defined period.
  • dimensions: These serve as the variables categorizing our data.
  • date: Essential for visualizing performance trends over time.
  • pagePath: Provides the specific URL path for pages, allowing us to pinpoint which are contributing to organic growth.
  • dim_filters = ga_data_filter(: Rather than crafting complicated conditional logic, this function lets us apply filters straightforwardly, adhering to how the GA4 API expects them to be structured.
  • “sessionDefaultChannelGroup” == “Organic Search”): By encapsulating the dimension name in quotes, we clarify to R that it should look for a field within GA4 rather than challenge it to find a local variable. This approach enhances code stability and minimizes errors, ensuring we capture true organic traffic, disregarding any noise from organic social or video.

And remember: always close your brackets. This expression will effectively retrieve your GA4 data for the last year, priming it for integration with your report.

Final Thoughts: Embracing Automation in SEO Reporting

Now that you've walked through the intricacies of automating an SEO reporting pipeline with R, it's clear that this approach offers more than just a tech-savvy toolset; it fundamentally shifts how we interact with data. Creating a new Google Sheet complete with the most pertinent metrics, paired with AI-generated insights, can save you hours of manual work. This means you can focus on interpreting the data rather than wrestling with it, allowing for more strategic thinking. Each time you run this script, a fresh set of data—covering the past year of traffic metrics from Google Analytics, insights from Search Console, and valuable visibility trends from SEMRush—springs to life. Plus, that AI commentary? That's not mere fluff; it adds context that can help you spot trends or issues you might otherwise overlook. If you’re in the SEO game, missing out on this workflow is a missed opportunity. But here’s the thing: while this automation streamlines processes, it also calls for the right interpretation. Take those AI insights with a grain of caution. It’s easy to accept them blindly, but you have the expertise to dig deeper. Engage with the data, challenge the commentary, and don’t shy away from asking tough questions. As we wrap up this series, I encourage you to take these lessons into your own workflow. If you build something interesting with what you've learned or encounter challenges along the way, reach out on [LinkedIn](https://www.linkedin.com/in/ben-johnston-seo/) or [BlueSky](https://bsky.app/profile/benjohnston.bsky.social). Your experiences could shed light on this evolving landscape and inspire others. Thanks for joining me on this journey through R for SEO! Keep an eye out for my next installment—there’s more exciting content on the horizon, and I promise it won't take long to arrive.
Source: Ben Johnston · www.r-bloggers.com

Discussion

Sign in to join the discussion.