erebusnz / gapi-google-analytics-php-interface

GA:PI() - Google Analytics PHP Interface
167 stars 86 forks source link

Dimensions/metrics in filter do not get namespace prefix if they include a number #129

Closed ZeroBeeOne closed 9 years ago

ZeroBeeOne commented 9 years ago

Hi all,

We have some dimensions we are attempting to filter by which include a number in the name, namely pagePathLevel1 and pagePathLevel2. in gapi.class.php:199 (the processFilters method) we use a regex to find: Group 1: The start of the string, or a boolean combinator followed by 0 or more spaces Group 2: one or more letters Group 3: 0 or more spaces, followed by a valid operator and prepend a 'ga:' to the second group. In our case it is not happening because the numeric portion of the dimension prevents it from matching the regex.

I believe this would be resolved by changing the appropriate regex to:

$filter = preg_replace('/(&&\s*|\|\|\s*|^)([a-z0-9]+)(\s*' . $valid_operators . ')/i','$1ga:$2$3',$filter);

Although I believe dimensions cannot START with numbers, so it may need to be more restrictive, like maybe: $filter = preg_replace('/(&&\s*|\|\|\s*|^)([a-z]+[a-z0-9]*)(\s*' . $valid_operators . ')/i','$1ga:$2$3',$filter);

In the meantime I am getting around this by manually including the prefix for these dimensions.

erebusnz commented 9 years ago

Issue is fixed in latest commit 6846b0699c0e7244aab6b937ca2475eae8e64990

Thanks!