October 5, 2016

How to Add Mixpanel or Google Analytics on a Shiny App Correctly?

Before you start reading this post, I recommend to read this blog on shiny.rstudio.com about how to add a Google Analytics to your shiny app. It's vey likely that you followed all the steps on the blog but it did not work out. 

3 steps are missing in the blog post on rstudio website. I will walk you step by step about adding Mixpanel on shiny correctly:



1) You must put the mixpanel.js and google_analytics.js into a folder named "www". You need to put all the images and javascript files into this folder. You cannot name it to capital "WWW" or "Myfolder". The folder name has to be www.

The files structure of an shiny app should be like as below:



2) When it comes to using dashboardpage, you have to put  "tags$head(tags$script(src="mixpanel.js"))" inside the dashboardbody. Function includeScript might not work so you can use the default function src to extract the files.

dashboardPage(
     
   dashboardHeader(title = "Dashboard")
  ,sidebar
  ,dashboardBoday(tags$head(tags$script(src="mixpanel.js")))
  ,skin = "blue"

)

3) If you have internet access and run the app locally on R Studio, the Mixpanel or Google Analytics website should receive the traffic immediately. If there's no visitor after you refresh page, please try it again.

1 comment: