private CountlyEventModel ReportViewDuration(bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(_lastView) && string.IsNullOrWhiteSpace(_lastView)) { return(null); } var viewSegment = new ViewSegment { Name = _lastView, Segment = CountlyHelper.OperationSystem, HasSessionBegunWithView = hasSessionBegunWithView }; var customEvent = new CountlyEventModel(CountlyEventModel.ViewEvent, (JsonConvert.SerializeObject(viewSegment, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, })), (DateTime.Now - _lastViewStartTime).TotalMilliseconds ); return(customEvent); }
public async Task <CountlyResponse> RecordOpenViewAsync(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { return(new CountlyResponse { IsSuccess = false, ErrorMessage = "View name is required." }); } var currentViewSegment = new ViewSegment { Name = name, Segment = Constants.UnityPlatform, Visit = 1, Exit = 0, Bounce = 0, HasSessionBegunWithView = hasSessionBegunWithView }; if (!_viewToLastViewStartTime.ContainsKey(name)) { _viewToLastViewStartTime.Add(name, DateTime.UtcNow); } Debug.Log("[ViewCountlyService] RecordOpenViewAsync: " + name); var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, currentViewSegment.ToDictionary()); return(await _eventService.RecordEventAsync(currentView)); }
public async Task <CountlyResponse> ReportCloseViewAsync(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { return(new CountlyResponse { IsSuccess = false, ErrorMessage = "View name is required." }); } var currentViewSegment = new ViewSegment { Name = name, Segment = Constants.UnityPlatform, Visit = 0, Exit = 1, HasSessionBegunWithView = hasSessionBegunWithView }; double?duration; duration = _lastViewStartTime != null ? (DateTime.UtcNow - _lastViewStartTime.Value).TotalSeconds : (double?)null; if (duration.HasValue) { duration = Math.Round(duration.Value); } var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, currentViewSegment.ToDictionary(), 1, null, duration); return(await _eventService.RecordEventAsync(currentView)); }
public async Task <CountlyResponse> ReportOpenViewAsync(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { return(new CountlyResponse { IsSuccess = false, ErrorMessage = "View name is required." }); } var currentViewSegment = new ViewSegment { Name = name, Segment = Constants.UnityPlatform, Visit = 1, HasSessionBegunWithView = hasSessionBegunWithView }; _lastViewStartTime = DateTime.UtcNow; var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, currentViewSegment.ToDictionary()); return(await _eventService.RecordEventAsync(currentView)); }
/// <summary> /// Stop tracking a view /// </summary> /// <param name="name"></param> /// <param name="hasSessionBegunWithView"></param> /// <returns></returns> public async Task <CountlyResponse> RecordCloseViewAsync(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { return(new CountlyResponse { IsSuccess = false, ErrorMessage = "View name is required." }); } var currentViewSegment = new ViewSegment { Name = name, Segment = Constants.UnityPlatform, Visit = 0, Exit = 1, Bounce = 0, HasSessionBegunWithView = hasSessionBegunWithView }; double?duration = null; if (_viewToLastViewStartTime.ContainsKey(name)) { var lastViewStartTime = _viewToLastViewStartTime[name]; duration = (DateTime.UtcNow - lastViewStartTime).TotalSeconds; _viewToLastViewStartTime.Remove(name); } if (_config.EnableConsoleLogging) { Debug.Log("[ViewCountlyService] RecordCloseViewAsync: " + name + ", duration: " + duration); } var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, currentViewSegment.ToDictionary(), 1, null, duration); return(await _eventService.RecordEventAsync(currentView)); }
private CountlyEventModel GetLastView(bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(_lastView) && string.IsNullOrWhiteSpace(_lastView)) { return(null); } var viewSegment = new ViewSegment { Name = _lastView, Segment = Constants.UnityPlatform, HasSessionBegunWithView = hasSessionBegunWithView }; var customEvent = new CountlyEventModel( CountlyEventModel.ViewEvent, viewSegment.ToDictionary(), null, null, (DateTime.Now - _lastViewStartTime.Value).TotalSeconds); return(customEvent); }
/// <summary> /// Reports a view with the specified name and a last visited view if it existed /// </summary> /// <param name="name"></param> /// <param name="hasSessionBegunWithView"></param> public void ReportView(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("Parameter name is required."); } var events = new List <CountlyEventModel>(); var lastView = ReportViewDuration(); if (lastView != null) { events.Add(lastView); } var currentViewSegment = new ViewSegment { Name = name, Segment = CountlyHelper.OperationSystem, Visit = 1, HasSessionBegunWithView = hasSessionBegunWithView }; var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, (JsonConvert.SerializeObject(currentViewSegment, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, })), null ); events.Add(currentView); CountlyEventModel.StartMultipleEvents(events); _lastView = name; _lastViewStartTime = DateTime.Now; }
/// <summary> /// Reports a view with the specified name and a last visited view if it existed /// </summary> /// <param name="name"></param> /// <param name="hasSessionBegunWithView"></param> public async Task <CountlyResponse> ReportViewAsync(string name, bool hasSessionBegunWithView = false) { if (string.IsNullOrEmpty(name)) { return(new CountlyResponse { IsSuccess = false, ErrorMessage = "View name is required." }); } var events = new List <CountlyEventModel>(); var lastView = GetLastView(); Debug.Log("[ReportViewAsync] get last view: " + lastView); if (lastView != null) { events.Add(lastView); } var currentViewSegment = new ViewSegment { Name = name, Segment = Constants.UnityPlatform, Visit = 1, HasSessionBegunWithView = hasSessionBegunWithView }; var currentView = new CountlyEventModel(CountlyEventModel.ViewEvent, currentViewSegment.ToDictionary()); events.Add(currentView); _lastView = name; _lastViewStartTime = DateTime.Now; return(await _eventService.ReportMultipleEventsAsync(events)); }