User Activity¶
RStudio Connect records different types of user activity for different types of content.
-
Content - records information about each visit.
This includes all content types other than Shiny applications.
The
GET /instrumentation/content/visits
API gives details about visits to content.Sample code is in this recipe.
-
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.
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.
- Obtain the server URL and API Key from environment variables.
- Call the "Get shiny app usage" endpoint to get the first page. See the API Documentation for more information.
- 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.
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
/instrumentation/content/visits
content visit API
to page through information about content visits. Information is returned in pages
following the keyset pagination model.
The keyset pagination recipe explains how to perform multiple, paged requests.
- Obtain the server URL and API Key from environment variables.
- Call the "Get content visits" endpoint to get the first page. See the API Documentation for more information.
- 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.
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) }