I am using c# to retrieve a report from Google Analytics (GA4) using Google.Apis.AnalyticsData.v1beta. Following an example from https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries#.net_1. Code below. I am getting the very generic error of "Object reference not set to an instance of an object" on the request. I have never asked a question before, so hopefully I am doing this right. Thank you!
My code:
RunReportRequest request = new RunReportRequest()
{
Property = "properties/xxxxxx",
DateRanges =
{
new DateRange()
{
StartDate = "2023-07-01",
EndDate = "2023-07-31"
}
},
Metrics =
{
new Metric()
{
Name = "sessions"
},
new Metric()
{
Name = "screenPageViews"
}
}
};
I also tried using the exact example code, but got the same result:
RunReportRequest request = new RunReportRequest
{
Property = "properties/xxxxx",
Dimensions = { new Dimension { Name = "city" }, },
Metrics = { new Metric { Name = "activeUsers" }, },
DateRanges = { new DateRange { StartDate = "2023-07-31", EndDate = "today" }, },
};
This problem is mentioned in a RunReport question from Microsoft, where the user indicates they also got the object reference error, but unfortunately, the followup question is not answered. https://learn.microsoft.com/en-us/answers/questions/1286681/how-to-get-data-from-google-analytics-4-using-c