Skip to content

Commit 12a78bd

Browse files
committed
Added plausible tracker for anonymous nb of users and countries, plus number of clicks to "Run simulations"
1 parent c98deee commit 12a78bd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

R/mod_tool_server.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ mod_tool_server <- function(id, rv) {
375375

376376
observeEvent(input$btn_run_mcs, {
377377

378+
## PLAUSIBLE - Send a Plausible event named "run_mcs" ----
379+
session$sendCustomMessage("plausible", list(event = "run_mcs"))
380+
378381
## + 3.1.1 Move to tabset RES ----
379382
# updateTabsetPanel(
380383
# session = session,

R/shiny_run_mocaredd.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ shiny_run_mocaredd <- function(...) {
9494
});
9595
"
9696

97+
## + Javascript custom handler for PLAUSIBLE =================================
98+
js_plausible_event <- "
99+
window.addEventListener('shiny:connected', function() {
100+
Shiny.addCustomMessageHandler('plausible', function(data) {
101+
if (window.plausible) {
102+
window.plausible(data.event); // send event
103+
}
104+
});
105+
});
106+
"
107+
97108

98109
## + UI Elements =============================================================
99110

@@ -134,6 +145,16 @@ shiny_run_mocaredd <- function(...) {
134145
shinyjs::useShinyjs(),
135146
shinyWidgets::useSweetAlert(),
136147
shiny.i18n::usei18n(i18n),
148+
tags$head(
149+
# Load Plausible tracker
150+
tags$script(
151+
async = NA, defer = NA,
152+
src = "https://plausible.io/js/script.js",
153+
`data-domain` = "openforis-shiny.shinyapps.io/mocaredd"
154+
),
155+
# Custom event handler for Shiny + Plausible
156+
tags$script(HTML(js_plausible_event))
157+
),
137158
tags$head(tags$script(HTML(js_activate_tab))),
138159
tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "assets/style.css")),
139160
htmltools::htmlDependency(

0 commit comments

Comments
 (0)