searchConsoleR (version 0.3.0)

search_analytics: Query search traffic keyword data

Description

Download your Google SEO data.

Usage

search_analytics(siteURL, startDate = Sys.Date() - 93, endDate = Sys.Date()
  - 3, dimensions = NULL, searchType = c("web", "video", "image"),
  dimensionFilterExp = NULL, aggregationType = c("auto", "byPage",
  "byProperty"), rowLimit = 1000, prettyNames = TRUE,
  walk_data = c("byBatch", "byDate", "none"))

Arguments

siteURL

The URL of the website you have auth access to.

startDate

Start date of requested range, in YYYY-MM-DD.

endDate

End date of the requested date range, in YYYY-MM-DD.

dimensions

Zero or more dimensions to group results by: "date", "country", "device", "page" , "query" or "searchAppearance"

searchType

Search type filter, default 'web'.

dimensionFilterExp

A character vector of expressions to filter. e.g. ("device==TABLET", "country~~GBR")

aggregationType

How data is aggregated.

rowLimit

How many rows to fetch. Ignored if walk_data is "byDate"

prettyNames

If TRUE, converts SO 3166-1 alpha-3 country code to full name and creates new column called countryName.

walk_data

Make multiple API calls. One of ("byBatch","byDate","none")

Value

A dataframe with columns in order of dimensions plus metrics, with attribute "aggregationType"

Details

startDate: Start date of the requested date range, in YYYY-MM-DD format, in PST time (UTC - 8:00). Must be less than or equal to the end date. This value is included in the range.

endDate: End date of the requested date range, in YYYY-MM-DD format, in PST time (UTC - 8:00). Must be greater than or equal to the start date. This value is included in the range.

dimensions: [Optional] Zero or more dimensions to group results by.

  • 'date'

  • 'country'

  • 'device'

  • 'page'

  • 'query'

  • 'searchAppearance' (can only appear on its own)

The grouping dimension values are combined to create a unique key for each result row. If no dimensions are specified, all values will be combined into a single row. There is no limit to the number of dimensions that you can group by apart from searchAppearance can only be grouped alone. You cannot group by the same dimension twice.

Example: c('country', 'device')

dimensionFilterExp: Results are grouped in the order that you supply these dimensions. dimensionFilterExp expects a character vector of expressions in the form: ("device==TABLET", "country~~GBR", "dimension operator expression")

  • dimension

    • 'country'

    • 'device'

    • 'page'

    • 'query'

    • 'searchAppearance'

  • operator

    • '~~' meaning 'contains'

    • '==' meaning 'equals'

    • '!~' meaning 'notContains'

    • '!=' meaning 'notEquals

  • expression

    • country: an ISO 3166-1 alpha-3 country code.

    • device: 'DESKTOP','MOBILE','TABLET'.

    • page: not checked, a string in page URLs without hostname.

    • query: not checked, a string in keywords.

    • searchAppearance: 'AMP_BLUE_LINK', 'RICHCARD'

searchType: [Optional] The search type to filter for. Acceptable values are:

  • "web": [Default] Web search results

  • "image": Image search results

  • "video": Video search results

aggregationType: [Optional] How data is aggregated.

  • If aggregated by property, all data for the same property is aggregated;

  • If aggregated by page, all data is aggregated by canonical URI.

  • If you filter or group by page, choose auto; otherwise you can aggregate either by property or by page, depending on how you want your data calculated;

See the API documentation to learn how data is calculated differently by site versus by page. Note: If you group or filter by page, you cannot aggregate by property. If you specify any value other than auto, the aggregation type in the result will match the requested type, or if you request an invalid type, you will get an error. The API will never change your aggregation type if the requested type is invalid. Acceptable values are:

  • "auto": [Default] Let the service decide the appropriate aggregation type.

  • "byPage": Aggregate values by URI.

  • "byProperty": Aggregate values by property.

batchType: [Optional] Batching data into multiple API calls

  • byBatch Use the API call to batch

  • byData Runs a call over each day in the date range.

  • none No batching

See Also

Guide to Search Analytics: https://support.google.com/webmasters/answer/6155685 API docs: https://developers.google.com/webmaster-tools/v3/searchanalytics/query

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
   library(searchConsoleR)
   scr_auth()
   sc_websites <- list_websites()
   
   default_fetch <- search_analytics("http://www.example.com")

   gbr_desktop_queries <-
       search_analytics("http://www.example.com",
                         start = "2016-01-01", end = "2016-03-01",
                         dimensions = c("query", "page"),
                         dimensionsFilterExp = c("device==DESKTOP", "country==GBR"),
                         searchType = "web", rowLimit = 100)

   batching <-
        search_analytics("http://www.example.com",
                         start = "2016-01-01", end = "2016-03-01",
                         dimensions = c("query", "page", "date"),
                         searchType = "web", rowLimit = 100000,
                         walk_data = "byBatch")

  
# }

Run the code above in your browser using DataLab