//For this you will have to add some dll in your .net project ie using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Analytics.v3; using Google.Apis.Analytics.v3.Data; using Google.Apis.Services; public ActionResult GetAnalyticsData(string GroupType, string date_from, string date_to) { try { AnalyticsService gas = AuthenticateUser(); // Creating our query DataResource.GaResource.GetRequest r = gas.Data.Ga.Get("ga:88028792", date_from, date_to, "ga:visits, ga:pageviews, ga:users, ga:newUsers, ga:sessions"); //Hour,Day,Week,Month if (GroupType == "Hour") { r.Dimensions = "ga:nthHour"; } else if (GroupType == "Day") { r.Dimensions = "ga:nthDay"; } else if (GroupType == "Week") { r.Dimensions = "ga:nthWeek"; } else if (GroupType == "Month") { r.Dimensions = "ga:nthMonth"; } //d: Execute and fetch the results of our query GaData d = r.Execute(); List<TotalsForAllResults> tr = new List<TotalsForAllResults>(); List<CustomeData> cd = new List<CustomeData>(); foreach (var item in d.Rows) { CustomeData mydata = new CustomeData(); // mydata.CreatedDate = item[0].ToString(); mydata.visits = Convert.ToInt32(item[1]); mydata.pageviews = Convert.ToInt32(item[2]); mydata.users = Convert.ToInt32(item[3]); mydata.newUsers = Convert.ToInt32(item[4]); mydata.sessions = Convert.ToInt32(item[5]);
}
Preetika Jul 28 '14 at 9:04 2014-07-28 09:04
source share