1

I'm trying to make API calls to Google Analytics and need to send regular expression as part of call using googleAnalyticsR package.

regular expression can be sent because I have special charaacter() in it. using double \ make it wrong when sent to API.

library(googleAnalyticsR)
date_range = c("2019-03-01", "2019-03-10")
view_id = "12345678"
reg_exp <- "(www.abc.com)\.*"
se <- segment_element("pagePath",
                  operator = "REGEXP",
                  type = "DIMENSION",
                  expressions = reg_exp,
                  scope = "SESSION")
sv_simple <- segment_vector_simple(list(list(se)))
seg_defined_one <- segment_define(sv_simple)
segment4 <- segment_ga4("simple", user_segment = seg_defined_one)

data <- google_analytics(view_id, 
               date_range = date_range,
               metrics = c("pageviews", ""),
               dimensions = c("pagePath"),
               segments = segment4)

How can I set the correct regexp in that variable?

4
  • Do you mean you can't send the string? If it is an R issue the escape character is '\'.
    – Jon Guiton
    Commented May 10, 2019 at 13:50
  • fortunes::fortune(365), escape the special character "\" with "\": "(www.abc.com)\\.*" Commented May 10, 2019 at 13:54
  • You mention / in your post text and you have \ in your code. Which one is actually present in your dimension?
    – kgrg
    Commented May 11, 2019 at 19:04
  • Sorry! It's \ @kgrg
    – Mehdi Zare
    Commented May 13, 2019 at 16:28

0