Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where are the examples (or docs for that matter) about filters??? #1590

Open
php4fan opened this issue Feb 1, 2022 · 5 comments
Open

Where are the examples (or docs for that matter) about filters??? #1590

php4fan opened this issue Feb 1, 2022 · 5 comments
Labels
samples Issues that are directly related to samples. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@php4fan
Copy link

php4fan commented Feb 1, 2022

Where is the detailed documentation with examples, of how to build reports with complex (or even trivial) filters with the PHP library??

Here:
https://developers.google.com/analytics/devguides/reporting/data/v1/basics#dimension_filters
Some (too basic) example of filters in raw HTTP but no mention of PHP.

Here:
http://googleapis.github.io/google-cloud-php/#/docs/analytics-data/v0.8.0/analyticsdata/v1beta/readme
The only one example in PHP is one request, not only with no filters but with no parameters whatsoever.

Here:
https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/FilterExpression#StringFilter
Some more details about filters but no clue as to how to translate it into PHP code.

This is pathetic.

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Feb 1, 2022
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Feb 2, 2022
@bshaffer
Copy link
Contributor

Hi @php4fan
Sorry to hear your experience hasn't been great. We haven't created samples for the documentation you linked to yet. However, looking at the Python sample, the PHP sample would look something like this:

use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
use Google\Analytics\Data\V1beta\RunReportRequest;
use Google\Analytics\Data\V1beta\Dimension;
use Google\Analytics\Data\V1beta\Metric;
use Google\Analytics\Data\V1beta\DateRange;
use Google\Analytics\Data\V1beta\Filter;
use Google\Analytics\Data\V1beta\FilterExpression;

$client = new BetaAnalyticsDataClient();
$propertyId = 'YOUR-GA4-PROPERTY-ID';

$dimension = (new Dimension())
    ->setName('date');
$metric = (new Metric())
    ->setName('eventCount');
$dateRange = (new DateRange())
    ->setStartDate('7daysAgo')
    ->setEndDate('yesterday');
$stringFilter = (new Filter\StringFilter())
    ->setValue('first_open');
$filter = (new Filter())
    ->setFieldName('eventName')
    ->setStringFilter($stringFilter);
$filterExprssion = (new FilterExpression())
    ->setFilter($filter);
$response = $client->runReport([
    'property' => 'properties/' . $propertyId,
    'dimensions' => [$dimension],
    'metrics' => [$metric],
    'date_ranges' => [$dateRange],
    'dimension_filter' => $filter,
]);

var_dump($response->serializeToJsonString());

I hope this helps.

@bshaffer bshaffer added type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jun 15, 2022
@php4fan
Copy link
Author

php4fan commented Jun 16, 2022

Have you added that to the docs? If so where? Otherwise why are you closing this as complete?

@AltamashShaikh
Copy link

@php4fan May be this could be helpful for you or anyone else

$dimensionFilter = new \Google\Analytics\Data\V1beta\FilterExpression([
                'and_group' => new \Google\Analytics\Data\V1beta\FilterExpressionList(
                    [
                        'expressions' => [
                            0 => new \Google\Analytics\Data\V1beta\FilterExpression(
                                [
                                    'filter' => new \Google\Analytics\Data\V1beta\Filter(
                                        array(
                                            'field_name' => 'streamId',
                                            'in_list_filter' => new \Google\Analytics\Data\V1beta\Filter\InListFilter([
                                                'values' => $streamIds,
                                                'case_sensitive' => false
                                            ]),
                                        )
                                    )
                                ]
                            )
                        ]
                    ]
                )
            ]);

@bshaffer bshaffer added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Sep 11, 2023
@bshaffer
Copy link
Contributor

We can link the documentation to our samples that we already have generated in this repository.

@bshaffer bshaffer reopened this Sep 11, 2023
@AltamashShaikh
Copy link

@bshaffer That would be great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants