Search Unity

How to get total playtime from the API?

Discussion in 'Unity Analytics' started by GripAnalytics, Dec 14, 2016.

  1. GripAnalytics

    GripAnalytics

    Joined:
    Dec 9, 2016
    Posts:
    2
    Hello,
    I have generated the appRunning report trying to calculate total play time since there is the ‘duration’ metric. However, from my data export, I see multiple appRunning events for a particular userid-sessionid. For example, a given user for a particular session, there are several records with different durations.

    When does an appRunning event fire?

    How do I calculate total time play from the raw data?

    I am leveraging the documentation from https://docs.unity3d.com/Manual/UnityAnalyticsRawDataExport.html.

    Thanks,
     
  2. rayw24

    rayw24

    Joined:
    May 23, 2016
    Posts:
    52
    @GripAnalytics appRunning events are sent whenever the app is sent out of focus (e.g. paused or stopped).

    The easiest way to calculate total time play from the raw data is to check the 'duration' field of the appRunning events and grab the largest duration for each unique session ID and aggregate them for a given player and/or date range. A new session is created if the game is opened after 30 minutes of inactivity, which also creates a new and unique session ID.

    I hope
     
  3. GripAnalytics

    GripAnalytics

    Joined:
    Dec 9, 2016
    Posts:
    2
    @rayw24 Thanks for the response.

    I suspected that was the methodology as well, but doing that, it didn't produce the same results as the UI. That's why I was wondering if there were any added nuances that I was not aware of. I exported the data from the AppRunning and took the max of every userid-sessionid pairing (which is equivalent to just using sessionid). The sum of those values is larger than what I see through the dashboard (eg. 3.28K seconds in the UI vs 5.16K seconds in the export).

    I do believe the export is in UTC and my configuration is set to EST. I have taken that into account. Thoughts?

    Another support person got back to me suggesting that I needed data from the appStart events but he was kind of vague of the actual methodology to calculate play time. If you have any other ideas, please let me know.
     
  4. UrsHanselmann

    UrsHanselmann

    Joined:
    Jan 28, 2014
    Posts:
    13
    @GripAnalytics: have you been able to solve this?

    I'm having the same issue, and my guess is, that it's related to a lot of data being skewed. For us, there are a lot of sessions in appRunning that clearly have unrealistic values for the session duration:



    Also there seem to be multiple appRunning events for the same session id, with a lot of time apart.


    It would be great if someone from the Analytics team could share some insights on how these events are filtered when processing for the Analytics Dashboard, so we can get at least a little closer to the reported total playtime there using the raw events.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are still looking into this. Apparently the duration is being recorded occasionally as an epoch absolute timestamp instead of duration (elapsed time).
     
  6. UrsHanselmann

    UrsHanselmann

    Joined:
    Jan 28, 2014
    Posts:
    13
    @JeffDUnity3D: Thanks for looking into this.

    In some cases it seems to be an epoch timestamp like you guessed (it's very close to the reported device time in the ts field). However, for other sessions it's off by quite a bit:


    Is there any easy filter we could use to get rid of the faulty rows, something you use internally for calculating the total times on the Analytics dashboard?

    I have already tried just dropping all rows with a duration larger than some arbitrary amount (e.g. 86400) - but the total calculated duration per day are still nowhere near the one displayed in the dashboard.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @ChrisHanselmann How frequently does this happen for you? We are seeing this behavior on less than .01% of users, and we have not yet been able to reproduce. We are using this data in the Dashboard too, but the large values are limited to max integer size. When you use Charles, do you see it happen in your testing?
    https://support.unity3d.com/hc/en-us/articles/115002917683