question

developer-4 avatar image
developer-4 asked

How to analyze with client_focus_change?

Refer to the documentation: client focus change

1.

here comes a event contains:

PayloadJSON : {  
  FocusState : false ,   
  FocusStateDuration : 105.600207
}

does that mean, the user is out of our app for 105 seconds? (like switched to other app, or screen sleep?)

2.

and if the FocusState is true, what does it mean, what situation would be focus for 0 seconds?

PayloadJSON : {  
  FocusState : true ,   
  FocusStateDuration : 0
}

3.

Is it a good practice to use this event which focusState is true to calculate how long users focus on our app? any additional steps should I take before analyzing with this event set? For example, I want to delete those event mentioned in my point 2.

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

·
Seth Du avatar image
Seth Du answered

The session feature, generating the focus change events, is via calling WriteEvents API. When FocusState is false, it means the player the focus is not on your client since now and FocusStateDuration calculates the duration of last session. Meanwhile, when FocusState is true, it means that the player starts to focus on the client, the timer begins now and that’s why the duration is 0.

This feature is implemented only on Unity SDK and you may analyze the source codes of corresponding parts and create your own way to send focus change events if necessary.

5 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.

developer-4 avatar image developer-4 commented ·

Thank you for your detail reply! It helps. Here comes a situation which is hard to explain with your answer, please check the following picture.

The table is a sequence of focus events, ordered by sessionID and eventTimeStamp.

As you can see, the focus event emited in the same session, but why the fourth session duration is not continuous like previous three events? and why somtimes there is no focus true before focus false?

Thanks!

0 Likes 0 ·
developer-4 avatar image developer-4 commented ·

Also, how does playfab calculate the valid user focus time? Is it to caculate the focus instance (same focus ID in previous table image) with the complete pair of true and false focus state?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ developer-4 commented ·

I have reviewed the source code and sorry for the previous information, it is partially incorrect, which may cause your confusion.

  • When a player is logged in for the first time, session start will be sent and after that, client will wait for 5 seconds to send a "fake" focus-on event will be sent.
  • When Focus state is TRUE, mark the current time as last focus on time. The duration is calculated by "current time - last focus off time"
  • When Focus state is FALSE, the duration is calculated by "current time - last focus on time". Then mark the last focus off time.
  • Sending events is processed in a coroutine of Unity, which is asynchronous, hence the sequence may not be precise.

I will suggest monitoring the session changes for longer time, then analysing the data. The above is my brief understanding of session feature in Unity SDK and if you are interested in digging into it, please check the ScreenTimeTracker.cs file in Unity SDK. In addition, please feel free to let me know if there is anything incorrect in my statement. Thanks.

1 Like 1 ·
developer-4 avatar image developer-4 Seth Du ♦ commented ·

thanks for your generous reply, I really appreciate it!

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ developer-4 commented ·

Thanks for the feedback. I will check the Unity SDK and dig into it.

0 Likes 0 ·

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.