使用 .NET 获取所有 Google 分析事件
Fetching All Google Analytics Events with .NET
我想获取在给定时间范围内生成的所有 Google 分析事件。我知道如何获取指标,但我认为这不一样。我对每个事件都特别感兴趣——时间戳、标签、类别等。这有可能吗?我正在使用 .NET 和 Google Analytics v3.
分析报告 API 无法满足您的需求。 Analytics Reporting API gives dimensions and metrics, it does not report back to you the raw events (hits) you have sent to GA. What might help you is BigQuery Export for Analytics.
但重要的是要了解您试图用 GA 事件数据回答哪些问题? API 确实有时间维度,例如 ga:datehourminute
。也许你可以从现有的 API.
中得到答案
如果您要分析的内容不一定是传统的网络或应用程序分析,或者至少不是 GA 提供的那些,也许使用其他 logs storage mechanism 会更适合您的应用程序。
可以:添加维度 ga:EventCategory、ga:EventAction、ga:EventLabel 和 ga:Date 以及指标 ga:TotalEvents 和 ga:EventValue。这returns就是我要的信息。在 .NET 中,我是这样实现的:
private const string _appName = "Some Name";
private const string _metrics = "ga:TotalEvents,ga:EventValue";
private const string _dimensions = "ga:EventCategory,ga:EventAction,ga:EventLabel,ga:Date";
using (var certificate = new X509Certificate2(_keyFilePath, _password, X509KeyStorageFlags.Exportable))
{
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(this._serviceAccountEmail) { Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly } }
.FromCertificate(certificate));
using (var service = new AnalyticsService(new BaseClientService.Initializer() { ApplicationName = _appName, HttpClientInitializer = credential }))
{
var request = service.Data.Ga.Get("ga:" + _profileId, _startDate.ToString("yyyy-MM-dd"), _endDate.ToString("yyyy-MM-dd"), _metrics);
request.Dimensions = _dimensions;
request.MaxResults = _maxResults;
var data = request.Execute();
//do something with data
}
}
我想获取在给定时间范围内生成的所有 Google 分析事件。我知道如何获取指标,但我认为这不一样。我对每个事件都特别感兴趣——时间戳、标签、类别等。这有可能吗?我正在使用 .NET 和 Google Analytics v3.
分析报告 API 无法满足您的需求。 Analytics Reporting API gives dimensions and metrics, it does not report back to you the raw events (hits) you have sent to GA. What might help you is BigQuery Export for Analytics.
但重要的是要了解您试图用 GA 事件数据回答哪些问题? API 确实有时间维度,例如 ga:datehourminute
。也许你可以从现有的 API.
如果您要分析的内容不一定是传统的网络或应用程序分析,或者至少不是 GA 提供的那些,也许使用其他 logs storage mechanism 会更适合您的应用程序。
可以:添加维度 ga:EventCategory、ga:EventAction、ga:EventLabel 和 ga:Date 以及指标 ga:TotalEvents 和 ga:EventValue。这returns就是我要的信息。在 .NET 中,我是这样实现的:
private const string _appName = "Some Name";
private const string _metrics = "ga:TotalEvents,ga:EventValue";
private const string _dimensions = "ga:EventCategory,ga:EventAction,ga:EventLabel,ga:Date";
using (var certificate = new X509Certificate2(_keyFilePath, _password, X509KeyStorageFlags.Exportable))
{
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(this._serviceAccountEmail) { Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly } }
.FromCertificate(certificate));
using (var service = new AnalyticsService(new BaseClientService.Initializer() { ApplicationName = _appName, HttpClientInitializer = credential }))
{
var request = service.Data.Ga.Get("ga:" + _profileId, _startDate.ToString("yyyy-MM-dd"), _endDate.ToString("yyyy-MM-dd"), _metrics);
request.Dimensions = _dimensions;
request.MaxResults = _maxResults;
var data = request.Execute();
//do something with data
}
}