ga_data(
propertyId,
metrics,
date_range = NULL,
dimensions = NULL,
dim_filters = NULL,
dimensionDelimiter = "/",
met_filters = NULL,
orderBys = NULL,
limit = 100,
page_size = 100000L,
realtime = FALSE,
raw_json = NULL
)
A GA4 property Id
The metrics to request - see ga_meta - set to NULL to only see dimensions
A vector with start and end dates in YYYY-MM-DD format - can send in up to four date ranges at once
The dimensions to request - see ga_meta
Filter on the dimensions of the request - a filter object created by ga_data_filter
If combining dimensions in one column, the delimiter for the value field
Filter on the metrics of the request - a filter object created by ga_data_filter
How to order the response - an order object created by ga_data_order
The number of rows to return - use -1 to return all rows
The size of API pages - default is 100000L rows
If TRUE then will call the real-time reports, that have a more limited set of dimensions/metrics - see valid real-time dimensions
You can send in the raw JSON string for a Data API request which will skip all checks
A data.frame tibble, including attributes metadata, metricAggregations and rowCount. Use ga_data_aggregations to extract the data.frames of metricAggregations
This is the main function to call the Google Analytics 4 Data API.
Other GA4 functions:
ga_data_filter()
,
ga_data_order()
if (FALSE) {
# send up to 4 date ranges
multi_date <- ga_data(
206670707,
metrics = c("activeUsers","sessions"),
dimensions = c("date","city","dayOfWeek"),
date_range = c("2020-03-31", "2020-04-27", "2020-04-30", "2020-05-27"),
dim_filters = ga_data_filter("city"=="Copenhagen"),
limit = 100
)
# metric and dimension expressions
# create your own named metrics
met_expression <- ga_data(
206670707,
metrics = c("activeUsers","sessions",sessionsPerUser = "sessions/activeUsers"),
dimensions = c("date","city","dayOfWeek"),
date_range = c("2020-03-31", "2020-04-27"),
limit = 100
)
# create your own aggregation dimensions
dim_expression <- ga_data(
206670707,
metrics = c("activeUsers","sessions"),
dimensions = c("date","city","dayOfWeek", cdow = "city/dayOfWeek"),
date_range = c("2020-03-31", "2020-04-27"),
limit = 100
)
# run a real-time report (no date dimension allowed)
realtime <- ga_data(
206670707,
metrics = "activeUsers",
dimensions = c("city","unifiedScreenName"),
limit = 100,
realtime = TRUE)
# extract meta data from the table
ga_data_aggregations(realtime)
# add ordering
a <- ga_data_order(-sessions)
b <- ga_data_order(-dayOfWeek, type = "NUMERIC")
ga_data(
206670707,
metrics = c("activeUsers","sessions"),
dimensions = c("date","city","dayOfWeek"),
date_range = c("2020-03-31", "2020-04-27"),
orderBys = c(a, b)
)
}