User Activity
Posit Connect records information about visits to hosted content. Shiny applications and other content types track different details about those visits. This page contains recipes for both kinds of activity data.
In addition to the recipes provided here, an R Markdown dashboard using the instrumentation APIs can be found in the sol-eng/connect-usage GitHub repository.
User Activity: Shiny Applications
Connect records information about each visit to a Shiny application and the length of that visit.
This recipe uses the GET /v1/instrumentation/shiny/usage
endpoint to page through R and Python Shiny application usage. Information is returned in pages following the keyset pagination model.
The keyset pagination recipe explains how to perform multiple, paged requests.
Workflow
- Obtain the Posit 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.
- The
paging.next
response field indicates the URL for the next page. Load, parse, and print each additional page untilpaging.next
isNULL
.
Here is an example of the workflow:
library(httr)
# The CONNECT_SERVER URL must have a trailing slash.
<- Sys.getenv("CONNECT_SERVER")
connectServer <- Sys.getenv("CONNECT_API_KEY")
connectAPIKey
# Request a page of up to 25 usage records.
<- GET(
resp paste0(connectServer, "__api__/v1/instrumentation/shiny/usage?limit=25"),
add_headers(Authorization = paste("Key", connectAPIKey))
)<- content(resp)
payload # 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"]])) {
<- GET(
resp $paging[["next"]],
payloadadd_headers(Authorization = paste("Key", connectAPIKey))
)<- content(resp)
payload # print the results on this page
print(payload$results)
}
User Activity: Content
Connect records information about each visit for non-Shiny application 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.
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.
- The
paging.next
response field indicates the URL for the next page. Load, parse, and print each additional page untilpaging.next
isNULL
.
Here is an example of the workflow:
library(httr)
# The CONNECT_SERVER URL must have a trailing slash.
<- Sys.getenv("CONNECT_SERVER")
connectServer <- Sys.getenv("CONNECT_API_KEY")
connectAPIKey
# Request a page of up to 25 visitation records.
<- GET(
resp paste0(connectServer, "__api__/v1/instrumentation/content/visits?limit=25"),
add_headers(Authorization = paste("Key", connectAPIKey))
)<- content(resp)
payload # 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"]])) {
<- GET(
resp $paging[["next"]],
payloadadd_headers(Authorization = paste("Key", connectAPIKey))
)<- content(resp)
payload # print the results on this page
print(payload$results)
}