Search code examples
c#unity-game-enginesteamworks-api

How to get how many hours has users spent playing my game? Steamworks API


How to get how many hours has users spent playing my game? Using Steamworks API and C# in Unity. I have went through a documentation but haven't found anything like that, and thinking that I am missing something.

I should've just went with a simple script that logs minutes played in its own game, but it's too late for that. If anyone can give me a hit or point me a right direction, I'd really appreciate it.


Solution

  • You might still have a chance to get it to work. As far as I know, there's a way to get the total hours played (as shown in the Gameplay stats) by using the deprecated Community XML Data:

    Player Game Stats

    To retrieve game stats, you will need the game's Steam Community name. Developers can contact Valve to obtain the community name for their game.

    You can retrieve stats and achievements for a player per game using the player's 64-bit Steam ID with: Format: http://steamcommunity.com/profiles/[SteamID]/stats/[CommunityGameName]/?xml=1

    Example: http://steamcommunity.com/profiles/76561197968575517/stats/L4D/?xml=1

    In the example you can see the hoursPlayed field on the bottom of the image:

    hoursPlayed field

    Now, the problem obviously is that this is deprecated and Steam advices you to use the web APIs whenever possible. However, I haven't seen a way to access this data through the web API so I think that this is your best bet without rolling out a custom way of tracking playtime.