Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common workflows in ga_model() format #354

Open
MarkEdmondson1234 opened this issue Jan 1, 2021 · 1 comment
Open

Common workflows in ga_model() format #354

MarkEdmondson1234 opened this issue Jan 1, 2021 · 1 comment
Assignees

Comments

@MarkEdmondson1234
Copy link
Collaborator

Use ga_model() to pre-load common tasks such as trends of metrics, etc.

@MarkEdmondson1234
Copy link
Collaborator Author

MarkEdmondson1234 commented Jan 1, 2021

GA4 date trends

# ga_model: GA4 metric time-series trended into an interactive dygraph plot

library(xts)
library(dygraphs)

# fetch data
data_f <- function(view_id,
date_range = c("400daysAgo","yesterday"),
metrics = c("sessions"),
...)
{

ga_data(view_id, metrics = metrics, date_range = date_range, dimensions = "date", limit = -1, orderBys = ga_data_order(+date))

}

# model data
model_f <- function(df,
...)
{

xts::xts(df[, -1], order.by = df$date)

}

# output data
output_f<- function(df,...)
{
require(dygraphs)
dygraph(df, main = "GA4 trend- googleAnalyticsR") %>% 
    dyAxis("x", label = "Date") %>%
    dyOptions(axisLineWidth = 1.5, drawGrid = FALSE)

}

model <- ga_model_make(data_f = data_f, required_columns = c("date"), model_f = model_f, output_f = output_f, required_packages = c("xts","dygraphs"), description = "GA4 Metric Trend", outputShiny = dygraphs::dygraphOutput, renderShiny = dygraphs::renderDygraph)



ga_model(1234567, ga4_trend)
ga_model(1234567, ga4_trend, date_range = c("100daysAgo","yesterday"))
ga_model_save(ga4_trend, "inst/models/ga4-trend.gamr")

Available via

ga_model(1234567, ga_model_example("ga4-trend.gamr"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant