# How to Track Usage in Dash App

**URL:** <https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059>\
**Category:** Dash Python\
**Created:** [August 9, 2019, 5:08pm UTC](https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059 "2019-08-09T17:08:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meg](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@meg](https://community.plotly.com/u/meg)\
**Post date:** [August 9, 2019, 5:08pm UTC](https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059/1 "2019-08-09T17:08:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![russellthehippo](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/russellthehippo/32/25312_2.png) [@russellthehippo](https://community.plotly.com/u/russellthehippo)\
**Post date:** [August 9, 2019, 7:22pm UTC](https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059/2 "2019-08-09T19:22:54Z")

</div>

@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/](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:

```auto
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. 🙂

---

<div class="post-metadata">

**Author:** ![meg](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@meg](https://community.plotly.com/u/meg)\
**Post date:** [August 12, 2019, 5:33pm UTC](https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059/3 "2019-08-12T17:33:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![russellthehippo](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/russellthehippo/32/25312_2.png) [@russellthehippo](https://community.plotly.com/u/russellthehippo)\
**Post date:** [August 12, 2019, 7:16pm UTC](https://community.plotly.com/t/how-to-track-usage-in-dash-app/27059/4 "2019-08-12T19:16:15Z")

</div>

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 is[client-side callbacks](https://community.plotly.com/t/dash-0-41-0-released/22131) or using [https://developer.mozilla.org/en-US/docs/Web/API/Page\_Visibility\_API](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.
