Search code examples
google-analytics-api

How to make Google Analytics API request with dimension: pageLocations and metrics: averageSessionDuration and newUsers?


I am trying to make the following dimensions and metrics using the Google Analytics API:

Dimension: pageLocations Metric: averageSessionDuration Metric: newUsers However, I am getting an error message saying that the requested combination of dimensions and metrics is not supported.

I get next error: Grpc.Core.RpcException: Status(StatusCode="InvalidArgument", Detail="Please remove pageLocation to make the request compatible. The request's dimensions & metrics are incompatible. To learn more, see https://ga-dev-tools.web.app/ga4/dimensions-metrics-explorer/")

Currently I'm using .NET library Google.Analytics.Data.V1Beta Version 2.0.0-beta03. So, it's GA4 Api (https://developers.google.com/analytics/devguides/reporting/data/v1).

I have checked the Dimensions & Metrics Explorer (https://ga-dev-tools.google/ga4/dimensions-metrics-explorer/) and confirmed that this combination of dimensions and metrics is not available. However, I can create an exploration using this combination of dimensions and metrics in the Google Analytics Exploration interface.

Is it possible to get these dimensions and metrics using the Google Analytics API? Or I should wait and this option will be added to API latter?

I will be glad to get all these data by .NET library, but if I have a chance to get this data by direct REST API request or some other technology, I would try to do that. I would like to perform this action daily, but I don't want to manually download CSV file from Google Analytics Exploration and import it in my system.

I tried to access through .NET library and get InvalidArgument error and I check Dimensions & Metrics Explorer (https://ga-dev-tools.google/ga4/dimensions-metrics-explorer/). Therefore I believe straightforward solution to this issue is currently unavailable, but may be I can find some work around to get these values may be from other available metrics.

Thank you!


Solution

  • They are incompatible in a single request and you can play with different metrics and dimensions to obtain you desired one. You can read this article [GA4] Data compatibility.

    as an example instead of pageLocations you can apply hostname and pagePath.

    You can also use this tool at this link GA Account Explorer to control the compatibility of your applied dimensions and metrics together.