ga_filter_add: Create a new filter and add it to the view (optional).

View source: R/filter_management.R

ga_filter_addR Documentation

Create a new filter and add it to the view (optional).


Take a filter object and add and/or apply it so its live.


  webPropertyId = NULL,
  viewId = NULL,
  linkFilter = FALSE



The Filter object to be added to the account or view. See examples.


Account Id of the account to add the Filter to


Property Id of the property to add the Filter to


View Id of the view to add the Filter to


If TRUE will apply the Filter to the view. Needs propetyId and viewId to be set.


If you don't set linkFilter=TRUE then the filter will only be created but not applied. You will find it listed in the admin panel Account > All Filters. You can then use ga_filter_apply_to_view to apply later on.


The filterId created if linkFilter=FALSE or a Filter object if linkFilter=TRUE

See Also

Other managementAPI functions: ga_experiment_list(), ga_experiment(), ga_filter_apply_to_view(), ga_filter_update_filter_link(), ga_filter_update(), ga_segment_list()


## Not run: 
## Create a filter object for adding an IP exclusion:
Filter <- list(
               name = 'Exclude Internal Traffic',
               type = 'EXCLUDE',
               excludeDetails = list(
                   field = 'GEO_IP_ADDRESS',
                   matchType = 'EQUAL',
                   expressionValue = '',
                   caseSensitive = 'False'

# create and add the filter to the view specified      
my_filter <- ga_filter_add(Filter, 
                           accountId = 12345, 
                           webPropertyId = "UA-12345-1", 
                           viewId = 654321,
                           linkFilter = TRUE)

# only create the filter, don't apply it to any view - returns filterId for use later
my_filter <- ga_filter_add(Filter, 
                           accountId = 12345, 
                           linkFilter = FALSE)                          

## Other examples of filters you can create below:
## Create a filter object for making campaign medium lowercase
Filter <- list(
               name = 'Lowercase Campaign Medium',
               type = 'LOWERCASE',
               lowercaseDetails = list(
                   field = 'CAMPAIGN_MEDIUM'

## Create a filter object to append hostname to URI
Filter <- list(
               name = 'Append hostname to URI',
               type = 'ADVANCED',
               advancedDetails = list(
                   fieldA = 'PAGE_HOSTNAME',
                   extractA = '(.*)',
                   fieldARequired = 'True',
                   fieldB = 'PAGE_REQUEST_URI',
                   extractB = '(.*)',
                   fieldBRequired = 'False',
                   outputConstructor = '$A1$B1',
                   outputToField = 'PAGE_REQUEST_URI',
                   caseSensitive = 'False',
                   overrideOutputField = 'True'

## Create a filter object to add www hostname without it
Filter <- list(
               name = 'Search and Replace www',
               type = 'SEARCH_AND_REPLACE',
               searchAndReplaceDetails = list(
                   field = 'PAGE_HOSTNAME',
                   searchString = '^exampleUSA\\.com$',
                   replaceString = '',
                   caseSensitive = 'False'

## End(Not run)

MarkEdmondson1234/googleAnalyticsR_public documentation built on May 5, 2022, 7:49 a.m.