Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session start/stop events #328

Merged
merged 3 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ learnr 0.10.0.9000 (unreleased)

* `learnr`'s built-in tutorials now come with a description as part of the YAML header, with the intention of this being used in front-end software that catalogues available `learnr` tutorials on the system. ([#312](https://github.com/rstudio/learnr/issues/312))

* Add `session_start` and `session_stop` events. ([#311](https://github.com/rstudio/learnr/pull/328))

## Bug fixes

* Fixed a bug where broken exercise code created non-"length-one character vector". ([#311](https://github.com/rstudio/learnr/pull/311))
Expand Down
10 changes: 10 additions & 0 deletions R/events.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ video_progress_event <- function(session, video_url, time, total_time) {
save_video_progress(session, video_url, time, total_time)
}

session_start_event <- function(session) {
record_event(session = session,
event = "session_start",
data = list())
}

session_stop_event <- function(session) {
record_event(session = session,
event = "session_stop",
data = list())
}

debug_event_recorder <- function(tutorial_id,
tutorial_version,
Expand Down
3 changes: 3 additions & 0 deletions R/http-handlers.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ register_http_handlers <- function(session, metadata) {
identifiers = identifiers
)

# Now that we've initialized the session state, emit the start event
session_start_event(session)

session$userData$learnr_state("initialized")
# return identifers
list(
Expand Down
9 changes: 9 additions & 0 deletions R/initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ initialize_tutorial <- function() {
singleton = TRUE
)

# Register session stop handler
rmarkdown::shiny_prerendered_chunk(
'server',
sprintf('session$onSessionEnded(function() {
learnr:::session_stop_event(session)
})'),
singleton = TRUE
)

# set initialized flag to ensure single initialization
knitr::opts_knit$set(tutorial.initialized = TRUE)
}
Expand Down
14 changes: 13 additions & 1 deletion docs/publishing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ The `event` parameter is one of the following values:
<td>video_progress</td>
<td>User watched a segment of a video.</td>
</tr>
<tr class="odd">
<td>section_skipped</td>
<td>A section of the tutorial was skipped.</td>
</tr>
<tr class="even">
<td>session_start</td>
<td>A new session has been initiated</td>
</tr>
<tr class="odd">
<td>session_stop</td>
<td>A session has been terminated</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -289,7 +301,7 @@ The default tutorial and user identifiers are determined as follows:
<td>tutorial_version</td>
<td>1.0</td>
</tr>
<tr class="add">
<tr class="odd">
<td>user_id</td>
<td>Account name of server user executing the tutorial</td>
</tr>
Expand Down
24 changes: 24 additions & 0 deletions docs/publishing.html
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,30 @@ <h4>Event Recorder Function</h4>
User watched a segment of a video.
</td>
</tr>
<tr class="odd">
<td>
section_skipped
</td>
<td>
A section of the tutorial was skipped.
</td>
</tr>
<tr class="even">
<td>
session_start
</td>
<td>
A new session has been initiated
</td>
</tr>
<tr class="odd">
<td>
session_stop
</td>
<td>
A session has been terminated
</td>
</tr>
</tbody>
</table>
<p>The <code>data</code> parameter is an R list which provides additional data that varies depending on which <code>event</code> is being recorded.</p>
Expand Down