问题描述
我在写这个控制台应用程序来获得一些基本的谷歌Analytics(分析)API的数据的逻辑去。万物工作正常,但我wan't添加更多的指标来查询谷歌分析API。我wan't添加GA:新访问者,GA:reaccuringvisitors等我如何在下面的code实现这种
I'm writing this Console Application to get some basic "Google Analytics Api-data" logic going. Everythings works fine but i wan't to add some more metrics to query to google analytics API. I wan't to add ga:newvisitors, ga:reaccuringvisitors etc. How do i implement this in the code below?
下面是的code相关的段子:
Here's a relevant piece of the code:
var gas = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "TestGoogleAnalytics",
});
var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", "ga:visitors");
//Specify some addition query parameters
r.Dimensions = "ga:pagePath";
r.Sort = "-ga:visitors";
r.MaxResults = 10000;
//Execute and fetch the results of our query
Google.Apis.Analytics.v3.Data.GaData d = r.Execute();
foreach (KeyValuePair<string, string> kvp in d.TotalsForAllResults)
{
Console.WriteLine("Antal Besök:" +" " + kvp.Value);
}
Console.WriteLine(d.TotalsForAllResults.Keys + " = " + d.TotalsForAllResults.Values);
Console.ReadLine();
感谢
推荐答案
指标是GET请求的最后一个项目只将它们分开用逗号隔开。
Metrics are the last item in the get request just separate them with a comma.
var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", "ga:visitors,ga:newvisitors,ga:reaccuringvisitors");
可能是easer阅读这种方式:
Might be easer to read this way:
string Metrics = "ga:visitors,ga:newvisitors,ga:reaccuringvisitors";
var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", Metrics);
请确保您的姓名权的不看我的权利,但我没有检查:的。
make sure you have the names right those don't look right to me but I didn't check: Dimension and metric reference .
更新: GA:新访问者辗转回到2009年我找不到任何提及GA:reaccuringvisitors。确保您的请求正确的衡量标准。
Update: ga:newvisitors was removed back in 2009. I cant find any reference to ga:reaccuringvisitors. Make sure your requesting the correct metrics.
这篇关于检索从谷歌Analytics(分析)API数据与.NET,多个指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!