Track User on shiny app

shiny

#1

How can I track user activity on my application?
I have provided them authentication to my app and want to track their activity on my app.


#2

What authentication system are you using?


#3

Shinyapp.io provides user authentication on standard purchase plan.
My question actually was do they also provide user activity tracking


#4

Have you seen this article?
https://shiny.rstudio.com/articles/usage-metrics.html


#5

Yes I've managed to setup google analytics with user tracking for a shiny app hosted on shinyapps.io with authentication following the article @jcblum posted above.

However I found I had to make some changes to the code suggested in the article for it to work. See this thread for more info.

You have to send the pageview after the userId has been set otherwise the pageview won't be associated with the logged in shiny user. The javascript tracking code below is working for me:

// Initial Tracking Code
(function(i,s,o,g,r,a,m){
  i['GoogleAnalyticsObject']=r;
  i[r]=i[r] || 
  function(){
    (i[r].q=i[r].q||[]).push(arguments);
  },i[r].l=1*new Date();
  a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];
  a.async=1;
  a.src=g;
  m.parentNode.insertBefore(a,m);
})(window,document,'script',
  'https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-YOUR-GA-TRACKING-NUMBER-HERE', 'auto');

// User Tracking Code
$(document).one('shiny:idle', function() {
  ga('set','userId', Shiny.user);
  ga('send', 'pageview');
});

Save your GA code in a file called ga.js in the root directory of your shiny app then call it into the app in your UI script with

tags$head(includeScript("ga.js")),

You also have to set up a specific view in google analytics with User-ID turned on. When that view is setup you should be able to see user metrics in the AUDIENCE -> USER EXPLORER section of your google analytics dashboard.