Google Analytics for Shiny tabPanel

120 views
Skip to first unread message

Thomas

unread,
Jan 29, 2015, 9:26:00 AM1/29/15
to shiny-...@googlegroups.com
Hi there,

I've read myself through the great tutorial here. However, my knowledge of jQuery equals to zero. Is there a way to track, if users click on a tabPanel?

Thanks for any help.
Thomas



Thomas

unread,
Jan 29, 2015, 10:37:54 AM1/29/15
to shiny-...@googlegroups.com
The Tutorial I tried to link to is this: http://shiny.rstudio.com/articles/google-analytics.html

Thomas

unread,
Jan 30, 2015, 6:54:00 AM1/30/15
to shiny-...@googlegroups.com
I tried this, but of course this does not work. My guess is that it has to be put into jquery...

shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tabsetPanel(
tabPanel
("Panel1", onclick="ga('send', 'event', 'click', 'link', 'Panel1Click', 1)", showOutput("PlotPanel1", 'dimple')),

tabPanel
("Panel2", onclick="ga('send', 'event', 'click', 'link', 'Panel1Click', 2)", showOutput("PlotPanel2", 'dimple')
))))))

Geoffrey

unread,
Dec 2, 2016, 3:00:54 PM12/2/16
to Shiny - Web Framework for R
Hey Tom, did you ever get this to work?

Debashis Paul

unread,
Jan 18, 2017, 4:19:44 PM1/18/17
to Shiny - Web Framework for R
Anybody get this to work ?
thanks 


On Friday, January 30, 2015 at 6:54:00 AM UTC-5, tom wrote:

Lukas Lundström

unread,
Jan 20, 2017, 9:24:50 AM1/20/17
to Shiny - Web Framework for R
For me it works with

tags$script("$('ul.nav-tabs').on('click', 'li', function(e) { ga('send', 'event', 'widget', 'nav-tabs link', $(e.currentTarget).children('a').data('value'));});")

It need to be in the end of your ui, or at least come after you defined your tabset, and google-analytics.js need to be loaded before. It sends the name (stored in 'data-value') of the clicked tabPanel to ga.

adding following to google-analytics.js should also work, but I haven't tested it and might be a bit less efficient as it listens to the whole document.

$(document).on('click', ''ul.nav-tabs' > li', function(e) { ga('send', 'event', 'widget', 'nav-tabs link', $(e.currentTarget).children('a').data("value")); });


/Lukas

Debashis Paul

unread,
Jan 20, 2017, 1:43:55 PM1/20/17
to Shiny - Web Framework for R
Thanks Lucas. 
We already get this work with InnerText . But thanks and appreciate your response.
This will be helpful for anybody has this weird issue until Shiny fix and add the id on tabpanel items. 
Reply all
Reply to author
Forward
0 new messages