@@ -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