-
-
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
Enhancement Request: Return All Segments via ga_segment_list() #174
Comments
In case anyone else is in a pinch, I was able to cobble together a passable solution to get up to 2k advanced segments but it's likely not worthy of a pull request. It's also likely this use case is uncommon :) SummaryUse the Source Code## load custom function
#' Get segments user has access to
#'
#' @return Segment list
#' @importFrom googleAuthR gar_api_generator
#' @family managementAPI functions
#' @export
get_all_segments <- function(){
url <- "https://www.googleapis.com/analytics/v3/management/segments"
segs <- googleAuthR::gar_api_generator(baseURI = url,
http_header = "GET",
data_parse_function = function(x) x)
req <- segs()
## page through list if necessary
if(req$totalResults > 1000){
nl <- req$nextLink
segs2 <- googleAuthR::gar_api_generator(baseURI = url,
http_header = "GET",
pars_args = c(list(`start-index` = 1001)),
data_parse_function = function(x) x)
req2 <- segs2()
req_all <- rbind(req$items, req2$items)
}
req_all
}
## load package
library(googleAnalyticsR)
## authenticate
ga_auth()
## use new function get up to 2k segments
my_segments <- get_all_segments() |
This is working but you need to install the "paging" gitHub branch of googleAuthR and googleAnalyticsR - can you see if it works with ga_segment_list() ? Install via:
Code to test: library(googleAnalyticsR)
# should return as many segments you have, even if over 1000
ga_segment_list() |
@MarkEdmondson1234 thank you for the fix and following up on this. Confirm this works and |
Hello,
Please find below an enhancement/feature request for returning all GA segments :)
Thank you in advance!
Justin
What goes wrong
The
ga_segment_list()
function returns only the first 1,000 advanced segments (source)Steps to reproduce the problem
Expected output
Total number of advanced segments
Actual output
Only first 1,000 (ascending order by segment title)
Session Info
The text was updated successfully, but these errors were encountered: