User Activity#
RStudio Connect records different types of user activity for different types of content.
Content type | User activity recorded |
---|---|
Content | Records information about each visit.
|
Shiny applications | Records information about each visit and the length of that visit.
|
Info
An R Markdown dashboard using instrumentation APIs can be found in the sol-eng/usage GitHub repository.
User Activity: Shiny Applications#
This recipe uses the GET
/v1/instrumentation/shiny/usage
endpoint to
page through Shiny application usage. Information is returned in pages
following the keyset pagination model.
Info
The keyset pagination recipe explains how to perform multiple, paged requests.
Workflow#
- Obtain the RStudio Connect server URL and API Key from environment variables.
- Call the
GET /v1/instrumentation/shiny/usage
endpoint to get the first page. - Parse the response using
httr::content
. - Print the current page.
- Repeat steps 1 through 3 until there are no more results. Note also
that the
paging.next
property in the response is the URL of the next page.
Here is an example of the workflow:
library(httr)
# The CONNECT_SERVER URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
# Request a page of up to 25 usage records.
resp <- GET(
paste0(connectServer, "__api__/v1/instrumentation/shiny/usage?limit=25"),
add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp)
# print the current page results
print(payload$results)
# Continue to page through additional records
# while we have a "next" reference
while(!is.null(payload$paging[["next"]])) {
resp <- GET(
payload$paging[["next"]],
add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp)
# print the results on this page
print(payload$results)
}
User Activity: Content#
This recipe uses the GET
/v1/instrumentation/content/visits
endpoint to page through information about content visits. Information is returned in pages
following the keyset pagination model.
Note
The keyset pagination recipe explains how to perform multiple, paged requests.
Workflow#
- Obtain the server URL and API Key from environment variables.
- Call the
GET /v1/instrumentation/content/visits
endpoint to get the first page. - Parse the response using
httr::content
. - Print the current page.
- Repeat steps 1 through 3 until there are no more results. Note also
that the
paging.next
property in the response is the URL of the next page.
Here is an example of the workflow:
library(httr)
# The CONNECT_SERVER URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
# Request a page of up to 25 visitation records.
resp <- GET(
paste0(connectServer, "__api__/v1/instrumentation/content/visits?limit=25"),
add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp)
# print the current page results
print(payload$results)
# Continue to page through additional records
# while we have a "next" reference
while(!is.null(payload$paging[["next"]])) {
resp <- GET(
payload$paging[["next"]],
add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp)
# print the results on this page
print(payload$results)
}