Search code examples
google-analyticsgoogle-analytics-api

Some Dimensions Cause Empty Response for GA4 runReport API


I believe this is a regression and used to work, but when I make queries against the GA4 RunReport API and request data which includes the dimensions "source", "medium" or "defaultChannelGrouping" I get a 200 from the server with no rows.

For Example:

const dimensions = ['browser', 'source'];
const basicDataMetrics = ['sessions'];
const body = {
            dimensions: dimensions.map((z) => { return { name: z } }),
            metrics: metrics.map((z) => { return { name: z } }),
            dateRanges: [
                {
                    endDate: dateToQuery,
                    startDate: dateToQuery
                },
            ],
            offset: startIndex,
            limit: maxResults,
            keepEmptyRows: true,
            returnPropertyQuota: true
        }
const ga4Response = await axios.post(`https://analyticsdata.googleapis.com/v1beta/properties/${webPropertyId}:runReport`, body, { headers });

In the above example, gaResponse.data will have something like

{
  dimensionHeaders: [
    {
      name: "browser",
    },
    {
      name: "source",
    },
  ],
  metricHeaders: [
    {
      name: "sessions",
      type: "TYPE_INTEGER",
    },
  ],
  metadata: {
    currencyCode: "EUR",
    timeZone: "Europe/Paris",
  },
  kind: "analyticsData#runReport",
}

Notice the completely missing rows or rowCount. If I omit 'source' from my dimensions everything works as expected. I've noticed that 'medium' and 'defaultChannelGrouping' also cause this behavior. All of these dimensions used to be valid and are still valid accoring to the documentation . Does anyone know what I can do to get results for these dimensions? Are they deprecated for this API?


Solution

  • If your GA4 property's Reporting Attribution model is neither Cross-channel last click nor Ads-preferred last click, then event-scoped attribution dimensions like "source", "medium", and "defaultChannelGrouping" return data for only conversion events. Attribution models are explained some on About attribution and attribution modeling.

    Try using "sessionSource", "sessionMedium", or "sessionDefaultChannelGrouping" in your request. If you use "sessionSource", your example request will return rows if at least one session occured on your GA4 property in the date range.