-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathget_usage.Rd
More file actions
100 lines (86 loc) · 3.79 KB
/
get_usage.Rd
File metadata and controls
100 lines (86 loc) · 3.79 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get.R
\name{get_usage}
\alias{get_usage}
\title{Get usage information for deployed content}
\usage{
get_usage(client, content_guid = NULL, from = NULL, to = NULL)
}
\arguments{
\item{client}{A \code{Connect} R6 client object.}
\item{content_guid}{Optional. A single content GUID or a character vector of
GUIDs to filter results. When multiple GUIDs are provided they are
collapsed with \code{"|"}.}
\item{from}{Optional date-time (\code{POSIXct} or \code{POSIXlt}). Only
records after this time are returned. If not provided, records
are returned back to the first record available.}
\item{to}{Optional date-time (\code{POSIXct} or \code{POSIXlt}). Only records
before this time are returned. If not provided, all records up to
the most recent are returned.}
}
\value{
A list of usage records. Each record is a list with all elements
as character strings unless otherwise specified.
\itemize{
\item \code{id}: A string identifier for the hit.
\item \code{user_guid}: The user GUID if the visitor is logged-in, \code{NULL} for
anonymous hits.
\item \code{content_guid}: The GUID of the visited content.
\item \code{timestamp}: The time of the hit in RFC3339 format.
\item \code{data}: A nested list with optional fields:
\itemize{
\item \code{path}: The request path (if recorded).
\item \code{user_agent}: The user agent string (if available).
}
}
Use \code{\link[=as.data.frame]{as.data.frame()}} or \code{\link[tibble:as_tibble]{tibble::as_tibble()}} to convert to a flat
table with parsed types. In the resulting data frame:
\itemize{
\item \code{timestamp} is parsed to \code{POSIXct}.
\item \code{path} and \code{user_agent} are extracted from the nested \code{data} field.
}
By default, \code{\link[=as.data.frame]{as.data.frame()}} attempts to extract the nested fields using
the \pkg{tidyr} package. If \pkg{tidyr} is not available, or if you want to
skip unnesting, call \code{as.data.frame(x, unnest = FALSE)} to leave \code{data} as
a list-column.
}
\description{
Retrieve content hits for all available content on the server. Available
content depends on the user whose API key is in use. Administrator accounts
will receive data for all content on the server. Publishers will receive data
for all content they own or collaborate on.
If no date-times are provided, all usage data will be returned.
}
\details{
The data returned by \code{get_usage()} includes all content types. For Shiny
content, the \code{timestamp} indicates the \emph{start} of the Shiny session.
Additional fields for Shiny and non-Shiny are available respectively from
\code{\link[=get_usage_shiny]{get_usage_shiny()}} and \code{\link[=get_usage_static]{get_usage_static()}}. \code{get_usage_shiny()} includes a
field for the session end time; \code{get_usage_static()} includes variant,
rendering, and bundle identifiers for the visited content.
When possible, however, we recommend using \code{get_usage()} over
\code{get_usage_static()} or \code{get_usage_shiny()}, as it is faster and more efficient.
}
\examples{
\dontrun{
client <- connect()
# Fetch the last 2 days of hits
usage <- get_usage(client, from = Sys.Date() - 2, to = Sys.Date())
# Fetch usage after a specified date and convert to a data frame.
usage <- get_usage(
client,
from = as.POSIXct("2025-05-02 12:40:00", tz = "UTC")
)
# Fetch usage for a specific content item
usage <- get_usage(client, content_guid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
# Fetch all usage
usage <- get_usage(client)
# Convert to tibble or data frame
usage_df <- tibble::as_tibble(usage)
# Skip unnesting if tidyr is not installed
usage_df <- as.data.frame(usage, unnest = FALSE)
}
}
\seealso{
\code{\link[=as.data.frame.connect_list_hits]{as.data.frame.connect_list_hits()}}, \code{\link[=as_tibble.connect_list_hits]{as_tibble.connect_list_hits()}}
}