Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tracking for returning anonymous users #142 #157

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

arunkodati77
Copy link
Contributor

Closes #142

Changes description

  • Added new argument 'track_anonymous_user' (TRUE by default) to telemetry$start_session().
  • if username is null and track_anonymous_user = TRUE then a cookie will be set in users browser.
  • When there is no session user or Shiny_Proxy_User then we will first look for the shiny_user_cookie cookie in users browser (will make sure cookie is a hexa-decimal key generated using 'sha256' algorithm.
  • if not found, cookie value is generated using :
    cookie_string <- paste0(session$request$HTTP_USER_AGENT, session$request$REMOTE_ADDR, Sys.time()) cookie_value <- digest::digest(cookie_string, algo = "sha256")
    Note:
  • Cookie expires in 365 days.
  • In the ShinyProxy environment, tracking anonymous users presents a challenge when the application.yml configuration file for ShinyProxy is set with authentication: none. Under this setting, ShinyProxy assigns a random hash to each session as a makeshift user identifier, which is accessible in Shiny applications via the Sys.getenv("SHINYPROXY_USERNAME") command. Refer Official Documentation. This could be easily resolved by adding a condition , if (Sys.getenv("SHINYPROXY_USERNAME") == <<random_hash>> ) then set the cookie. But what if shinyproxy user itself is a Random hash?

@arunkodati77 arunkodati77 requested a review from averissimo March 16, 2024 19:53
@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 49 lines in your changes are missing coverage. Please review.

Project coverage is 30.48%. Comparing base (6136a33) to head (a813c33).

❗ Current head a813c33 differs from pull request most recent head 80407e8. Consider uploading reports for the commit 80407e8 to get more accurate results

Files Patch % Lines
R/telemetry.R 0.00% 32 Missing ⚠️
R/ui_elements.R 0.00% 17 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #157      +/-   ##
==========================================
- Coverage   31.33%   30.48%   -0.85%     
==========================================
  Files          16       16              
  Lines        1436     1476      +40     
==========================================
  Hits          450      450              
- Misses        986     1026      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@averissimo averissimo self-assigned this Mar 18, 2024
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality works great! I've tested it locally.

I've found some improvements on the code, let's discuss them 😄

ps. can you assign yourself to the original issue? (this flags that you're working on it)

R/telemetry.R Outdated Show resolved Hide resolved
R/telemetry.R Show resolved Hide resolved
R/telemetry.R Outdated Show resolved Hide resolved
R/telemetry.R Outdated Show resolved Hide resolved
R/telemetry.R Outdated Show resolved Hide resolved
R/telemetry.R Outdated Show resolved Hide resolved
R/telemetry.R Outdated Show resolved Hide resolved
R/ui_elements.R Outdated Show resolved Hide resolved
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you preferred to implement the changes here directly instead of using #159

Good job on using htmltools::htmlDependency, but it seemed like you overlooked some of the other aspects of the PR:

  • LICENSE file (this needs to be distributed with js-cookie.min.js, otherwise we might be in breach of the license)

Optional (but I think they can be included here):

  • Use of shiny::singleton to prevent injection of repeated <script> tags
  • Minor optimization of ID using shiny::NS instead of glue::glue

R/ui_elements.R Outdated Show resolved Hide resolved
R/ui_elements.R Outdated Show resolved Hide resolved
inst/js/js.cookie.min.js Outdated Show resolved Hide resolved
arunkodati77 and others added 3 commits March 21, 2024 20:55
1) moved js.cookie.min.js to a seperate folder and added LICENSE file
2) Used shiny::singleton() over <script> to load the tags only once at app start.
3) remove glue() near Namespace variable and used NS()
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Tested it out again and works like it should.

I left one last optional suggestion. Feel free to accept it or not.

R/telemetry.R Outdated Show resolved Hide resolved
@arunkodati77 arunkodati77 merged commit bfbce9c into main Mar 27, 2024
8 checks passed
@arunkodati77 arunkodati77 deleted the feature/#142-track-anonymous-user branch March 27, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add tracking of returning anonymous users
3 participants