metricDimensionSelect: metricDimensionSelectUI - GA4 Shiny Module

Description Usage Arguments Value See Also Examples

View source: R/shiny-modules-new.R

Description

Create a Google Analytics variable selector

Shiny Module for use with GA4 metric and dimension fields fetched via ga_meta("ga4")

Usage

1
2
3
4
5
6
7
8
metricDimensionSelectUI(id, label = "Metric", multiple = TRUE, width = NULL)

metricDimensionSelect(
  id,
  field_type = c("metric", "dimension"),
  custom_meta = NULL,
  default = NULL
)

Arguments

id

The Shiny id

label

label

multiple

multiple select

width

width of select

field_type

metric or dimension

custom_meta

Pass a meta field table from ga_meta("ga4") to get custom fields from GA4 (reactive)

default

The default selected choice. First element if NULL

Value

Shiny UI

the selected variable

See Also

Other Shiny modules: accountPickerUI(), authDropdownUI(), authDropdown(), multi_selectUI(), multi_select()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## Not run: 

# ui.R
metricDimensionSelect("mets1")
metricDimensionSelect("dims1")

#server.R
metrics <- metricDimensionSelect("mets1", "metric")
dims <- metricDimensionSelect("dims1", "dimension")



# use in app with custom fields
#' ui <- fluidPage(title = "Shiny App",
                 accountPickerUI("auth_menu", inColumns = TRUE),
                 metricDimensionSelectUI("mets1"),
                 metricDimensionSelectUI("dims_custom")
                 )
server <- function(input, output, session){
  token <- gar_shiny_auth(session)
  
  accs <- reactive({
    req(token)
    ga_account_list("ga4")
   })
   
  # no custom data
  metrics <- metricDimensionSelect("mets1")
   
  # module for authentication
  property_id <- accountPicker("auth_menu", ga_table = accs, id_only = TRUE)
  
  meta <- reactive({
      req(property_id())
      ga_meta("data", propertyId = property_id())
  })
 
  
  # custom data
  dims_custom <- metricDimensionSelect("dims_custom", 
                                       type = "dimension", 
                                       custom_meta = meta())
 }
 
 shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)
 



## End(Not run)

googleAnalyticsR documentation built on Oct. 7, 2021, 9:06 a.m.