'Setting proxy for Google Analytics Data API (GA4)

I need to config proxy credential for GA4 Client library to pass it from http proxy server, unfortunately there isn't any rich documentation for this purpose on the web (or maybe I couldn't find them)

Google Analytics Data API(GA4)

using Google.Analytics.Data.V1Beta;
using System.Net;

// Config Proxy Credential
WebProxy proxy = new WebProxy([proxy_url], [bypass]);
proxy.Credentials = new NetworkCredential([username], [password]);


// Google Analytics configuration
BetaAnalyticsDataClient client = BetaAnalyticsDataClient.Create();
RunReportRequest 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"}, },
};

// Make the request
var response = client.RunReport(request);

I have tried to assign object proxy to BetaAnalyticsDataClient or RunReportRequest object but I can't find it and I don't know how to use proxy configuration for GA4 library.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source