Description Usage Arguments Value Anti-sampling See Also Examples
A convenience function that wraps make_ga_4_req and fetch_google_analytics_4 for the common case of one GA data request.
Will perform automatic batching if over the 10000 row per API call limit.
1 2 3 4 5 6 7 | google_analytics_4(viewId, date_range = NULL, metrics = NULL,
dimensions = NULL, dim_filters = NULL, met_filters = NULL,
filtersExpression = NULL, order = NULL, segments = NULL,
pivots = NULL, cohorts = NULL, max = 1000,
samplingLevel = c("DEFAULT", "SMALL", "LARGE"), metricFormat = NULL,
histogramBuckets = NULL, anti_sample = FALSE,
anti_sample_batches = "auto")
|
viewId |
viewId of data to get. |
date_range |
character or date vector of format |
metrics |
Metric to fetch. Supports calculated metrics. |
dimensions |
Dimensions to fetch. |
dim_filters |
A filter_clause_ga4 wrapping dim_filter |
met_filters |
A filter_clause_ga4 wrapping met_filter |
filtersExpression |
A v3 API style simple filter string. Not used with other filters. |
order |
An order_type object |
segments |
List of segments as created by segment_ga4 |
pivots |
Pivots of the data as created by pivot_ga4 |
cohorts |
Cohorts created by make_cohort_group |
max |
Maximum number of rows to fetch. Defaults at 1000. Use -1 to fetch all results. |
samplingLevel |
Sample level |
metricFormat |
If supplying calculated metrics, specify the metric type |
histogramBuckets |
For numeric dimensions such as hour, a list of buckets of data. See details in make_ga_4_req |
anti_sample |
If TRUE will split up the call to avoid sampling. |
anti_sample_batches |
"auto" default, or set to number of days per batch. 1 = daily. |
A Google Analytics data.frame
anti_sample
being TRUE ignores max
as the API call is split over days
to mitigate the sampling session limit, in which case a row limit won't work. Take the top rows
of the result yourself instead e.g. head(ga_data_unsampled, 50300)
If you are lucky enough to need sub-day sampling, it will attempt to fetch per hour, but you are
restricted to not using dim_filter
argument if this is the case.
Try using filtersExpression
instead.
anti_sample
being TRUE will also set samplingLevel='LARGE'
to minimise
the number of calls.
Other GAv4 fetch functions: fetch_google_analytics_4
,
make_ga_4_req
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Not run:
library(googleAnalyticsR)
## authenticate,
## or use the RStudio Addin "Google API Auth" with analytics scopes set
ga_auth()
## get your accounts
account_list <- google_analytics_account_list()
## pick a profile with data to query
ga_id <- account_list[23,'viewId']
ga_data <- google_analytics_4(ga_id,
date_range = c("2015-07-30","2015-10-01"),
dimensions=c('source','medium'),
metrics = c('sessions','bounces'))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.