4

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.

Daahrien
  • 10,190
  • 6
  • 39
  • 71
papi
  • 379
  • 7
  • 25
  • Sorry, I don't have an actual answer, but I am pretty sure it is possible because Rocksmith 2014 has achievements that trigger based on 10, 100, 200, etc. hours. I imagine they are polling that information, but I guess it is possible they logged it themselves. – TyCobb Aug 18 '17 at 20:52
  • @TyCobb, yeah, it's either possible or they have done it themselves. – papi Aug 18 '17 at 21:00
  • You should ask these sort of questions over at gamedev.net –  Aug 18 '17 at 21:01
  • @MickyD, never heard of that place. But thanks! – papi Aug 18 '17 at 21:03
  • There's also https://gamedev.stackexchange.com – TyCobb Aug 18 '17 at 21:04
  • 1
    You don't need the Steamworks API to do this. Are you open to solutions without Steamworks API? – Programmer Aug 18 '17 at 21:27
  • Wut. Just log number of hours played (don't rely on system clock differential) and trigger achievement unlock? – Mardoxx Aug 18 '17 at 21:47

1 Answers1

3

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.

Timo Salomäki
  • 7,099
  • 3
  • 25
  • 40
  • Hmm, that does look interesting and might take quiet some time. Thanks for the info! I'll wait for a few other replies to see what other people have to say; And if nothing, this will be a chosen answer! – papi Aug 18 '17 at 21:03
  • @berdyev It seems really weird to me that this stat wouldn't be available from the web API so hopefully someone turns up with a better answer! – Timo Salomäki Aug 18 '17 at 21:04
  • 2
    Do we have any new update on this? I too want to be able to get hours played from a user on every game – CDrosos Jun 17 '20 at 08:01
  • 1
    I'm also wondering if there is any new update on this. Can this functionality be accomplished through the Web API or some other method now? – Guy Mar 09 '21 at 02:10