Skip to content

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

Open

Description

@php4fan

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.

Activity

  1. added
    samples
    on Feb 1, 2022
  2. added
    triage me
    🚨
    on Feb 2, 2022
  3. bshaffer commented on Jun 15, 2022

    @bshaffer
    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.

  4. added
    type: question
    and removed
    🚨
    triage me
    on Jun 15, 2022
  5. php4fan commented on Jun 16, 2022

    @php4fan
    Author

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

  6. AltamashShaikh commented on Sep 11, 2023

    @AltamashShaikh

    @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
                                                ]),
                                            )
                                        )
                                    ]
                                )
                            ]
                        ]
                    )
                ]);
    
  7. added
    type: feature request
    and removed
    type: question
    on Sep 11, 2023
  8. bshaffer commented on Sep 11, 2023

    @bshaffer
    Contributor

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

  9. AltamashShaikh commented on Sep 12, 2023

    @AltamashShaikh

    @bshaffer That would be great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    samplestype: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions