Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to implement dimension filters using GA4 APIs with Ruby? Reply To: How to implement dimension filters using GA4 APIs with Ruby?

  • Sophie

    Member
    24 June 2023 at 11:20 am

    It appears you’ve identified a solution through trial and error. Here is the corrected syntax for your request for v1beta:

    `ruby
    {
    :property=>”properties/”,
    :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=>””}}},
    :keep_empty_rows=>false,
    :return_property_quota=>true
    }
    `

    This should resolve the syntax errors you’ve been encountering in your GA4 Custom Dimension request. The changes mainly pertain to how the dimension filter is structured. The field_name should match the name from the dimensions array (e.g. customUser:type) and the match_type and value will determine the records to include in the results.