How to Track Usage in Dash App

Hi,

I am interested to know whether there is a built-in function to track usage of the app? If not, any workarounds? Can anyone share your experience implementing it?

Thanks,
Meg

@meg how I have done this in two ways. The first is with flask.logging which is built into the dash.Dash app object. https://flask.palletsprojects.com/en/1.0.x/logging/

How I continue to do it, is by creating a logging function that logs simple actions and values to SQLite:

def send_log(vals):
  try:
    c = sqlite3.connect('log.db')
    c.cursor.execute( 'insert into myapp_log (col1, col2, col3, col4) values (?,?,?,?)',vals)
    c.commit()
    c.close()
    return False
  except:
    return True

@app.callback(...)
def did_something(...)
    log = [ some, list, of, loggable, values ]
    if send_log(log):
        # handle error in some way

    # do normal callback function stuff
    ...
    return output

In this way I can log things happening in a very straightforward, lightweight way.

EDIT: and I get precisely the log values that I want, and the ability to easily visualize them with a portable SQLite database without having some other process running. KISS. :slight_smile:

1 Like

Thanks @russellthehippo.

As far as I know, dash_enterprise_auth provides the capability of returning username and other user info as well. Have you implemented something to log the time that users stayed on the app?

Thanks.

I have not done this; this is tough to do. My first thought is to track user interaction events and come up with some arbitrary logic to define what a session’s “start” and “end” are.

My next thought isclient-side callbacks or using https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API or something similar.

My last thought is…Google Analytics can do this for you.

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online