User Activity

RStudio Connect records different types of user activity for different types of content.

  1. Shiny applications - records information about each visit and the length of that visit.

The GET /instrumentation/shiny/usage API provides details about Shiny application sessions.

Sample code is in this recipe.

  1. Static and rendered content - records information about each visit.

Static content includes plots and other HTML content not rendered by the server. Rendered content includes R Markdown documents, parameterized R Markdown, and Jupyter notebooks.

The GET /instrumentation/content/visits API gives details about visits to static and rendered content.

Sample code is in this recipe.

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 /instrumentation/shiny/usage Shiny usage API to page through Shiny application usage. Information is returned in pages following the keyset pagination model.

The keyset pagination recipe explains how to perform multiple, paged requests.

  1. Obtain the server URL and API Key from environment variables.
  2. Call the "Get shiny app usage" endpoint to get the first page. See the API Documentation for more information.
  3. Parse the response using httr::content.
  4. Print the current page.
  5. 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.
# set up environment
library(httr)
# Note that the connectServer string must have a trailing slash
connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

# get usage information
authHeader <- add_headers(Authorization = paste("Key", apiKey))
usageURL <- paste0(connectServer, "__api__/v1/instrumentation/shiny/usage?limit=25")
resp <- GET(usageURL, authHeader)
payload <- content(resp)
# print first 25!
print(payload$results)
# now step through the remaining audit logs
while(!is.null(payload$paging[["next"]])) {
  resp <- GET(payload$paging[["next"]], authHeader)
  payload <- content(resp)
  # print the next 25
  print(payload$results)
}

User Activity: Rendered and Static Content

This recipe uses the GET /instrumentation/content/visits content visit API to page through information about static and rendered content visits. Information is returned in pages following the keyset pagination model.

The keyset pagination recipe explains how to perform multiple, paged requests.

  1. Obtain the server URL and API Key from environment variables.
  2. Call the "Get rendered/static content visits" endpoint to get the first page. See the API Documentation for more information.
  3. Parse the response using httr::content.
  4. Print the current page.
  5. 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.
# set up environment
library(httr)
# Note that the connectServer string must have a trailing slash
connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

# get visit information
authHeader <- add_headers(Authorization = paste("Key", apiKey))
hitsURL <- paste0(connectServer, "__api__/v1/instrumentation/content/visits?limit=25")
resp <- GET(hitsURL, authHeader)
payload <- content(resp)
# print first 25!
print(payload$results)
# now step through the remaining audit logs
while(!is.null(payload$paging[["next"]])) {
  resp <- GET(payload$paging[["next"]], authHeader)
  payload <- content(resp)
  # print the next 25
  print(payload$results)
}