question

Bailey Brown avatar image
Bailey Brown asked

Is there a way to get player logins data in client

As part of a 'User Session' event i use the PlayFabClientAPI to request profile & account info in order to add details such as display name and location to my event data.

As an extension I'm now looking to send the number of logins the user has made within the last 30 days as part of my event data, this is already available within PlayFab under Players>Logins (Player Logins - PlayFab | Microsoft Docs) but in terms of accessing this data via the API and sending in an event i cant seem to find a solution in the PlayFabClientAPI.GetPlayerProfile , PlayFabClientAPI.GetAccountInfo ect documentation.

If anyone knows if this is possible or any other way of easily getting this number for an event please let me know

Player Data
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

·
Ivan Cai avatar image
Ivan Cai answered

Whether you call the Login API or GetPlayerProfile, only the time of LastLogin will be returned instead of the number of logins. In your case, if you want to get the number of logins within the last 30 days, you can navigate to Data Explorer(advanced) in the game manager.

Please refer to the following json statement for query:

['events.all']
|where FullName_Name == 'player_logged_in'
|where Entity_Id == 'Entity id in Login API Response'
|where Timestamp > ago(30d)

For more detailed operation information about data explorer(advanced), please refer to https://docs.microsoft.com/en-us/gaming/playfab/features/insights/data-explorer/getting-started-with-data-explorer-advanced.

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

Bailey Brown avatar image Bailey Brown commented ·

Hi Ivan, thanks for the response, the query provided gives the last 30 days of logins like I'm looking for but i need to combine this with data from my user session event in order to help create a table.

Currently I'm using a custom "user session" event to create a table with data about each user session via a query eg

Name , Email, Company, Session_Start_Time , Session_End_Time ect

I'm looking to add the logins for the user in the last 30 days as an extra column, my initial plan was to calculate / get this in client and pass as event data. Ive tried a similar query to the one provided as a function and planned to call it for each row with the users id as input, however this is not possible as the response must be scalar.

Is there a way i could run the query you have provided as a function for each user session event where i use the users id of that event instance to get their 30 day count?

Ive tried this but i get the error "Non-scalar result for projected attribute". My understanding is that the function cant be called with a changing input eg countLogins("Bailey") vs countLogins(EventData.Name) . However i need to get a different count for each session event


0 Likes 0 ·
Ivan Cai avatar image Ivan Cai ♦ Bailey Brown commented ·

Can you provide the error query for reproducing?

0 Likes 0 ·
Bailey Brown avatar image Bailey Brown Ivan Cai ♦ commented ·

Here's the query i tried where i get the error : Non-scalar result for projected attribute

let count30Days = (nameToSearchFor:string  ) {
['events.all']
|where Timestamp > ago(30d) 
| where  FullName_Name  == "User_Session" and EventData.Name contains nameToSearchFor 
| count};
['events.all']
|where Timestamp > ago(30d)  
| where  FullName_Name  == "User_Session" 
| project  Name=EventData.Name, 
Login_Time=EventData.Login_Time_Formatted, 
Logout_Time=EventData.Logout_Time_Formatted,  
Session_Length=EventData.Session_Length , 
Email=EventData.Email ,
Company=EventData.Company, 
Country=EventData.Country,  
City=EventData.City, 
First_Login=EventData.First_Login_Formatted, 
Last_Login=EventData.Last_Login_Formatted,
30DayCount= count30Days (EventData.Name) 


After looking into user functions User-defined functions - Azure Data Explorer i think this may not be possible due to one of the listed limitations "User-defined functions can't pass into toscalar() invocation information that depends on the row-context in which the function is called."

This is why my initial hope was to be able to get this 30 day data in client via api call and send as event data for easy projecting

0 Likes 0 ·
Show more comments

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.