Skip to content

Commit

Permalink
feat: Adds type check for dimension group enabling send Filter object…
Browse files Browse the repository at this point in the history
…s directly
  • Loading branch information
nsinisterra committed Mar 28, 2023
1 parent 9eceb73 commit a1819ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Facades/LaravelGoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @method static self metricAggregations(int ...$items)
* @method static self whereDimension(string $name, int $matchType, $value, bool $caseSensitive = false)
* @method static self whereDimensionIn(string $name, array $values, bool $caseSensitive = false)
* @method static self whereAndGroupDimensions(array $dimensions)
* @method static self whereMetric(string $name, int $operation, $value)
* @method static self whereMetricBetween(string $name, $from, $to)
* @method static \Google\Analytics\Data\V1beta\NumericValue getNumericObject( $value)
Expand Down
18 changes: 13 additions & 5 deletions src/Traits/FilterByDimensionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ protected function createDimensionGroup($dimensions): array
$filterExpressionList = [];

foreach ($dimensions as $dimension) {
$stringFilter = (new StringFilter())->setCaseSensitive($dimension[3] ?? false)
->setMatchType($dimension[1])
->setValue($dimension[2]);
if($dimension instanceof Filter){
$filterExpressionList[] = (new FilterExpression())->setFilter($dimension);
continue;
}

$filter = (new Filter())->setStringFilter($stringFilter)->setFieldName($dimension[0]);
if(is_array($dimension)){
$stringFilter = (new StringFilter())->setCaseSensitive($dimension[3] ?? false)
->setMatchType($dimension[1])
->setValue($dimension[2]);

$filterExpressionList[] = (new FilterExpression())->setFilter($filter);
$filter = (new Filter())->setStringFilter($stringFilter)->setFieldName($dimension[0]);
$filterExpressionList[] = (new FilterExpression())->setFilter($filter);
}

// TODO: Throw and invalid dimension exception?
}

return $filterExpressionList;
Expand Down

0 comments on commit a1819ad

Please sign in to comment.