您可以在 Google Analytics(分析)中的帐户中找到个人资料 ID:
sign in -> Admin -> Profile Settings
这是youtube上的视频。它使用旧设计,但路径相同
如果有帮助,我将使用以下操作按 newsID 获取新闻页面的统计信息(页面浏览量):
public ActionResult Stats(int id)
{
string userName = "myusername";
string passWord = "mypassword";
string profileId = "ga:12345678";
string pagepath = "~/Home/Details/" + id;
AnalyticsService asv = new AnalyticsService("GData-Version: 1.8");
asv.setUserCredentials(userName, passWord);
const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";
var service = new AnalyticsService("WebSiteAnalytics");
service.setUserCredentials(userName, passWord);
DataQuery query = new DataQuery(dataFeedUrl);
query.Ids = profileId;
query.Metrics = "ga:pageviews";
query.GAStartDate = "2011-05-01";
query.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd");
query.Filters = "ga:pagePath=" + pagepath;
Uri url = query.Uri;
// Send our request to the Analytics API and wait for the results to
// come back.
var feed = asv.Query(query);
var totalEntrys = feed.Entries[0];
ViewData["Total"] = ((DataEntry)(totalEntrys)).Metrics[0].Value;
return PartialView(feed.Entries);
}