met_filter: Make a metric filter object

View source: R/filters.R

met_filterR Documentation

Make a metric filter object

Description

Make a metric filter object

Usage

met_filter(
  metric,
  operator = c("EQUAL", "LESS_THAN", "GREATER_THAN", "IS_MISSING"),
  comparisonValue,
  not = FALSE
)

Arguments

metric

metric name to filter on.

operator

How to match the dimension.

comparisonValue

What to match.

not

Logical NOT operator. Boolean.

Value

An object of class met_fil_ga4 for use in filter_clause_ga4()

See Also

Other filter functions: dim_filter(), filter_clause_ga4()

Examples


## 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']

## create filters on metrics
mf <- met_filter("bounces", "GREATER_THAN", 0)
mf2 <- met_filter("sessions", "GREATER", 2)

## create filters on dimensions
df <- dim_filter("source","BEGINS_WITH","1",not = TRUE)
df2 <- dim_filter("source","BEGINS_WITH","a",not = TRUE)

## construct filter objects
fc2 <- filter_clause_ga4(list(df, df2), operator = "AND")
fc <- filter_clause_ga4(list(mf, mf2), operator = "AND")

## make v4 request
ga_data1 <- google_analytics_4(ga_id,
                               date_range = c("2015-07-30","2015-10-01"),
                               dimensions=c('source','medium'),
                               metrics = c('sessions','bounces'),
                               met_filters = fc,
                               dim_filters = fc2,
                               filtersExpression = "ga:source!=(direct)")


## End(Not run)


googleAnalyticsR documentation built on Sept. 11, 2024, 8:15 p.m.