question

Walentin avatar image
Walentin asked

Player Session Tracking - client_session_start & client_focus_change

After going over:

https://github.com/PlayFab/UnitySDK/blob/master/ExampleMacProject/Assets/PlayFabSDK/Entity/ScreenTimeTracker.cs

https://learn.microsoft.com/en-us/gaming/playfab/api-references/events/

I noticed that there is no client_session_end.

When a player connects to my game server, I want to manually trigger client_session_start via the server api and when they disconnect I want to trigger client_session_end. Is there a dedicated event for this or do I need to use client_focus_change (FocusState = false, FocusStateDuration = PlayerPlayDuration)?

If the latter is the case, will that show up correctly in the Trends Average duration dashboard?

analyticsPlayStream
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

·
Neils Shi avatar image
Neils Shi answered

In fact, the API call Unity SDK uses to track Session Duration/Focus change is WriteEvents instead of WritePlayerEvent. Therefore, in order to track the info you want, you can refer to the ScreenTimeTracker.cs and use WriteEvents to implement it. Since you want to implement this feature in server side, you may need to disable the focus time reporting (which in Game Manager - Title setting – Data Collection) so that the client cannot generate related events that conflict with the average duration.

2 comments
10 |1200

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

Walentin avatar image Walentin commented ·

Thanks for the answer!

To clarify: WriteEvents is just a batch version of WritePlayerEvent? If I then want to use it on server-side, is a title secret key a valid X-EntityToken?

This would also address my concern of "dangling" player sessions - the ones that have a client_session_start but no client_focus_change. I was originally going to write one event when a player joins and then another once they leave. This can go wrong if the server crashes or there are network issues.

However, using WriteEvents I can just submit both events when a player leaves - manually calculating & submitting the session duration.

0 Likes 0 ·
Neils Shi avatar image Neils Shi Walentin commented ·

The API WritePlayerEvent focuses on writing player-based event into PlayStream, and the API WriteEvents is used to write batches of entity-based events to PlayStream, you should refer to the ScreenTimeTracker.cs and use WriteEvents to implement your function. And if you want to use WriteEvents on server-side, you should use title level Entity Token, you can get it via calling API GetEntityToken.

1 Like 1 ·

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.