GithubHelp home page GithubHelp logo

galogger's Introduction

GAlogger - Log R Events and R Usage to Google Analytics

Easily track how R users use your application by sending pageviews or events to Google Analytics. Developed with the following use cases in mind

Track usage of your application

  • If someone visits a page in your web application (e.g. Shiny) or web service (e.g. RApache, Plumber), use this R package to send the page and title of the page which is visited so that you can easily see how visitors are using your application
  • Do you want to know which user inputs are set in your Shiny app, you can now collect these events easily with this R package

Track usage of your scripts / package usage / functions

  • Keep track on how your internal useRs are using your package (e.g. when a user loads your package or uses a specific function or webservice)
  • Do you want to keep track on the status of a long-running process or keep track of an error message if something failed.

Set-up

Get your UA tracking ID from Google Analytics (it looks like UA-XXXXX-Y) and indicate that you approve that data will be send to Google Analytics.

library(GAlogger)
ga_set_tracking_id("UA-25938715-4")
ga_set_approval(consent = TRUE)

Usage

Visits

Someone is visiting your app, great, log it is follows.

ga_collect_pageview(page = "/home")
ga_collect_pageview(page = "/simulation", title = "Mixture process")
ga_collect_pageview(page = "/simulation/bayesian")
ga_collect_pageview(page = "/textmining-exploratory")
ga_collect_pageview(page = "/my/killer/app")
ga_collect_pageview(page = "/home", title = "Homepage", hostname = "www.xyz.com")

Events

An event is happening in your app or R code, great, log it as follows.

ga_collect_event(event_category = "Start", event_action = "shiny app launched")
ga_collect_event(event_category = "Error", event_label = "convergence failed", event_action = "Oh no")
ga_collect_event(event_category = "Error", event_label = "Bad input", 
                 event_action = "send the firesquad", event_value = 911)
ga_collect_event(event_category = "Simulation", event_label = "Launching Bayesian multi-level model",
                 event_action = "How many simulations", event_value = 10)                 

Installation

Install the development version of the package with remotes::install_github("bnosac/GAlogger") Or install the ready-made R package from www.datatailor.be as follows.

install.packages("uuid")
install.packages("curl")
install.packages("GAlogger", repos = "http://www.datatailor.be/rcube", type = "source")

Advanced usage

At package startup, the package looks to 5 environment variables. Set these in your startup files .Rprofile/.Renviron or .bashrc if you want to avoid having to specify these in your R code itself.

  • GALOG_UA_TRACKINGID: the Google Analytics tracking ID
  • GALOG_UA_USERID: the identifier of the user of your application as known by you. E.g. someones name.
  • GALOG_UA_CLIENTID: an identifier in UUID format which anonymously and uniquely identifies a particular R user or device across different R sessions.
  • GALOG_HOSTNAME: the hostname which is used in ga_collect_pageview of not given in the argument hostname
  • GALOG_CONSENT: Set to the value of yes if you automatically want to give consent
Sys.setenv('GALOG_UA_TRACKINGID' = "UA-25938715-4")
Sys.setenv('GALOG_UA_USERID' = "datascientist-workstation-xyz")
Sys.setenv('GALOG_UA_CLIENTID' = "a5d1eeb6-0459-11e8-8912-134976ff196e")
Sys.setenv('GALOG_HOSTNAME' = "www.mywebapplication.org")
Sys.setenv('GALOG_CONSENT' = "yes")

library(GAlogger)
ga_collect_pageview(page = "/home")
ga_collect_event(event_category = "Waw", event_action = "I got visitors")

This package by itself does not send private information to Google Analytics, the R developer itself is responsible for making sure not to send any information which he/she does not want to see appearing in Google Analytics or he/she is not entitled to store elsewhere. If you do not trust this statement, just look at the R source code at https://github.com/bnosac/GAlogger/blob/master/R/pkg.R, it is pretty basic and is released under the Mozilla Public License 2.0 so you can see what id does.

Support in R application development

Need support in R application development? Contact BNOSAC: http://www.bnosac.be

galogger's People

Contributors

jwijffels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

galogger's Issues

Update doc

Event value is supposed to be an integer and not a string

event_value a character string of length 1 with the value of the event. This is optional.

You should update the doc and test the type

Client ID not picks up by GA

Thank you very much for your package. I have an issue wit the CLIENT_ID which does not get pick up bu Google Analytics. I am using:
ga_set_user_id(user_id = session$userData$app.login.name)
But GA still shows:
image

Do you know why?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.