Learn business growth with Google Analytics 4 Forums Google Analytics 4 Accessing Query Parameters in Google Analytics 4 API

  • Accessing Query Parameters in Google Analytics 4 API

    Posted by Alexander on 26 January 2023 at 7:22 pm

    Hey there, I’m trying to use the Google Analytics 4 API to grab data for pagePathPlusQueryString, sessionCampaignName, & totalUsers by using this POST link: https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID:runReport. But when I add sessionCampaignName to the dimensions, it throws a fit with some incompatibility error.

    Here are my dimensions: date, pagePathPlusQueryString, and sessionCampaignName:

    "dimensions": [
     {
      "name": "date"
    },
     {
      "name": "pagePathPlusQueryString"
    },
    {
      "name": "sessionCampaignName"
    }
     ]
    

    And here are my metrics: totalUsers & screenPageViews:

    "metrics": [
    {
      "name": "totalUsers"
    },
    {
      "name": "screenPageViews"
    }
    ]

    Anyone got a clue on how to get data with the querystring and sessionCampaignName? Any suggestions are appreciated. Thanks!

    P.S.: I’m struggling with compatibility issues between pagePathPlusQueryString and sessionCampaignName.

    Benjamin replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Leo

    Member
    28 February 2023 at 8:31 pm

    Oh, I feel you! I hit the same issue a few days ago with those stubborn incompatibilities in Google Analytics. The solution is actually simpler than it looks.

    The tricky part here is that dimensions that bring in the query string – like our friend pagePathPlusQueryString – play nicely only with a select group of other dimensions and metrics.

    Turns out pagePathPlusQueryString is like a prima donna page level dimension, kinda different from the regular event parameters we know and love.

    So, what’s the workaround? Get the queryString into an event parameter, and it should all work smoothly.

    Also, if you’re dealing with custom event parameters, dimensions or metrics, just remember you need to slightly change the way you’re referencing them. Instead of the literal names, use customEvent:{parameter_name}. Treat it like any other standard parameter and it should respond nicely.

    Hope this helps! Don’t let the Analytics APIs bully you; you got this!

  • Benjamin

    Member
    2 March 2023 at 5:36 pm

    The incompatibility issue you’re encountering stems from the fact that “pagePathPlusQueryString” and “sessionCampaignName” dimensions belong to different scopes in Google Analytics 4. The “pagePathPlusQueryString” is in the ‘Page’ scope, while “sessionCampaignName” is within the ‘Session’ scope. These scopes are mutually incompatible— you cannot combine them in a single report. Data in GA4 is processed differently based on its scope.

    For a solution, consider separating your reports based on the scope: one with ‘Session’ scope, featuring the “date” and “sessionCampaignName” dimensions, and another with ‘Page’ scope, combining the “date” and “pagePathPlusQueryString”. You can then splice and dice the data from the two separate reports to get the information you need. Alternatively, it may be possible to use other compatible dimensions that serve a similar purpose in your use case.

    Always remember to ensure that the dimensions in your report are all compatible (within the same scope) to avoid errors. This is key when working with Google Analytics 4’s API.

Log in to reply.