/// <summary> /// Queues the initialization event. /// </summary> public void OnPlayFabMultiPlayerManagerInitialize() { gameSessionID = Guid.NewGuid(); EventsModels.EventContents eventInfo = new EventsModels.EventContents(); eventInfo.Name = "unity_client_initialization_completed"; eventInfo.EventNamespace = eventNamespace; eventInfo.Entity = entityKey; eventInfo.OriginalTimestamp = DateTime.UtcNow; var payload = new Dictionary <string, object>(); SetCommonTelemetryProperties(payload); payload["ClientInstanceId"] = gameSessionID; payload["PartyVersion"] = Version.PartyNativeVersion; payload["PartyUnityVersion"] = Version.PartyUnityVersion; payload["UnityVersion"] = Application.unityVersion; eventInfo.Payload = payload; if (entityKey.Id == null) { eventsPending.Enqueue(eventInfo); // we need to call this only once, during initialization, once logged in and entity has been retrieved, we will no longer call this. StartCoroutine(WaitUntilEntityLoggedIn(delayBetweenEntityLoggedIn)); } else { eventsRequests.Enqueue(eventInfo); } }
/// <summary> /// Start session, the function responsible for creating SessionID and gathering information about user and device /// </summary> /// <param name="playFabUserId">Result of the user's login, represent user ID</param> public void ClientSessionStart(string entityId, string entityType, string playFabUserId) { gameSessionID = Guid.NewGuid(); entityKey.Id = entityId; entityKey.Type = entityType; EventsModels.EventContents eventInfo = new EventsModels.EventContents(); eventInfo.Name = "client_session_start"; eventInfo.EventNamespace = eventNamespace; eventInfo.Entity = entityKey; eventInfo.OriginalTimestamp = DateTime.UtcNow; var payload = new Dictionary <string, object> { { "UserID", playFabUserId }, { "DeviceType", SystemInfo.deviceType }, { "DeviceModel", SystemInfo.deviceModel }, { "OS", SystemInfo.operatingSystem }, { "ClientSessionID", gameSessionID }, }; eventInfo.Payload = payload; eventsRequests.Enqueue(eventInfo); // Fake a focus-on event at the time of the first login: OnApplicationFocus(true); }
/// <summary> /// Queues errors for sending it server /// </summary> /// <param name="errorCode">error code associated with the error</param> /// <param name="type">Type of error defined in unity layer</param> public void OnPlayFabPartyError(uint errorCode, PlayFabMultiplayerManagerErrorType type) { EventsModels.EventContents eventInfo = new EventsModels.EventContents(); // TODO update the table name for unity errors eventInfo.Name = "unity_client_api_error_occurred"; eventInfo.EventNamespace = eventNamespace; eventInfo.Entity = entityKey; eventInfo.OriginalTimestamp = DateTime.UtcNow; var payload = new Dictionary <string, object>(); SetCommonTelemetryProperties(payload); payload["ClientInstanceId"] = gameSessionID; payload["ErrorCode"] = errorCode; payload["ErrorType"] = type; eventInfo.Payload = payload; if (entityKey.Id == null) { eventsPending.Enqueue(eventInfo); } else { eventsRequests.Enqueue(eventInfo); } }
/// <summary> /// Sends events to server. /// </summary> public void DoWork() { if (PlayFabSettings.staticPlayer.IsClientLoggedIn()) { // The events which are sent without login will only be in this queue intially. // Once login is done, the count should always be 0. while (eventsPending.Count > 0) { if (entityKey.Id == null) { return; } EventsModels.EventContents eventInfo = eventsPending.Dequeue(); eventInfo.Entity = entityKey; eventsRequests.Enqueue(eventInfo); } long currentTime = GetCurrentTimeInMilliseconds(); if (currentTime > lastErrorTimeInMillisecond + (retryCount * 1000)) { if (eventsRequests.Count > 0) { EventsModels.WriteEventsRequest request = new EventsModels.WriteEventsRequest(); request.Events = new List <EventsModels.EventContents>(); while ((eventsRequests.Count > 0) && (request.Events.Count < maxBatchSizeInEvents)) { EventsModels.EventContents eventInfo = eventsRequests.Dequeue(); request.Events.Add(eventInfo); } if (request.Events.Count > 0) { #if !UNITY_EDITOR eventApi.WriteTelemetryEvents(request, EventSentSuccessfulCallback, EventSentErrorCallback); #endif } } } } }
/// <summary> /// Sends events to server. /// </summary> public void Send() { if ((PlayFabClientAPI.IsClientLoggedIn()) && (isSending == false)) { isSending = true; EventsModels.WriteEventsRequest request = new EventsModels.WriteEventsRequest(); request.Events = new List <EventsModels.EventContents>(); while ((eventsRequests.Count > 0) && (request.Events.Count < maxBatchSizeInEvents)) { EventsModels.EventContents eventInfo = eventsRequests.Dequeue(); request.Events.Add(eventInfo); } if (request.Events.Count > 0) { PlayFabEventsAPI.WriteEvents(request, EventSentSuccessfulCallback, EventSentErrorCallback); } isSending = false; } }
/// <summary> /// Sends events to server. /// </summary> public void Send() { if ((ClientAPI.IsClientLoggedIn()) && (isSending == false)) { isSending = true; EventsModels.WriteEventsRequest request = new EventsModels.WriteEventsRequest(); request.Events = new List <EventsModels.EventContents>(); while ((eventsRequests.Count > 0) && (request.Events.Count < maxBatchSizeInEvents)) { EventsModels.EventContents eventInfo = eventsRequests.Dequeue(); request.Events.Add(eventInfo); } if (request.Events.Count > 0) { EventsAPI.WriteEvents(request.Events).FireForgetLog("Failed to send session data."); } isSending = false; } }
public override void Tick(UUnitTestContext testContext) { if (pubSub != null && pubSub.State == PersistentSocketState.Opened && DateTime.Now > nextWrite) { UpdateNextWriteTime(); EventsModels.WriteEventsRequest req = new EventsModels.WriteEventsRequest(); EventsModels.EventContents ec = new EventsModels.EventContents(); ec.Entity = new EventsModels.EntityKey(); ec.Entity.Id = _MyEntityKey.Id; ec.Entity.Type = _MyEntityKey.Type; ec.Name = testName; ec.EventNamespace = ns; ec.PayloadJSON = $"{{\"CurrentTime\" : \"{DateTime.Now}\"}}"; req.Events = new List <EventsModels.EventContents>(); req.Events.Add(ec); PlayFabEventsAPI.WriteEvents(req, null, null); } }
/// <summary> /// Gather information about user's focus. Calculates interaction durations. /// Name mimics MonoBehaviour method, for ease of integration. /// </summary> /// <param name="isFocused">State of focus</param> public void OnApplicationFocus(bool isFocused) { EventsModels.EventContents eventInfo = new EventsModels.EventContents(); DateTime currentUtcDateTime = DateTime.UtcNow; eventInfo.Name = "client_focus_change"; eventInfo.EventNamespace = eventNamespace; eventInfo.Entity = entityKey; double focusStateDuration = 0.0; if (initialFocus) { focusId = Guid.NewGuid(); } if (isFocused) { // start counting focus-on time focusOnDateTime = currentUtcDateTime; // new id per focus focusId = Guid.NewGuid(); if (!initialFocus) { focusStateDuration = (currentUtcDateTime - focusOffDateTime).TotalSeconds; // this check safeguards from manual time changes while app is running if (focusStateDuration < 0) { focusStateDuration = 0; } } } else { focusStateDuration = (currentUtcDateTime - focusOnDateTime).TotalSeconds; // this check safeguards from manual time changes while app is running if (focusStateDuration < 0) { focusStateDuration = 0; } // start counting focus-off time focusOffDateTime = currentUtcDateTime; } var payload = new Dictionary <string, object> { { "FocusID", focusId }, { "FocusState", isFocused }, { "FocusStateDuration", focusStateDuration }, { "EventTimestamp", currentUtcDateTime }, { "ClientSessionID", gameSessionID }, }; eventInfo.OriginalTimestamp = currentUtcDateTime; eventInfo.Payload = payload; eventsRequests.Enqueue(eventInfo); initialFocus = false; }