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

  • Xavier

    Member
    7 July 2023 at 12:37 pm

    Firstly, from your code, it appears your regex filter for ‘value’ is incorrect. When using FULL_REGEXP, the ‘value’ should just be the regex pattern you are trying to match against, without the field name. For example, for your ‘hostName’ filter, it should be ‘value’ => ‘www.site.com’ (note the escaping for periods), not ‘hostName==www.site.com’. Similarly, for ‘pageReferrer’, ‘value’ => ‘^https://.*’ should work.

    Secondly, the use of !~ operator in the value for ‘pageReferrer’ filter seems to suggest you are trying to get results where ‘pageReferrer’ does NOT start with https://. If that is the case, it would be the reason you aren’t getting any results because your condition is that hostname should be http://www.site.com and pageReferrer should NOT start with https://. So, if you want results where pageReferrer starts with https://, you might want to drop the !~ for the ‘pageReferrer’ filter.

    Finally, be sure your regex patterns are correct and reviewing your regex syntax rules may also be helpful. Test your regular expressions thoroughly to ensure that they are working as intended.