'Google.Analytics.Data.V1Alpha - property "daterange" read only
https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries I have run the sample code of the quickstart in c# and this works fine. But I want to use it in an older project that's written in vb.net.
when I create the RunReportRequest object, the properties seem to be readonly...
Dim entity As New Entity()
entity.PropertyId = propertyId
Dim m As New Metric
m.Name = "activeUsers"
Dim metrics = New Google.Protobuf.Collections.RepeatedField(Of Metric)
metrics.Add(m)
Dim d As New Dimension
d.Name = "city"
Dim dimensions As New Google.Protobuf.Collections.RepeatedField(Of Dimension)
dimensions.Add(d)
Dim r As New DateRange
r.StartDate = "2021-01-01"
r.EndDate = "2021-04-31"
Dim range As New Google.Protobuf.Collections.RepeatedField(Of DateRange)
range.Add(r)
Dim request As New RunReportRequest
With request
.Entity = entity
.Dimensions = dimensions
.Metrics = metrics
.DateRanges = range
End With
when I hit F5 on the "RunReportRequest" object:
<DebuggerNonUserCode>
Public Shared ReadOnly Property Descriptor As MessageDescriptor
<DebuggerNonUserCode>
Public Shared ReadOnly Property Parser As MessageParser(Of RunReportRequest)
'
' Summary:
' Date ranges of data to read. If multiple date ranges are requested, each response
' row will contain a zero based date range index. If two date ranges overlap, the
' event data for the overlapping days is included in the response rows for both
' date ranges. In a cohort request, this `dateRanges` must be unspecified.
<DebuggerNonUserCode>
Public ReadOnly Property DateRanges As RepeatedField(Of DateRange)
'
' Summary:
' The row count of the start row. The first row is counted as row 0. To learn more
' about this pagination parameter, see [Pagination](https://developers.google.com/analytics/devguides/reporting/data/v1/basics#pagination).
<DebuggerNonUserCode>
Public Property Offset As Long
'
' Summary:
' The number of rows to return. If unspecified, 10 rows are returned. If -1, all
' rows are returned. To learn more about this pagination parameter, see [Pagination](https://developers.google.com/analytics/devguides/reporting/data/v1/basics#pagination).
<DebuggerNonUserCode>
Public Property Limit As Long
'
' Summary:
' A currency code in ISO4217 format, such as "AED", "USD", "JPY". If the field
' is empty, the report uses the entity's default currency.
<DebuggerNonUserCode>
Public Property CurrencyCode As String
'
' Summary:
' The filter clause of dimensions. Dimensions must be requested to be used in this
' filter. Metrics cannot be used in this filter.
<DebuggerNonUserCode>
Public Property DimensionFilter As FilterExpression
'
' Summary:
' The filter clause of metrics. Applied at post aggregation phase, similar to SQL
' having-clause. Metrics must be requested to be used in this filter. Dimensions
' cannot be used in this filter.
<DebuggerNonUserCode>
Public Property MetricFilter As FilterExpression
'
' Summary:
' Specifies how rows are ordered in the response.
<DebuggerNonUserCode>
Public ReadOnly Property OrderBys As RepeatedField(Of OrderBy)
'
' Summary:
' Cohort group associated with this request. If there is a cohort group in the
' request the 'cohort' dimension must be present.
<DebuggerNonUserCode>
Public Property CohortSpec As CohortSpec
'
' Summary:
' Aggregation of metrics. Aggregated metric values will be shown in rows where
' the dimension_values are set to "RESERVED_(MetricAggregation)".
<DebuggerNonUserCode>
Public ReadOnly Property MetricAggregations As RepeatedField(Of MetricAggregation)
'
' Summary:
' The metrics requested and displayed.
<DebuggerNonUserCode>
Public ReadOnly Property Metrics As RepeatedField(Of Metric)
'
' Summary:
' Toggles whether to return the current state of this Analytics Property's quota.
' Quota is returned in [PropertyQuota](#PropertyQuota).
<DebuggerNonUserCode>
Public Property ReturnPropertyQuota As Boolean
'
' Summary:
' A property whose events are tracked. Within a batch request, this entity should
' either be unspecified or consistent with the batch-level entity.
<DebuggerNonUserCode>
Public Property Entity As Entity
'
' Summary:
' If false or unspecified, each row with all metrics equal to 0 will not be returned.
' If true, these rows will be returned if they are not separately removed by a
' filter.
<DebuggerNonUserCode>
Public Property KeepEmptyRows As Boolean
'
' Summary:
' The dimensions requested and displayed.
<DebuggerNonUserCode>
Public ReadOnly Property Dimensions As RepeatedField(Of Dimension)
I have installed this version : Install-Package Google.Analytics.Data.V1Alpha -Version 1.0.0-alpha01
Solution 1:[1]
I recommend installing Google.Analytics.Data.V1Beta, The following is working with .net 5 and C#.
var client = await BetaAnalyticsDataClient.CreateAsync(CancellationToken.None);
var request = new RunReportRequest
{
Property = "properties/" + PropertyId,
Dimensions = {new Dimension {Name = "city"},},
Metrics = {new Metric {Name = "activeUsers"},},
DateRanges = {new DateRange {StartDate = "2020-03-31", EndDate = "today"},},
};
var response = await client.RunReportAsync(request);
Console.WriteLine("Report result:");
foreach (var row in response.Rows)
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
}
Solution 2:[2]
After suffering from the exact same confusion as OP, this comment from Jon Skeet over on GitHub finally led me to the solution.
Dim request = New RunReportRequest() With {
.Property = "properties/" & propertyId
}
request.Metrics.Add(metrics)
request.Dimensions.Add(dimensions)
request.DateRanges.Add(range)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DaImTo |
Solution 2 | Turnip |