コード例 #1
0
        public GraphStats articleTraffic([FromBody] trafficInput input)
        {
            ArticleController use     = new ArticleController();
            user_traffic      traffic = new user_traffic();
            GraphStats        total   = new GraphStats()
            {
                dateTime = "", sessions = "", earned = 0
            };

            traffic.non_premium = 0;
            traffic.premium     = 0;

            get_admin_gid_Result res;
            DateTime             join;

            using (var data = db.get_joining_date(input.id))
            {
                join = data.FirstOrDefault <get_joining_date_Result>().date;
            }
            using (var data = db.get_admin_gid(input.site_url))
            {
                res = data.FirstOrDefault <get_admin_gid_Result>();
            }

            Authorization auth = new Authorization(res.Email);

            var result  = auth.service.Data.Ga.Get("ga:" + res.ga_id, use.convertDate(join), use.convertDate(System.DateTime.Now), input.session);
            var result1 = auth.service.Data.Ga.Get("ga:" + res.ga_id, use.convertDate(join), use.convertDate(System.DateTime.Now), input.session);

            result.Filters  = "ga:landingPagePath=@" + use.convertUrl(input.url, input.site_url) + ";ga:campaign=@" + input.uid + ";ga:medium=@referral";
            result1.Filters = "ga:landingPagePath=@" + use.convertUrl(input.url, input.site_url) + ";ga:campaign=@" + input.uid + ";ga:medium=@referral;ga:country=@Canada";
            try
            {
                var session_result  = result.Execute();
                var session_result1 = result1.Execute();
                int count           = (int)session_result.TotalResults;
                if (count != 0)
                {
                    IList <string> l = session_result.Rows[0];
                    traffic.non_premium = traffic.non_premium + long.Parse(l[0]);
                }
                traffic.non_premium = traffic.non_premium + 0;
                int count2 = (int)session_result1.TotalResults;
                if (count2 != 0)
                {
                    IList <string> lp = session_result1.Rows[0];
                    traffic.premium = traffic.premium + long.Parse(lp[0]);
                }
                traffic.premium = traffic.premium + 0;

                traffic.non_premium = traffic.non_premium - traffic.premium;

                total.earned   = total.earned + GetEarned(traffic.premium.ToString(), "premium") + GetEarned(traffic.non_premium.ToString(), "non-premium");
                total.sessions = (traffic.premium + traffic.non_premium).ToString();
            }catch (Exception e)
            {
            }
            return(total);
        }