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

GA4/ga_data(): Error in if (grepl("^#", mm)) { : the condition has length > 1 #403

Closed
elalbaicin opened this issue Oct 11, 2022 · 13 comments
Assignees
Labels

Comments

@elalbaicin
Copy link

What goes wrong

Whenever I try to extract data from GA4 with ga_data(), I get the following error:

Error in if (grepl("^#", mm)) { : the condition has length > 1
In addition: Warning message:
In pq$concurrentRequests < 10 || verbose :
  'length(x) = 2 > 1' in coercion to 'logical(1)'
Error: API Data failed to parse.  
             Wrote diagnostic object to 'gar_parse_error.rds', use googleAuthR::gar_debug_parsing('gar_parse_error.rds') to 
             debug the data_parse_function.

Steps to reproduce the problem

All session info is at the "Session Info" section; then it should suffice to run:

ga_data(propertyId = propertyId,
              date_range = c("2022-10-10", "2022-10-10"),
              dimensions = c("date"),
              metrics = c("sessions"),
              limit = -1)

By the way, I've tried omitting the limit argument to see if the issue persisted, and it still threw an error.

Expected output

A dataframe.

Actual output

The aforementioned error message.

Running options(googleAuthR.verbose=2) does not yield any output.

'API Data failed to parse' diagnostics

I've written the output of googleAuthR::gar_debug_parsing("gar_parse_error.rds") on this file:
gar_parse_error.txt

Session Info

This file contains the output of sessionInfo():
session_info.txt

@eniefaC
Copy link

eniefaC commented Oct 11, 2022

Same error here, I switched to the raw json method in order to do some urgent work, and it was working for a while, but know I also have an error while parsing the response :

Error in if (pq$tokensPerDay$consumed > (care_factor * tpd_remaining) || :
missing value where TRUE/FALSE needed
Error: API Data failed to parse.

I can see the correct API response in the debug file (so I guess the request is fine and I'm not over quotas), but I'm not technical enough so I have no idea if it is connected to the firt issue or why it stopped working suddenly. Given I've just started using the package and I'm not sure what I'm doing half of the time, I would guess the problem might be unrelated!

Might add debug files later if needed.

@MarkEdmondson1234
Copy link
Collaborator

Thanks, sessionInfo will be helpful - upgraded to a new version of R? It may have caught an error that was a warning but raises an error now in new version.

Was the same query working in a previous version of R?

@MarkEdmondson1234
Copy link
Collaborator

From the error messages, it looks like part of the api response that is expected to be a scalar (length 1) is now receiving a vector (length 2)

@elalbaicin
Copy link
Author

elalbaicin commented Oct 11, 2022

Thanks, sessionInfo will be helpful - upgraded to a new version of R? It may have caught an error that was a warning but raises an error now in new version.

Was the same query working in a previous version of R?

I did upgrade to R 4.2.1 from R 4.2.0 recently, but when I downgraded back to 4.2.0 the exact same error ocurred. By the way, it stopped working on October 10, if it's any help.

@eniefaC
Copy link

eniefaC commented Oct 11, 2022

upgraded to a new version of R?

I'm on a brand new install (R, R Studio, googleanalyticsr)

sessionInfo.txt

Thanks for your work.

@MarkEdmondson1234
Copy link
Collaborator

It may be the API changed it's response, but will check it out

@XoliloX
Copy link

XoliloX commented Oct 12, 2022

Hi all,

I have the same issue with same error message. The error gets triggered with ga_data() à but not with google_analytics()

sessioninfo.txt

Thanks for your support !

Best,
D.

@MarkEdmondson1234
Copy link
Collaborator

Should be fixed now, it was a change in the API response related to quotas.

> options(googleAuthR.verbose = 2)
> ga_data(ga_id,
+         date_range = c("2022-10-10", "2022-10-10"),
+         dimensions = c("date"),
+         metrics = c("sessions"),
+         limit = -1)
ℹ 2022-10-12 11:14:45 > Request:  https://analyticsdata.googleapis.com/v1beta/properties/206670707:runReport/2022-10-12 11:14:45 > Reading cache2022-10-12 11:14:45 > tokensPerDay: Query Cost [ 1 ] / Remaining [ 24992 ]
ℹ 2022-10-12 11:14:45 > tokensPerHour: Query Cost [ 1 ] / Remaining [ 4996 ]
ℹ 2022-10-12 11:14:45 > concurrentRequests Consumed / Remaining:  0  /  102022-10-12 11:14:45 > serverErrorsPerProjectPerHour Consumed / Remaining:  0  /  102022-10-12 11:14:45 > Downloaded [ 1 ] of total [ 1 ] rows
# A tibble: 1 × 2
  date       sessions
  <date>        <dbl>
1 2022-10-10       86

To install the fix now use remotes::install_github("MarkEdmondson1234/googleAnalyticsR")and I'll submit it to CRAN ASAP

MarkEdmondson1234 added a commit that referenced this issue Oct 12, 2022
@XoliloX
Copy link

XoliloX commented Oct 12, 2022

Fixed, thanks a lot !!!

@elalbaicin
Copy link
Author

It's working now. Thank you very much, Mark.

@elliedigitalanalytics
Copy link

Thanks for the fix!!!

@MarkEdmondson1234
Copy link
Collaborator

This fix is on CRAN now so you can install normally, v1.1.0

@eniefaC
Copy link

eniefaC commented Oct 17, 2022

Thank you for the great software and support!

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

5 participants