Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ga_aggregate

Aggregate a Google Analytics dataframe over inputted columns


Description

A helper function to aggregate over dimensions

Usage

ga_aggregate(
  ga_data,
  agg_names = NULL,
  mean_regex = "^avg|^percent|Rate$|^CPC$|^CTR$|^CPM$|^RPC$|^ROI$|^ROAS$|Per"
)

Arguments

ga_data

A dataframe of data to aggregate

agg_names

The columns to aggregate over

mean_regex

The regex for column names to do mean() rather than sum()

Details

Will auto select metrics if they are numeric class columns. Will auto perform mean aggregation it metric names match mean_regex argument If agg_names is NULL will aggregate over all

Examples

## Not run: 

# use `aggregateGAData` so you can on the fly create summary data
ga_data <- google_analytics(81416156, 
                            date_range = c("10daysAgo", "yesterday"),
                            metrics = "sessions", dimensions = c("hour","date"))
                            
# if we want totals per hour over the dates:
ga_aggregate(ga_data[,c("hour","sessions")], agg_names = "hour")

# it knows not to sum metrics that are rates:
ga_aggregate(ga_data[,c("hour","bounceRate")], agg_names = "hour")



## End(Not run)

googleAnalyticsR

Google Analytics API into R

v1.0.0
MIT + file LICENSE
Authors
Mark Edmondson [aut, cre] (<https://orcid.org/0000-0002-8434-3881>), Artem Klevtsov [ctb], Johann deBoer [ctb], David Watkins [ctb], Olivia Brode-Roger [ctb], Jas Sohi [ctb], Zoran Selinger [ctb], Octavian Corlade [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.