Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in as(segments, "segment_ga4") : no method or default for coercing “list” to “segment_ga4” #253

Closed
jdeboer opened this issue Apr 25, 2019 · 3 comments
Assignees
Labels

Comments

@jdeboer
Copy link
Contributor

jdeboer commented Apr 25, 2019

What goes wrong

Previously users were able to create multiple segments using segment_ga4 then combine them using list(). But now this generates an error "Error in as(segments, "segment_ga4") : no method or default for coercing “list” to “segment_ga4”"

Running class(segments) <- "segment_ga4" immediately after creating the segments list is a workaround.

Ideas for resolution:
Should a list of 'segment_ga4' objects have its own class name separate from an atomic segment_ga4 object? If so, is there a function in googleAnalyticsR to create such a list object rather than the user having to create one by using y <- list(x) and class(y)<-'segment_ga4'? Or should we modify googleAnalyticsR to examine the elements of a supplied list to determine whether all of the elements are of the class 'segment_ga4'?

@MarkEdmondson1234
Copy link
Collaborator

If I can get a reproducible example, I'll put a test in then try out different solutions.

@adamribaudo
Copy link

Here's an example that produces the error noted above. Both segment1 and segment2 work when placed in the google_analytics call individually. As a list, however, the error is returned:

se1 <- segment_element("source", operator = "REGEXP", type = "DIMENSION", expressions = "google")
sv1 <- segment_vector_simple(list(list(se1)))
seg_defined1  <- segment_define(sv1)
segment1 <- segment_ga4("Google Traffic", session_segment  = seg_defined1)

se2 <- segment_element("source", operator = "REGEXP", type = "DIMENSION", expressions = "bing")
sv2 <- segment_vector_simple(list(list(se2)))
seg_defined2  <- segment_define(sv2)
segment2 <- segment_ga4("Bing Traffic", session_segment  = seg_defined2)

ga_sessions <- google_analytics(viewId = view_id,
                            date_range = c(start_date, end_date),
                            metrics = "sessions",
                            dimensions = c("yearMonth"),
                            segments = list(segment1, segment2),
                            anti_sample = F)

@MarkEdmondson1234
Copy link
Collaborator

Thanks for the test! I think this is solved now in the latest version on GitHub, will be on CRAN

etk4ya added a commit to etk4ya/googleAnalyticsR that referenced this issue Sep 6, 2019
I've encountered a similar problem to Issue 8-bit-sheep#253, but with an error in Line 356: as(dim_filters, ".filter_clauses_ga4").
It seems there's no method or default for coercing "list" to ".filter_clauses_ga4". So I'm hoping that the solution you applied for segments will work for dim_filters. Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants