google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

GA4 DATA API Entrances and exits metric example

Open imaksp opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. Not sure if this is the right place but it seems GA4 DATA API does not have any metrics for Entrances and exits

Describe the solution you'd like Add an example for getting data mentioned (Entrances and exits) in this support article. it was present in old analytics (UA) api. & as per this article it should be present in GA4. https://support.google.com/analytics/answer/11080047

Describe alternatives you've considered None

Additional context

It is present in Explore -> free form report, but API gives error like this:

Field entrances is not a valid metric

imaksp avatar Mar 25 '23 13:03 imaksp

What's Maven artifact you're using? Do you have sample Java code to explain your issue?

suztomo avatar Mar 25 '23 18:03 suztomo

Hi, I am using latest version:

<dependency>
    <groupId>com.google.analytics</groupId>
    <artifactId>google-analytics-data</artifactId>
    <version>0.24.0</version>
</dependency>

But this issue might not be specific to java lib, its a general issue as these (entrances & exits) metrics are missing from api schema, & if you want regenerate this error then you can use query like this:

RunReportRequest.Builder reqBuilder = RunReportRequest.newBuilder()
        .addDateRanges(current)
        .addDateRanges(previous)
        .addDimensions(Dimension.newBuilder().setName("pagePath"))
        .addMetrics(Metric.newBuilder().setName("screenPageViews"))
        .addMetrics(Metric.newBuilder().setName("bounceRate"))
        .addMetrics(Metric.newBuilder().setName("userEngagementDuration"))
        .addMetrics(Metric.newBuilder().setName("entrances"))
        .addMetrics(Metric.newBuilder().setName("exits"))
        .addOrderBys(OrderBy.newBuilder()
                .setMetric(OrderBy.MetricOrderBy.newBuilder().setMetricName("screenPageViews"))
                .setDesc(true))
        .setLimit(2000);

I can generate report like this using Free form report by using official analytics dashboard but not through beta API. I created issue here because I am using java version & I am not sure about right place for this issue.

imaksp avatar Mar 26 '23 05:03 imaksp

@aksdevac Thanks for the additional information and explanation! Support in this repo is specific to the Java client libraries, but if you identify the scope of this question to be at API-level, please reach out through Google Analytics API Support for more product-specific help and resources.

emmileaf avatar Mar 27 '23 16:03 emmileaf

+1 on this request. @aksdevac I would keep an eye on https://support.google.com/analytics/thread/206052625/google-analytics-data-api-exits-exit-rate-metrics?hl=en as well, it's the same question.

toshali avatar Mar 28 '23 18:03 toshali