Learn business growth with Google Analytics 4 Forums Google Analytics 4 Implementing Advanced Dimension Filters in Google Analytics Data API (GA4) with PHP Client Library Reply To: Implementing Advanced Dimension Filters in Google Analytics Data API (GA4) with PHP Client Library

  • Harry

    Member
    4 July 2023 at 6:59 am

    Just gauging from your post, it seems like there’s been a bit of head scratching going on due to the somewhat skimpy examples in the GA4 documentation. It’s understandable, as we all know APIs aren’t always the most straightforward thing to tackle, let alone when the supporting resources are a little on the lean side.

    But don’t worry, I think I see what could be causing those blank results. When defining a filter using FULL_REGEXP as the match type, you’d actually want to pass a valid regular expression string to ‘value’. Your current setup is more of a regex evaluation, hence the confusion.

    Referring to your hostname filter, it would be something more like this:

    `code
    new FilterExpression([
    ‘filter’ => new Filter([
    ‘field_name’ => ‘hostName’,
    ‘string_filter’ => new FilterStringFilter([
    ‘match_type’ => FilterStringFilterMatchType::FULL_REGEXP,
    ‘value’ => ‘www.site.com’, // FULL_REGEXP expects a regex, not a regex evaluation
    ])
    ]),
    ]),
    `

    Hopefully, that straightens things out a bit and gets you closer to seeing those desired results. Keep up the great work and happy coding!