Use with ga_data to create orderBys
ga_data_order(
x,
type = c("ALPHANUMERIC", "CASE_INSENSITIVE_ALPHANUMERIC", "NUMERIC")
)
Order DSL enabled syntax
Order Type
A list of OrderBy
objects suitable for use in ga_data
The DSL rules are:
Fields can be quoted or unquoted. If unquoted they will be validated
Use + as a prefix to indicate ascending order e.g. +sessions
Use - as a prefix to indicate decreasing order e.g. -sessions
Combine order fields without commas e.g. +sessions -city
Ordering of dimensions can also specify a type of ordering: ALPHANUMERIC, CASE_INSENSITIVE_ALPHANUMERIC, NUMERIC
The dimension ordering have these effects:
ALPHANUMERIC For example, "2" < "A" < "X" < "b" < "z"
CASE_INSENSITIVE_ALPHANUMERIC Case insensitive alphanumeric sort by lower case Unicode code point. For example, "2" < "A" < "b" < "X" < "z"
NUMERIC Dimension values are converted to numbers before sorting. For example in NUMERIC sort, "25" < "100", and in ALPHANUMERIC sort, "100" < "25". Non-numeric dimension values all have equal ordering value below all numeric values
https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/OrderBy
Other GA4 functions:
ga_data_filter()
,
ga_data()
# session in descending order
ga_data_order(-sessions)
#> [[1]]
#> ==GA4 OrderBy==
#> Metric: sessions
#> Descending: TRUE
#>
# city dimension in ascending alphanumeric order
ga_data_order(+city)
#> [[1]]
#> ==GA4 OrderBy==
#> Dimension: city
#> OrderType: ALPHANUMERIC
#> Descending: FALSE
#>
# as above plus sessions in descending order
ga_data_order(+city -sessions)
#> [[1]]
#> ==GA4 OrderBy==
#> Dimension: city
#> OrderType: ALPHANUMERIC
#> Descending: FALSE
#>
#> [[2]]
#> ==GA4 OrderBy==
#> Metric: sessions
#> Descending: TRUE
#>
# as above plus activeUsers in ascending order
ga_data_order(+city -sessions +activeUsers)
#> [[1]]
#> ==GA4 OrderBy==
#> Dimension: city
#> OrderType: ALPHANUMERIC
#> Descending: FALSE
#>
#> [[2]]
#> ==GA4 OrderBy==
#> Metric: sessions
#> Descending: TRUE
#>
#> [[3]]
#> ==GA4 OrderBy==
#> Metric: activeUsers
#> Descending: FALSE
#>
# dayOfWeek dimension in ascending numeric order
ga_data_order(+dayOfWeek, type = "NUMERIC")
#> [[1]]
#> ==GA4 OrderBy==
#> Dimension: dayOfWeek
#> OrderType: NUMERIC
#> Descending: FALSE
#>
# you can also combine them with c()
a <- ga_data_order(-sessions)
b <- ga_data_order(-dayOfWeek, type = "NUMERIC")
c(a, b)
#> [[1]]
#> ==GA4 OrderBy==
#> Metric: sessions
#> Descending: TRUE
#>
#> [[2]]
#> ==GA4 OrderBy==
#> Dimension: dayOfWeek
#> OrderType: NUMERIC
#> Descending: TRUE
#>
if (FALSE) {
# example of use
ga_data(
206670707,
metrics = c("activeUsers","sessions"),
dimensions = c("date","city","dayOfWeek"),
date_range = c("2020-03-31", "2020-04-27"),
orderBys = ga_data_order(-sessions -dayOfWeek)
)
}