public void addGoogleAnalyticsStats(GoogleAnalyticsStats gastats)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             session.Save(gastats);
             transaction.Commit();
         }
     }
 }
 /// <addGoogleAnalyticsStats>
 /// Add a new Google Analytics Stats
 /// </summary>
 /// <param name="gastats">Set Values in a GoogleAnalyticsStats Class Property and Pass the same Object of GoogleAnalyticsStats Class.(Domain.GoogleAnalyticsStats)</param>
 public void addGoogleAnalyticsStats(GoogleAnalyticsStats gastats)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action, to save data.
             session.Save(gastats);
             transaction.Commit();
         }//End Transaction
     }//End Session
 }
Exemplo n.º 3
0
        public DataTable getCountryAnalyticsApi(string profileId,Guid user)
        {
            DataTable dtAnalytics = new DataTable();
            try
            {
               
                Analytics objAlyt = new Analytics();
                oAuthTokenGa obj = new oAuthTokenGa();
                GoogleAnalyticsAccountRepository objGaAccRepo=new GoogleAnalyticsAccountRepository();
                GoogleAnalyticsStats objGaStats = new GoogleAnalyticsStats();
                GoogleAnalyticsStatsRepository objGaStatsRepo=new GoogleAnalyticsStatsRepository();
                GoogleAnalyticsAccount objGaAcc = objGaAccRepo.getGoogelAnalyticsAccountHomeDetailsById(profileId, user);

                string strRefresh = obj.GetAccessToken(objGaAcc.RefreshToken);
                    if (!strRefresh.StartsWith("["))
                        strRefresh = "[" + strRefresh + "]";
                    JArray objArray = JArray.Parse(strRefresh);
                    foreach (var itemRefresh in objArray)
                    {
                        objGaAcc.AccessToken = itemRefresh["access_token"].ToString();
                    }
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.LoadXml(objAlyt.getAnalyticsData(objGaAcc.GaProfileId, "metrics=ga:visits&dimensions=ga:country", "2013-01-01", "2013-07-15", objGaAcc.AccessToken));
                    dtAnalytics= getdatafromXml(xDoc);
                    for (int i = 0; i < dtAnalytics.Rows.Count; i++)
                    {
                        objGaStats.EntryDate = DateTime.Now;
                        objGaStats.GaAccountId = objGaAcc.GaAccountId;
                        if (dtAnalytics.Rows[i]["title"].ToString().Contains("ga:country"))
                            objGaStats.gaCountry = dtAnalytics.Rows[i]["title"].ToString().Substring(11);
                        objGaStats.gaVisits = dtAnalytics.Rows[i]["ga:visitors"].ToString();
                        objGaStats.GaProfileId = objGaAcc.GaProfileId;
                        objGaStats.Id = Guid.NewGuid();
                        objGaStats.UserId = user;
                        if (!objGaStatsRepo.checkGoogleAnalyticsDateStatsExists(objGaAcc.GaProfileId, "country", dtAnalytics.Rows[i]["title"].ToString(), user))
                            objGaStatsRepo.addGoogleAnalyticsStats(objGaStats);
                        else
                            objGaStatsRepo.updateGoogleAnalyticsStats(objGaStats);
                    }
            }
            catch (Exception Err)
            {
                Console.Write(Err.StackTrace);
            }
            return dtAnalytics;
        }
 public void updateGoogleAnalyticsStats(GoogleAnalyticsStats fbaccount)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
        public string getDayWiseAnalytics(string gaAccountId)
        {
            string strYearVal = string.Empty;
            try
            {
                User user = (User)HttpContext.Current.Session["LoggedUser"];

                GoogleAnalyticsStats objGaStats = new GoogleAnalyticsStats();
                GoogleAnalyticsStatsRepository objGaStatsRepo = new GoogleAnalyticsStatsRepository();
                ArrayList arrCountry = objGaStatsRepo.getGoogleAnalyticsStatsYearById(gaAccountId, user.Id, 7, "day");

                string strYear = string.Empty;
                string strVal = string.Empty;
                int cnt = 0;
                foreach (var item in arrCountry)
                {
                    cnt++;
                    Array temp = (Array)item;
                    strYear = strYear + temp.GetValue(3).ToString() + ",";
                    strVal = strVal + temp.GetValue(8).ToString() + ",";
                }
                if (cnt < 7)
                {
                    for (int j = 0; j < 7 - cnt; j++)
                    {
                        strYear = strYear + "0,";
                        strVal = strVal + "0,";
                    }
                }
                strYearVal = strYear.Substring(0, strYear.Length - 1) + "@" + strVal.Substring(0, strVal.Length - 1);
            }
            catch (Exception Err)
            {
                Console.Write(Err.StackTrace);
            }
            return strYearVal;
        }