ruby-on-rails 如何在ruby的GA4 apis中应用维度过滤器?

0sgqnhkj  于 2023-01-22  发布在  Ruby
关注(0)|答案(2)|浏览(180)

我试图添加过滤器的请求为ga 4自定义尺寸,但得到倍数错误。
如果我尝试发送没有任何过滤器,我能够获得数据,所以没有问题的自定义维度设置。
我对语法感到困惑。
引用自-https://googleapis.dev/ruby/google-api-client/v0.53.0/Google/Apis/AnalyticsreportingV4/DimensionFilterClause.html

{
 :property=>"properties/1234",
 :dimensions=>[{:name=>"date"}, {:name=>"customUser:type"}],
 :metrics=>[{:name=>"activeUsers", :invisible=>false}],
 :date_ranges=>[{:start_date=>"2023-01-01", :end_date=>"today", :name=>"date"}],
 :order_bys=>[{:dimension=>{:dimension_name=>"date"}}],
 :dimension_filter_clauses=>[{:dimension_name=>"customUser:type", :expressions=>["Customer"], :not=>false, :operator=>"OR"}],
 :keep_empty_rows=>false,
 :return_property_quota=>true
}

发出请求的正确语法应该是什么?

1wnzp6jl

1wnzp6jl1#

在Google Analytics 4(GA4)API中,您可以应用维度过滤器来检索特定维度的数据。GA4 API使用filters参数来过滤数据

require "google/apis/analyticsdata_v1alpha"

analyticsdata_service = Google::Apis::AnalyticsdataV1alpha::AnalyticsDataService.new

# request parameters
request = Google::Apis::AnalyticsdataV1alpha::RunRealtimeReportRequest.new(
  report_request: Google::Apis::AnalyticsdataV1alpha::ReportRequest.new(
    metric_aggregations: ["count"],
    dimensions: ["eventName"],
    filters: "eventName==ExampleEvent"
  )
)

response = analyticsdata_service.run_realtime_report(request)

puts response.to_json
f5emj3cl

f5emj3cl2#

我得到的答案后,反复试验,这将是为v1beta。

{
 :property=>"properties/<property_id>",
 :dimensions=>[{:name=>"date"}, {:name=>"customUser:type"}],
 :metrics=>[{:name=>"activeUsers", :invisible=>false}],
 :date_ranges=>[{:start_date=>"2023-01-01", :end_date=>"today", :name=>"date"}],
 :order_bys=>[{:dimension=>{:dimension_name=>"date"}}],
 :dimension_filter=>{:filter=>{:field_name=>"customUser:type", :string_filter=>{ :match_type=> "EXACT", :value=>"<value>"}}},
 :keep_empty_rows=>false,
 :return_property_quota=>true
}

相关问题