Can GA4-API fetch the data from requests made with a combination of minute and region and sessions?

772 views Asked by At

Problem

With UA, I was able to get the number of sessions per region per minute (a combination of minute, region, and sessions), but is this not possible with GA4?

If not, is there any plan to support this in the future?


Detail

I ran GA4 Query Explorer with date, hour, minute, region in Dimensions and sessions in Metrics.

But I got an incompatibility error.


What I tried

I have checked with GA4 Dimensions & Metrics Explorer and confirmed that the combination of minute and region is not possible. (see image below).

image of the result I checked

(updated 2022/05/16 15:35)Checked by Code Execution

I ran it with ruby.

require "google/analytics/data/v1beta/analytics_data"
require 'pp'
require 'json'

ENV['GOOGLE_APPLICATION_CREDENTIALS'] = '' # service acount file path
client = ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new

LIMIT_SIZE = 1000
offset = 0

loop do
  request = Google::Analytics::Data::V1beta::RunReportRequest.new(
    property: "properties/xxxxxxxxx",
    date_ranges: [
      { start_date: '2022-04-01', end_date: '2022-04-30'}
    ],
    dimensions: %w(date hour minute region).map { |d| { name: d } },
    metrics: %w(sessions).map { |m| { name: m } },
    keep_empty_rows: false,
    offset: offset,
    limit: LIMIT_SIZE
  )

  ret = client.run_report(request)
  dimension_headers = ret.dimension_headers.map(&:name)
  metric_headers = ret.metric_headers.map(&:name)
  puts (dimension_headers + metric_headers).join(',')
  ret.rows.each do |row|
    puts (row.dimension_values.map(&:value) + row.metric_values.map(&:value)).join(',')
  end

  offset += LIMIT_SIZE

  break if ret.row_count <= offset
end

The result was an error.

3:The dimensions and metrics are incompatible.. debug_error_string:{"created":"@1652681913.393028000","description":"Error received from peer ipv4:172.217.175.234:443","file":"src/core/lib/surface/call.cc","file_line":953,"grpc_message":"The dimensions and metrics are incompatible.","grpc_status":3}

1

There are 1 answers

7
Linda Lawton - DaImTo On

Error in your code, Make sure you use the actual dimension name and not the UI name. The correct name of that dimension is dateHourMinute not Date hour and minute

dimensions: %w(dateHourMinute).map { |d| { name: d } },

The query explore returns this request just fine

enter image description here

results

enter image description here

Limited use for region dimension

The as for region. As the error message states the dimensions and metrics are incompatible. The issue being that dateHourMinute can not be used with region. Switch to date or datehour

at the time of writing this is a beta api. I have sent a message off to google to find out if this is working as intended or if it may be changed.