Search code examples
c#google-analytics-api

Specifying OrderBys on RunReportRequest object using Google Analytics Data API (Beta)


Using C#'s Google.Analytics.Data.V1Beta nuget package, how do I set the OrderBys when creating a RunReportRequest object? The property has only { get; } and no set. Perhaps this is not available in the Beta version?

var request = new RunReportRequest
{
    Property = $"properties/xxx",
    Metrics = { new Metric { Name = "screenpageviews" }, },
    Dimensions = { new Dimension { Name = "pagepath" }, },    
    DateRanges = { dateRange },
    // OrderBys
};

Solution

  • It's a RepeatedField having an Add(), so you can use collection intializer syntax:

    OrderBys = { new OrderBy(), }
    

    Just as you do in the rest of your code (and please post code as text, not as screenshot).

    You can also find code by searching for "OrderBys" in their repo.