-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
unsampled report downloads #44
Comments
I can work on this one before the end of the year. Feel free to assign it to me. |
@j450h1 that would be great! There are several management API functions that have been requested, mostly those that help setup (like editing filters) so if you are looking for more just say! |
See PR #139. A couple things to note:
options(googleAuthR.scopes.selected = c("https://www.googleapis.com/auth/analytics",
|
@j450h1 did you look into using |
Yes, I explored that option. I believe the problem was v3 of the API only allows you to export Google Doc type files (mimeType): https://developers.google.com/apis-explorer/#p/drive/v3/drive.files.export and I believe that package uses v3. I think another issue was that file was not in "my" google drive which is what the functions in that package allow you to download/upload files from. Nonetheless, I obviously tried to go with a simple approach first. |
Working with it now, and to handle the extra scope issues I don't want to add the general scope to the whole package, and just have some documentation to add the scope when needed, and a check at the start of the download that checks Also I'd like the |
Sure sounds good to me. Whatever will make it easier to work with. |
Just following up on this one, do you want me to remove the save to dataframe option or are you going to take care of it? |
Didn't want to remove the save to dataframe option, but rather change That way it will only need these arguments: ga_unsampled_download <- function(reportTitle,
file=sprintf("%s.csv", reportTitle),
downloadFile=TRUE) ...and could be chained and looped via something like: library(googleAnalyticsR)
library(tidyverse)
## download all unsampled reports
ga_unsampled_list(accountId, webPropertyId, profileId) %>%
select(title) %>%
map(ga_unsampled_download)
Some more documentation and examples won't hurt either. |
Okay, so " a check at the start of the download that checks options(googleAuthR.scopes.selected) that raises an error if the drive scope isn't present." is done. Regarding, the 2nd point, I have changed the ga_unsampled_list to return a dataframe. This might require updating other code that uses this function. However, it is working quite well for this ga_unsampled_download function. I'm having a little trouble using walk2 and map2 as you can see it is split up when not needed (technically map2 isn't needed, but just in case the user enters the title when they want the dataframes - even though that argument won't be used) in a pipe, but I managed to get these two test cases working for now:
|
If a user wanted to download just 1 report:
This is what I mean, by how walk2, map2, or walk like this one should all be in one pipeline (not sure if there is a better word?). I just couldn't get it working, maybe you know the correct syntax? This one only works because it is 1 item, if it wasn't filtered it wouldn't work properly. So I realize it definitely needs more testing. Also by default right now, the filename is the documentId/driveDownloadDetails (example: 19dydgPj1A9L7QRDgNvE6qTNcXN0rqBxj.csv), unless user selects the title column which should be best practice when downloading (hence use of walk2), while when creating a list of dataframes it is not needed/used. |
The downside of this approach is if the user doesn't want to use pipes, he/she will need to enter the driveDownloadDetails and can't just enter the report name. That was the advantage of the old approach. But I guess, if its documented to review the list first and choose the driveDownloadDetails or maybe most people are using %>% now. |
Its perhaps easier to download the files as they are named in the GA UI (perhaps with date too) then show an example on how to rename them if they want, that way you don't have to juggle two argument loops. My overall strategy over time has been to try and get each function to be as useful but do as little as possible, with as many sensible defaults for beginners but the arguments in there for advanced users if they want it, as its the most flexible and easiest to maintain. If its just one report, I guess they could just read the reportTitle from the UI, and pass that in:
How come you needed |
I think that approach makes a lot of sense. Regarding na.omit(), it is required because the list includes what appear to be standard reports not created by the user and therefore no download details. Yes, I can include it as part of the ga_unsampled_list. Should a tibble be returned instead of a dataframe? Just trying to be consistent with the rest of the repo. |
Regarding allowing the user to enter the ReportTitle, if we go with that approach it will either require all the same arguments as ga_unsampled_list (as was originally done) or the returned dataframe/tibble from this function. So their is a tradeoff because you can enter the reportTitle which will essentially just filter the dataframe, however then you cannot simply pipe the reportTitle as mentioned. Looks like the simpler approach for the user is to allow the reportTitle be entered, so I will change it back to that approach. What do you think of requiring the same arguments of ga_unsampled_list or just requiring the returned df/tibble? |
I'm not sure it is consistent in the package, but IIRC it should fall back to data.frame from tibble if they don't have it loaded - the It doesn't necessarily have to be piped, in fact a motive is to allow other ways that we haven't thought of to cover. A base R example may be: library(googleAnalyticsR)
## download all unsampled reports
unsample_df <- ga_unsampled_list(accountId, webPropertyId, profileId)
# you need the title to pass in to ga_unsampled_download
lapply(unsample_df$title, ga_unsampled_download) |
Ok thanks for clarifying. I think I know what updates to make now. |
Give this a crack and let me know. Note: accountId, webPropertyId, profileId are required again because I have to call ga_unsampled_list within ga_unsampled_download. The only other option I see is to pass the dataframe/tibble object itself (similar to what I was doing before this) and the user cannot then enter a reportTitle if they wanted to do that. Anyways here it is:
|
|
unsampled report downloads #44
Hey Mark. Just wondering if this issue can be closed or is there a reason it is still open? I'm happy to clear up any loose ends if there are any! |
I just forgot to close it :) |
Fetch from management API for 360 properties
The text was updated successfully, but these errors were encountered: