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:
Add both of these variables to your .Renviron file and restart the R session.
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
projects <- ssar_projects()
## Get the sites for a specific project
sites <- ssar_sites(projectid = {project_id}) #replace {project_id} with a specific project id found in the `projects` object
## Get the keywords for a site
keywords <- ssar_keywords(siteid = {site_id}) #replace {site_id} with a specific site id found in the 'sites' object
## Get the rankings for a keyword
rankings <- ssar_rankings(keywordid = {keyword_id}, #replace {keyword_id} with a specific keyword id found in the `keywords` object
fromdate = {created_at},
todate = Sys.Date()-1)
## Get the bulk rankings report
all_rankings <- ssar_bulk_rankings(date = Sys.Date()-2,
siteid = {site_id},
ranktype = 'highest',
engines = 'google',
currentlytracked = 'true',
crawledkeywords = 'true')