forked from 8-bit-sheep/googleAnalyticsR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiments.R
83 lines (69 loc) · 2.46 KB
/
experiments.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#' Experiments Meta data
#'
#' @param accountId Account Id
#' @param webPropertyId Web Property Id
#' @param profileId Profile Id
#' @param experimentId Experiment Id
#'
#' @return Experiment Meta Data
#' @importFrom googleAuthR gar_api_generator
#' @family managementAPI functions
#' @export
ga_experiment <- function(accountId,
webPropertyId,
profileId,
experimentId){
url <- "https://www.googleapis.com/analytics/v3/management/"
experiments <- gar_api_generator(url,
"GET",
path_args = list(
accounts = accountId,
webproperties = webPropertyId,
profiles = profileId,
experiments = experimentId
),
data_parse_function = function(x) x)
experiments()
}
#' List Experiments
#'
#' @param accountId Account Id
#' @param webPropertyId Web Property Id
#' @param profileId Profile Id
#'
#' @return Experiments List
#' @importFrom googleAuthR gar_api_generator
#' @family managementAPI functions
#' @export
ga_experiment_list <- function(accountId,
webPropertyId,
profileId){
url <- "https://www.googleapis.com/analytics/v3/management/"
experiments <- gar_api_generator(url,
"GET",
path_args = list(
accounts = accountId,
webproperties = webPropertyId,
profiles = profileId,
experiments = ""
),
data_parse_function = parse_ga_experiments_list)
pages <- gar_api_page(experiments, page_f = get_attr_nextLink)
Reduce(bind_rows, pages)
}
#' @noRd
#' @import assertthat
parse_ga_experiments_list <- function(x){
o <- x %>%
management_api_parsing("analytics#experiments")
if(is.null(o)){
return(data.frame())
}
o <- o %>%
mutate(created = iso8601_to_r(created),
updated = iso8601_to_r(updated),
startTime = iso8601_to_r(startTime),
endTime = iso8601_to_r(endTime))
attr(o, "nextLink") <- x$nextLink
o
}