We're looking at surfacing to the user their time spent in app and noticed Amplitude already by default tracks this, but getting a successful response from the dashboard API (User Activity) has not been fruitful (usage_time is currently returning null from this endpoint even though usage time shows up fine in the dashboard, and it’s unclear why).
There might also be a better endpoint for what we want as I'm sure fetching past activity for a user is pretty expensive - we only want the usage_time property for the user. Is there a lighter-weight, non rate-limited endpoint we could use?
Best answer by Saish RedkarView original
Thanks for reaching out here
@kennyw Usage Time is calculated by:
sum( max(event_time in session) - session_id)i.e sum of usage time of all sessions, in milliseconds. For additional information about the dashboard API visit our developer docs here. I’m going to share this with our support team who can assist with the second part of your question.
From what details you have provided above, here are couple of points -
Or is it empty?
Ideally, if you are capturing session id ( not equal to -1 ) on all your events via Amplitude SDKs then you should be seeing that metric populated ( based on aggregation of user’s total lifetime spent in the app )
If you are using a custom session definition, then you might not be able to see Total Sessions/ usage time in the user profile.
AFAIK, the user activity endpoint is the only way of getting the
"usage_time"for an individual user.
We want to fetch usage time on a per-user per-session basis, so we can see ourselves hitting the rate limit for the user activity endpoint pretty easily. Do you know if there are any future plans for supporting a user property endpoint or any workarounds for our use case? Thank you!
That’s weird. Ideally, the user profile’s Total Sessions and Usage Time should be mapping to the user activity response datapoints of "num_sessions" and "usage_time". Not sure what’s the issue here.
Maybe Amplitude Support team can help out here if that’s a bug.
Re. the per-user per-session basis requirement, I don’t know if there is any endpoint which does that for now. The user activity endpoint looks the easiest option. All the other relevant ones are for aggregate session metrics.
You can try creating the desired session chart and fetch some data using the existing chart endpoint if that fits your case.
num_sessions, num_events, and usage_time are null from the endpoint (I’ve tested for multiple users), and those fields populate fine on the user profile.
This is what the end of the response object looks like (omitted other fields).