/// <summary> /// 结束记录一个页面的访问 /// </summary> /// <param name="pageId">页面 Id</param> public void EndPage(string pageId) { var begunPage = this.terminate.activities.First(a => a.activityId == pageId); if (begunPage == null) { throw new ArgumentOutOfRangeException("can not find page with id is " + pageId); } begunPage.du = AVAnalytics.UnixTimestampFromDateTime(DateTime.Now) - begunPage.ts; }
/// <summary> /// 记录一个页面的访问时长 /// </summary> /// <param name="name">页面名称</param> /// <param name="duration">访问时长,毫秒</param> /// <returns>页面 Id</returns> public string TrackPage(string name, long duration) { var newActivityId = string.Format("activity_{0}", Guid.NewGuid().ToString()); var newActivity = new AVAnalyticsActivity() { activityId = newActivityId, du = duration, name = name, ts = AVAnalytics.UnixTimestampFromDateTime(DateTime.Now) }; this.terminate.activities.Add(newActivity); return newActivityId; }
/// <summary> /// 记录一个自定义事件 /// </summary> /// <param name="name">事件名称</param> /// <param name="tag">事件标签</param> /// <param name="attributes">自定义参数字典</param> /// <returns>事件 Id</returns> public string TrackEvent(string name, string tag, IDictionary<string, object> attributes) { var newEventId = string.Format("event_{0}", Guid.NewGuid().ToString()); var newEvent = new AVAnalyticsEvent(this.SessionId) { eventId = newEventId, attributes = attributes, name = name, tag = tag, ts = AVAnalytics.UnixTimestampFromDateTime(DateTime.Now), du = 0, }; [email protected](newEvent); return newEventId; }
/// <summary> /// 结束记录一个持久化的自定义事件 /// </summary> /// <param name="eventId">事件 Id</param> /// <param name="attributes">自定义参数字典</param> /// <remarks>End 传入的 attributes 会合并 Begin 传入的 attributes 的键值对,如果有 key 重复,以 End 传入的为准</remarks> public void EndEvent(string eventId, IDictionary<string, object> attributes = null) { var begunEvent = [email protected](e => e.eventId == eventId); if (begunEvent == null) { throw new ArgumentOutOfRangeException("can not find event whick id is " + eventId); } begunEvent.du = AVAnalytics.UnixTimestampFromDateTime(DateTime.Now) - begunEvent.ts; if (attributes != null) { if (begunEvent.attributes == null) begunEvent.attributes = new Dictionary<string, object>(); foreach (var kv in attributes) { begunEvent.attributes[kv.Key] = kv.Value; } } }