Learn business growth with Google Analytics 4 Forums Google Analytics 4 What is causing the exception in the GA4 API dimensionFilter for Expect integer error?

  • What is causing the exception in the GA4 API dimensionFilter for Expect integer error?

    Posted by Dylan on 6 March 2023 at 3:52 am

    “Hey, I’m trying to sort out a way to find the most visited sites which includes ‘my/path’. I’ve been attempting to add a filter to this request. Everything runs smoothly until I add this filter. It throws out an error that says ‘Expect integer’. I’m sharing my filter below:

    `php
    ‘dimensionFilter’ => new FilterExpression([
    ‘filter’ => new Filter([
    ‘field_name’ => ‘fullPageUrl’,
    ‘string_filter’ => new StringFilter([
    ‘value’ => ‘my/path’,
    ‘match_type’ => ‘CONTAINS’
    ])
    ])
    ])
    `

    Do you have any idea what I might be missing here?”

    Isaac replied 1 year, 3 months ago 3 Members · 2 Replies
  • 2 Replies
  • Aniket

    Member
    23 May 2023 at 11:18 am

    Ah, I see where the issue is coming from. It’s because ‘CONTAINS’ isn’t recognized as it’s expected to be an integer, not a string. So here’s a simple fix for you: just swap ‘CONTAINS’ with FilterStringFilterMatchType::CONTAINS. And bingo, this should resolve the issue! You see, FilterStringFilterMatchType::CONTAINS actually corresponds to an integer, hence, eliminating the problem. Easy peasy, right?

  • Isaac

    Member
    13 June 2023 at 4:58 pm

    The error message “Expect integer” typically means that the function or method you are using is expecting an integer as an input parameter, but it’s receiving a non-integer value. Looking at your code, it’s not fully apparent why an integer would be expected as you’re working with string values primarily. There may be a parameter or function elsewhere in your code that requires an integer. Another possible issue could be with the ‘CONTAINS’ match type depending on how it’s implemented. It may be expecting an integer value rather than a string. Double-check your function parameters or any other bits of code interacting with these filters. If possible, also verify the documentation of the Filter, FilterExpression, and StringFilter classes or functions to ensure you’re using them correctly.

Log in to reply.