예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <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;
 }
예제 #3
0
 /// <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;
 }
예제 #4
0
        /// <summary>
        /// Tracks this application being launched. If the LaunchActivatedEventArgs
        /// parameter contains push data passed through from a Toast's "launch"
        /// parameter, then we extract and report information to correlate this
        /// application open with that push.
        /// </summary>
        /// <param name="launchArgs">The LaunchActivatedEventArgs available in an
        /// Application.OnLaunched override.</param>
        /// <returns>An Async Task that can be waited on or ignored.</returns>
        public static Task TrackAppOpenedAsync(ILaunchActivatedEventArgs launchArgs)
        {
            // Short-circuit if the Launch event isn't from an actual app launch.
            // We'll still phone home if the launchArgs passed in is null, though,
            // so here we only check for a non-Launch ActivationKind.
            if (launchArgs != null && launchArgs.Kind != ActivationKind.Launch)
            {
                return(((Task)null).Safe());
            }

            object pushHash;
            IDictionary <string, object> contentJson = AVPush.PushJson(launchArgs);

            contentJson.TryGetValue("push_hash", out pushHash);
            return(AVAnalytics.TrackAppOpenedWithPushHashAsync((string)pushHash));
        }
예제 #5
0
        /// <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;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 开启统计功能
        /// </summary>
        /// <param name="device">客户端参数,例如硬件,网络,版本,渠道等信息</param>
        /// <returns></returns>
        public static Task<bool> InitAsync(IAVAnalyticsDevice device)
        {
            if (device == null)
                throw new NotImplementedException("InitAsync need an IAVAnalyticsDevice implementment");

            return CurrentUserController.GetCurrentSessionTokenAsync(CancellationToken.None).OnSuccess(t =>
            {
                return AVAnalytics.AnalyticsController.GetPolicyAsync(t.Result, CancellationToken.None);
            }).Unwrap().OnSuccess(s =>
            {
                var settings = s.Result;
                var current = new AVAnalytics();
                current.CloudParameters = settings["parameters"] as IDictionary<string, object>;
                current.Enable = bool.Parse(settings["enable"].ToString());
                current.Policy = int.Parse(settings["policy"].ToString());
                current.deviceHook = device;
                current.Reset();
                Current = current;
                return current.Enable;
            });
        }
예제 #7
0
 /// <summary>
 /// Tracks this application being launched.
 /// </summary>
 /// <returns>An Async Task that can be waited on or ignored.</returns>
 public static Task TrackAppOpenedAsync()
 {
     return(AVAnalytics.TrackAppOpenedWithPushHashAsync());
 }