Hi,
I am developing a program in C# to get data from Google Analytics 4. I am not an expert in C#. I have the following code. But getting the following error.
CS7036: There is no argument given that corresponds to the required formal parameter 'property' of 'Properties.RunReport(RunReportRequest, string)'
I tried everything I could but nothing seems to work. Can someone please help?
using Google.Apis.AnalyticsData.v1beta;
using Google.Apis.AnalyticsData.v1beta.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
// Google Analytics 4 property ID.
string propertyId = "123456789";
// Credential Path
string credentialsPath = @"D:\\Google Analytics\GoogleAnalytics4.json";
// Authenticate and create the service.
GoogleCredential credential = GoogleCredential.FromFile(credentialsPath);
AnalyticsDataService service = new AnalyticsDataService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Google Analytics 4",
});
// Construct the request.
RunReportRequest request = new RunReportRequest()
{
Property = $"properties/{propertyId}",
DateRanges =
{
new DateRange()
{
StartDate = "2023-05-15",
EndDate = "2023-05-15"
}
},
Dimensions =
{
new Dimension()
{
Name = "date"
},
new Dimension()
{
Name = "landingPagePlusQueryString"
},
new Dimension()
{
Name = "medium"
},
new Dimension()
{
Name = "orderCoupon"
},
new Dimension()
{
Name = "sourceMedium"
},
new Dimension()
{
Name = "transactionId"
}
},
Metrics =
{
new Metric()
{
Name = "sessions"
},
new Metric()
{
Name = "totalRevenue"
}
}
};
// Execute request.
RunReportResponse response = service.Properties.RunReport(request).Execute();
// Print the results.
Console.WriteLine("Report result:");
foreach (Row row in response.Rows)
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
}
Console.ReadLine();
}
}
}
Thanks.