I would like do fetch all Google Analytics events produced in a given time frame. I know how to get metrics, but I don't think it's the same. I am specifically interested in each event - timestamp, label, category, etc. Is this at all possible? I am using .NET and Google Analytics v3.
It is possible: add dimensions ga:EventCategory, ga:EventAction, ga:EventLabel and ga:Date and metrics ga:TotalEvents and ga:EventValue. This returns the information I want. In .NET, I achieve it as this:
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
}
}