RGA (version 0.4.2)

get_ga: Core Reporting API

Description

Get the Anaytics data from Core Reporting API for a view (profile).

Usage

get_ga(profileId = getOption("rga.profileId"), start.date = "7daysAgo", end.date = "yesterday", metrics = c("ga:users", "ga:sessions", " ga:pageviews"), dimensions = NULL, sort = NULL, filters = NULL, segment = NULL, samplingLevel = NULL, start.index = NULL, max.results = NULL, include.empty.rows = NULL, fetch.by = NULL, token)

Arguments

profileId
character. Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID. Can be obtained using the list_profiles or via the web interface Google Analytics.
start.date
character. Start date for fetching Analytics data. Request can specify a start date formatted as "YYYY-MM-DD" or as a relative date (e.g., "today", "yesterday", or "7daysAgo"). The default value is "7daysAgo".
end.date
character. End date for fetching Analytics data. Request can specify an end date formatted as "YYYY-MM-DD" or as a relative date (e.g., "today", "yesterday", or "7daysAgo"). The default value is "yesterday".
metrics
character. A comma-separated list of Analytics metrics. E.g., "ga:sessions,ga:pageviews". At least one metric must be specified.
dimensions
character. A comma-separated list of Analytics dimensions. E.g., "ga:browser,ga:city".
sort
character. A comma-separated list of dimensions or metrics that determine the sort order for Analytics data.
filters
character. A comma-separated list of dimension or metric filters to be applied to Analytics data.
segment
character. An Analytics segment to be applied to data. Can be obtained using the list_segments or via the web interface Google Analytics.
samplingLevel
character. The desired sampling level. Allowed values: "DEFAULT", "FASTER", "HIGHER_PRECISION".
start.index
integer. An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter.
max.results
integer. The maximum number of entries to include in this feed.
include.empty.rows
logical. The response will include empty rows if this parameter is set to TRUE (default),
fetch.by
character. Split the query by date range. Allowed values: "day", "week", "month", "quarter", "year". It does not work correctly with the ga:users and ga:NdayUsers metrics.
token
Token2.0 class object with a valid authorization data.

Value

A data frame including the Analytics data for a view (profile). Addition information about profile and request query stored in the attributes.

References

Core Reporting API - Dimensions & Metrics Reference

Core Reporting API - Query Parameter Details

Core Reporting API - Common Queries

Google Analytics Demos & Tools - Query Explorer

See Also

list_dimsmets shiny_dimsmets

Other Reporting API: firstdate, get_mcf, get_realtime

Examples

Run this code
## Not run: 
# # get token data
# authorize()
# # get report data
# ga_data <- get_ga(XXXXXXX, start.date = "30daysAgo", end.date = "today",
#                   metrics = "ga:sessions", dimensions = "ga:source,ga:medium",
#                   sort = "-ga:sessions")
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace