Get authenticated username from javascript

Hi,

For a Shiny app published in RSC, it is possible to get the username in js using the Shiny object. My question is if there is a way to get the a similar information for a RMarkdown document if the content is open by someone authenticated in RSC.

I tried to peek in the objects available in the global scope but I couldn't find anything relevant. Anyone has any tips on this matter? Thanks!

Hi @joseluizferreira,

Can you say a little more about what you're trying to accomplish? If it's a static R Markdown document, then there isn't a runtime to pass the current user to, but there may be a way to do what you're trying.

Hi @alexkgold,

I am trying to develop a tracking framework for content in RSC that extends a bit the default usage endpoint from its api. To give a more concrete example, I want to replicate the session_start and session_end information available for Shiny apps in static content. The only missing piece at this point is how to retrieve the username for logged users.

Hey @joseluizferreira! Thanks for the background there!

Unfortunately, tracking session_start and session_stop on a static file is potentially rife with extreme outliers as many users (myself included) leave static files open in a browser tab for long periods of time. This is also the reason that we have not done more work to this end in the product - it is data that has the potential to be high in volume and low in value.

Rather, when a user "refreshes the page," for instance, then you get a new "content hit" that shows the user has requested the file again.

In any case, if you want to continue down this path, you are delving into the realm of Google Analytics and related products (a few of which are open source: https://matomo.org and http://www.openwebanalytics.com/ ) that do pure-JavaScript analytics and data capture.

Unfortunately, today there is not a nice way for you to access the user's Connect username from a pure-browser-side javascript context. However, we are happy to share this feedback with developers for consideration in a future release! Please keep us posted how you progress here!! We are always interested to hear how Connect is being used in various environments!

1 Like

Hi @cole,

Thanks for sharing your thoughts on this! You are right that the example I gave is not the best one, especially if some sort of polling is used. Of course this is only one of the many events that I intend to track with this, but they all suffer from this issue that I can't assign a known user to them.

I will take a look on the open-source products that you shared and try to find some inspiration. One of the ideas of creating such tool was exactly to avoid external products for many reasons and RSC provides us already a way to quickly implement a web API that can do the job in the scale of our content.

It's a pity that there isn't a nice way to do it (what about an ugly?) and please share the feedback with the developers.

Thanks a lot!