Learn business growth with Google Analytics 4 Forums Google Analytics 4 Requesting Data with Multiple Dimensions: pagePathPlusQueryString and deviceCategory

  • Requesting Data with Multiple Dimensions: pagePathPlusQueryString and deviceCategory

    Posted by Lily on 7 January 2023 at 4:54 pm

    I’m trying to craft a request to snag page views for a specific URL, and I also need to pull in the device category and country id. However, I’ve hit a snag — when I send the request, I’m faced with the following error:

    POST https://analyticsdata.googleapis.com:443/v1beta/properties/317256757:runReport?$alt=json;enum-encoding%3Dint
    {
    “error”: {
    “code”: 400,
    “message”: “Please remove pagePathPlusQueryString 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/“,
    “errors”: [
    {
    “message”: “Please remove pagePathPlusQueryString 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/“,
    “domain”: “global”,
    “reason”: “badRequest”
    }
    ],
    “status”: “INVALID_ARGUMENT”
    }

    I’m working with the Google Analytics Data API, GA4 version, and I’m writing my code in Java. Here’s the code for my request:

    RunReportRequest request =
                        RunReportRequest.newBuilder()
                                .setProperty("properties/" + propertyID)
                                .addMetrics(Metric.newBuilder().setName("screenPageViews"))
                                .addDimensions(Dimension.newBuilder().setName("pagePathPlusQueryString"))
                                .addDimensions(Dimension.newBuilder().setName("deviceCategory"))
                                .addDimensions(Dimension.newBuilder().setName("countryId"))
                                .addDateRanges(DateRange.newBuilder().setStartDate(startDate).setEndDate(endDate))
                                .build();
    
    Oliver replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Aiden

    Member
    9 March 2023 at 3:28 am

    The error request you’re seeing is likely because you’re using “pagePathPlusQueryString” as a dimension, which is incompatible with “screenPageViews” as a metric. Try replacing “screenPageViews” with “pageViews” and “pagePathPlusQueryString” with “pagePath”. This should resolve the issue and allow your request to be processed.

  • Oliver

    Member
    19 March 2023 at 1:10 pm

    The error message is telling you that there’s a mismatch between the metrics and dimensions you’re trying to pull in via the Google Analytics Data API. In this case, the specific problem is with “pagePathPlusQueryString”. This likely means that “pagePathPlusQueryString” cannot be used in conjunction with the other metrics and dimensions you’re trying to pull. To fix this issue, try removing “pagePathPlusQueryString” from your request. Otherwise, you could look for an alternative to “pagePathPlusQueryString” that is compatible with the other metrics and dimensions you’re trying to retrieve.

Log in to reply.