Ricardo Peres
Ricardo Peres

Reputation: 14535

Fetching All Google Analytics Events with .NET

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.

Upvotes: 2

Views: 1275

Answers (2)

Ricardo Peres
Ricardo Peres

Reputation: 14535

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
    }
}

Upvotes: 1

Matt
Matt

Reputation: 5168

What you are looking for is not possible with the Analytics Reporting API. The 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.

But it is important to understand what questions you are trying to answer with GA event data? The API does have time dimensions, for example ga:datehourminute. Perhaps you can get at the answers with the existing API.

If what you are tying to analyze is not necessarily traditional web or app analytics, or at least not those provided by GA perhaps using some other logs storage mechanism would better suit your application.

Upvotes: 1

Related Questions