Learn business growth with Google Analytics 4 Forums Google Analytics 4 Implementing Metric Filtering in GA4 API with PHP Library Reply To: Implementing Metric Filtering in GA4 API with PHP Library

  • Daniel

    Member
    25 March 2023 at 6:05 am

    It appears the code is expecting a GoogleAnalyticsDataV1betaNumericValue instance in the ‘value’ field of numeric_filter, not a string or integer as currently passed (‘10000’).

    Take a look at the JSON equivalent provided, the value is an object:
    `
    “value”: {
    “int64Value”: “10000”
    }
    `
    Translating this to PHP, it likely expects an equivalent object:
    `
    ‘numeric_filter’ => new FilterNumericFilter([
    ‘operation’ => FilterNumericFilterOperation::GREATER_THAN,
    ‘value’ => new GoogleAnalyticsDataV1betaNumericValue([
    ‘int64_value’ => ‘10000’,
    ])
    ])
    `
    Please make sure to replace ‘GoogleAnalyticsDataV1betaNumericValue’ with the actual class path in your case.

    Also, make sure that you’ve added necessary class initializations for the classes used like DateRange, Dimension, Metric, FilterExpression, FILTER, NumericValue etc., at the top of your PHP file per your namespace structure.

    If the issue still persists, you could refer to Google’s official PHP library repository or contact their support for further assistance as the GA4 library is in beta and may contain bugs or lack of documentations.