question

ted avatar image
ted asked

How to get a player's total playing time?

I want to get a specific player's total playing time, just like Steam show I played a game for 48 hours.

How to do it?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Rick Chen avatar image
Rick Chen answered

Here is a workaround:

  • Create a Cloud Script function that records the player’s last start-game time in their Player Data. When clients start the game, they call this function.
  • Create another Cloud Script function that calculates the elapsed time since the last start-game time and add this duration to the total play time (another Player Data). When client quit the game, they call this function to record their total play time. If it is the first time calling this function, i.e. no “total play time” in their Player Data, you can set the “total play time” to equal to the elapsed time in Player Data.

If you are using the PlayFab Unity SDK, you can also calculate the play time with the following events

  1. client_session_start
  2. client_focus_change

. Please refer to this document for more detail: Sessions - PlayFab | Microsoft Learn.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.