google / google/site-kit-wp

Provide support for additional Analytics dimension filters

Open
#4,685 0 comments 0 reactions 0 assignees View on GitHub
Module: Analytics Type: Enhancement Type: Support
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 12h
Merged PRs (30d)
80

Description

## Feature Description

As per [one users request](https://wordpress.org/support/topic/dimension-filters-parameter-does-not-support-all-supported-match-types/#post-15267568) in the support forums consider providing support for additional operators which WordPress developers can use for custom development.

Full context of support topic:

> I have been developing a plugin to retrieve Google Analytics Reports for the front-end page using Google Sitekit Rest API, everything is working fine but I realized that the Dimension filters parameter does not support all supported match types https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet?hl=vi#Operator
>
> In google-site-kit/includes/Modules/Analytics.php file at lines 545 and 548
>
> This may retrieve wrong page views reports, could you add other operators such as PARTIAL, REGEXP, BEGINS_WITH, ENDS_WITH … in the next update?

```
$dimension_filters = $data['dimensionFilters'];
$dimension_filter_instances = array();
if ( ! empty( $dimension_filters ) && is_array( $dimension_filters ) ) {
foreach ( $dimension_filters as $dimension_name => $dimension_value ) {
$dimension_filter = new Google_Service_AnalyticsReporting_DimensionFilter();
$dimension_filter->setDimensionName( $dimension_name );
if ( is_array( $dimension_value ) ) {
$dimension_filter->setOperator( 'IN_LIST' );
$dimension_filter->setExpressions( $dimension_value );
} else {
$dimension_filter->setOperator( 'EXACT' );
$dimension_filter->setExpressions( array( $dimension_value ) );
}
$dimension_filter_instances[] = $dimension_filter;
}

if ( ! empty( $dimension_filter_instances ) ) {
$request_args['dimension_filters'] = $dimension_filter_instances;
}
}
```

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

*

## Implementation Brief

*

### Test Coverage

*

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.