The statsearchanalyticsr makes it easy to pull STAT Search Analytics data into R for visualization, integration, and analysis by enabling you to retrieve keyword ranking data in a tidy way.
You can install the development version of statsearchanalyticsr from github with:
install.packages('remotes')
::install_github('searchdiscovery/statsearchanalyticsr') remotes
Add both of these variables to your .Renviron file and restart the R session.
= '{apikey}'
SSAR_APIKEY = '{subdomain}' SSAR_SUBDOMAIN
Once completed, then the API is ready to start pulling data.
The API Key can be acquired following these steps:
The subdomain is easy to find. It is the first part of the
‘getstat.com’ URL. For example, if your STAT login URL is
demonstration.getstat.com
then your STAT subdomain is
demonstration
.
The default daily limit for API calls is 1,000 calls per day. The daily count resets every night at midnight UTC. If you need to exceed the daily limit, you will need to talk to STAT Searh Analytics support.
If you are attempting to pull more than 1,000 keywords at a time, then consider using the ssar_bulk_rankings() function. This function enables you to pull all the rankings by day for all keywords. This option can be more time efficient, saving you a 24 hour wait for next data pull, but note it will likely include much more data than necessary.
This is a basic example showing the process of pulling data for the first time:
## Get all available projects
<- ssar_projects()
projects
## Get the sites for a specific project
<- ssar_sites(projectid = {project_id}) #replace {project_id} with a specific project id found in the `projects` object
sites
## Get the keywords for a site
<- ssar_keywords(siteid = {site_id}) #replace {site_id} with a specific site id found in the 'sites' object
keywords
## Get the rankings for a keyword
<- ssar_rankings(keywordid = {keyword_id}, #replace {keyword_id} with a specific keyword id found in the `keywords` object
rankings fromdate = {created_at},
todate = Sys.Date()-1)
## Get the bulk rankings report
<- ssar_bulk_rankings(date = Sys.Date()-2,
all_rankings siteid = {site_id},
ranktype = 'highest',
engines = 'google',
currentlytracked = 'true',
crawledkeywords = 'true')