From a55011d999eef310603f8f6020cb771ca126a4b7 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 2 Apr 2021 21:38:41 +0200 Subject: [PATCH 01/14] chore(deps): update dependency google-analytics-data to v0.5.0 (#49) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 4d222ea..2b2d2d6 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-analytics-data==0.4.0 +google-analytics-data==0.5.0 google-auth-oauthlib==0.4.4 \ No newline at end of file From a1e63c56f5fa5835c528724c9d861c18cb34d6ad Mon Sep 17 00:00:00 2001 From: ikuleshov Date: Tue, 6 Apr 2021 12:20:50 -0700 Subject: [PATCH 02/14] docs: add sample code for Data API v1 (#57) * docs: added a sample * docs: usage instructions updated to use Python3 * docs: updated sample to include main() method * docs: update the sample to support the Google Analytics Data API v1 beta * docs: add samples for the Data API v1 beta * update region tag names to match the convention * docs: add Data API v1 samples * add tests for new samples * add more samples * fix the test * fix tests * fix tests * fix tests * lint * lint * add README.md * fix time range in a query * temporary disable the threashold quota display * display pootentially thresholded requests per hour quota * lint * lint * removed noxfile.py from PR * removed generated configs from PR * removed generated configs from PR * remove generated configs from PR * Use f-strings instead of fortmat(). Use run_sample() to start the sample.. * move each sample into an individual file * move each sample into an individual file * fix region tags * fix tests --- samples/snippets/README.md | 33 +++++++ samples/snippets/get_common_metadata.py | 81 +++++++++++++++ samples/snippets/get_common_metadata_test.py | 21 ++++ .../snippets/get_metadata_by_property_id.py | 56 +++++++++++ .../get_metadata_by_property_id_test.py | 25 +++++ samples/snippets/quickstart.py | 5 +- .../snippets/quickstart_json_credentials.py | 2 +- samples/snippets/quickstart_oauth2.py | 14 ++- samples/snippets/run_batch_report.py | 78 +++++++++++++++ samples/snippets/run_batch_report_test.py | 25 +++++ samples/snippets/run_pivot_report.py | 99 +++++++++++++++++++ samples/snippets/run_pivot_report_test.py | 25 +++++ samples/snippets/run_realtime_report.py | 57 +++++++++++ samples/snippets/run_realtime_report_test.py | 25 +++++ ...ealtime_report_with_multiple_dimensions.py | 57 +++++++++++ ...me_report_with_multiple_dimensions_test.py | 27 +++++ ...n_realtime_report_with_multiple_metrics.py | 57 +++++++++++ ...ltime_report_with_multiple_metrics_test.py | 25 +++++ samples/snippets/run_report.py | 80 +++++++++++++++ samples/snippets/run_report_test.py | 25 +++++ .../snippets/run_report_with_aggregations.py | 66 +++++++++++++ .../run_report_with_aggregations_test.py | 25 +++++ samples/snippets/run_report_with_cohorts.py | 85 ++++++++++++++++ .../snippets/run_report_with_cohorts_test.py | 25 +++++ .../run_report_with_custom_parameters.py | 41 ++++++++ .../snippets/run_report_with_date_ranges.py | 62 ++++++++++++ .../run_report_with_date_ranges_test.py | 25 +++++ ...eport_with_dimension_and_metric_filters.py | 99 +++++++++++++++++++ ..._with_dimension_and_metric_filters_test.py | 27 +++++ ...un_report_with_dimension_exclude_filter.py | 74 ++++++++++++++ ...port_with_dimension_exclude_filter_test.py | 27 +++++ .../run_report_with_dimension_filter.py | 73 ++++++++++++++ .../run_report_with_dimension_filter_test.py | 25 +++++ ...un_report_with_dimension_in_list_filter.py | 79 +++++++++++++++ ...port_with_dimension_in_list_filter_test.py | 27 +++++ ..._report_with_multiple_dimension_filters.py | 86 ++++++++++++++++ ...rt_with_multiple_dimension_filters_test.py | 27 +++++ .../run_report_with_multiple_dimensions.py | 62 ++++++++++++ ...un_report_with_multiple_dimensions_test.py | 27 +++++ .../run_report_with_multiple_metrics.py | 64 ++++++++++++ .../run_report_with_multiple_metrics_test.py | 25 +++++ .../run_report_with_named_date_ranges.py | 64 ++++++++++++ .../run_report_with_named_date_ranges_test.py | 27 +++++ samples/snippets/run_report_with_ordering.py | 68 +++++++++++++ .../snippets/run_report_with_ordering_test.py | 25 +++++ .../snippets/run_report_with_pagination.py | 95 ++++++++++++++++++ .../run_report_with_pagination_test.py | 25 +++++ .../run_report_with_property_quota.py | 86 ++++++++++++++++ .../run_report_with_property_quota_test.py | 25 +++++ 49 files changed, 2270 insertions(+), 13 deletions(-) create mode 100644 samples/snippets/README.md create mode 100644 samples/snippets/get_common_metadata.py create mode 100644 samples/snippets/get_common_metadata_test.py create mode 100644 samples/snippets/get_metadata_by_property_id.py create mode 100644 samples/snippets/get_metadata_by_property_id_test.py create mode 100644 samples/snippets/run_batch_report.py create mode 100644 samples/snippets/run_batch_report_test.py create mode 100644 samples/snippets/run_pivot_report.py create mode 100644 samples/snippets/run_pivot_report_test.py create mode 100644 samples/snippets/run_realtime_report.py create mode 100644 samples/snippets/run_realtime_report_test.py create mode 100644 samples/snippets/run_realtime_report_with_multiple_dimensions.py create mode 100644 samples/snippets/run_realtime_report_with_multiple_dimensions_test.py create mode 100644 samples/snippets/run_realtime_report_with_multiple_metrics.py create mode 100644 samples/snippets/run_realtime_report_with_multiple_metrics_test.py create mode 100644 samples/snippets/run_report.py create mode 100644 samples/snippets/run_report_test.py create mode 100644 samples/snippets/run_report_with_aggregations.py create mode 100644 samples/snippets/run_report_with_aggregations_test.py create mode 100644 samples/snippets/run_report_with_cohorts.py create mode 100644 samples/snippets/run_report_with_cohorts_test.py create mode 100644 samples/snippets/run_report_with_custom_parameters.py create mode 100644 samples/snippets/run_report_with_date_ranges.py create mode 100644 samples/snippets/run_report_with_date_ranges_test.py create mode 100644 samples/snippets/run_report_with_dimension_and_metric_filters.py create mode 100644 samples/snippets/run_report_with_dimension_and_metric_filters_test.py create mode 100644 samples/snippets/run_report_with_dimension_exclude_filter.py create mode 100644 samples/snippets/run_report_with_dimension_exclude_filter_test.py create mode 100644 samples/snippets/run_report_with_dimension_filter.py create mode 100644 samples/snippets/run_report_with_dimension_filter_test.py create mode 100644 samples/snippets/run_report_with_dimension_in_list_filter.py create mode 100644 samples/snippets/run_report_with_dimension_in_list_filter_test.py create mode 100644 samples/snippets/run_report_with_multiple_dimension_filters.py create mode 100644 samples/snippets/run_report_with_multiple_dimension_filters_test.py create mode 100644 samples/snippets/run_report_with_multiple_dimensions.py create mode 100644 samples/snippets/run_report_with_multiple_dimensions_test.py create mode 100644 samples/snippets/run_report_with_multiple_metrics.py create mode 100644 samples/snippets/run_report_with_multiple_metrics_test.py create mode 100644 samples/snippets/run_report_with_named_date_ranges.py create mode 100644 samples/snippets/run_report_with_named_date_ranges_test.py create mode 100644 samples/snippets/run_report_with_ordering.py create mode 100644 samples/snippets/run_report_with_ordering_test.py create mode 100644 samples/snippets/run_report_with_pagination.py create mode 100644 samples/snippets/run_report_with_pagination_test.py create mode 100644 samples/snippets/run_report_with_property_quota.py create mode 100644 samples/snippets/run_report_with_property_quota_test.py diff --git a/samples/snippets/README.md b/samples/snippets/README.md new file mode 100644 index 0000000..f390224 --- /dev/null +++ b/samples/snippets/README.md @@ -0,0 +1,33 @@ +# Google Analytics Data API examples + +[![Open in Cloud Shell][shell_img]][shell_link] + +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/python-analytics-data&page=editor&working_dir=samples/snippets + +These samples show how to use the +[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1) from Python. + +## Build and Run +1. **Enable APIs** - [Enable the Analytics Data API](https://console.cloud.google.com/flows/enableapi?apiid=analyticsdata.googleapis.com) + and create a new project or select an existing project. +2. **Download The Credentials** - Configure your project using [Application Default Credentials][adc]. + Click "Go to credentials" after enabling the APIs. Click "Create Credentials" + and select "Service Account Credentials" and download the credentials file. Then set the path to + this file to the environment variable `GOOGLE_APPLICATION_CREDENTIALS`: +```sh + $ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json +``` +3. **Clone the repo** and cd into this directory +```sh + $ git clone https://github.com/googleapis/python-analytics-data + $ cd python-analytics-data/samples/snippets +``` +4. **Install dependencies** via [pip3](https://pip.pypa.io/en/stable). + Run `pip3 install --upgrade google-analytics-data`. +5. **Review the comments starting with `TODO(developer)` and update the code +to use correct values. +6. **Run** with the command `python3 SNIPPET_NAME.py`. For example: +```sh + $ python3 quickstart.py +``` diff --git a/samples/snippets/get_common_metadata.py b/samples/snippets/get_common_metadata.py new file mode 100644 index 0000000..731da0d --- /dev/null +++ b/samples/snippets/get_common_metadata.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application retrieving dimension and metrics +metadata. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata +for more information. +""" +# [START analyticsdata_get_common_metadata] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import GetMetadataRequest +from google.analytics.data_v1beta.types import MetricType + + +def run_sample(): + """Runs the sample.""" + get_common_metadata() + + +def get_common_metadata(): + """Retrieves dimensions and metrics available for all Google Analytics 4 + properties.""" + client = BetaAnalyticsDataClient() + + # Set the Property ID to 0 for dimensions and metrics common + # to all properties. In this special mode, this method will + # not return custom dimensions and metrics. + property_id = 0 + request = GetMetadataRequest(name=f"properties/{property_id}/metadata") + response = client.get_metadata(request) + + print("Dimensions and metrics available for all Google Analytics 4 properties:") + print_get_metadata_response(response) + + +def print_get_metadata_response(response): + """Prints results of the getMetadata call.""" + # [START analyticsdata_print_get_metadata_response] + for dimension in response.dimensions: + print("DIMENSION") + print(f"{dimension.api_name} ({dimension.ui_name}): {dimension.description}") + print(f"custom_definition: {dimension.custom_definition}") + if dimension.deprecated_api_names: + print(f"Deprecated API names: {dimension.deprecated_api_names}") + print("") + + for metric in response.metrics: + print("METRIC") + print(f"{metric.api_name} ({metric.ui_name}): {metric.description}") + print(f"custom_definition: {dimension.custom_definition}") + if metric.expression: + print(f"Expression: {metric.expression}") + + metric_type = MetricType(metric.type_).name + print(f"Type: {metric_type}") + + if metric.deprecated_api_names: + print(f"Deprecated API names: {metric.deprecated_api_names}") + print("") + # [END analyticsdata_print_get_metadata_response] + + +# [END analyticsdata_get_common_metadata] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/get_common_metadata_test.py b/samples/snippets/get_common_metadata_test.py new file mode 100644 index 0000000..ae11969 --- /dev/null +++ b/samples/snippets/get_common_metadata_test.py @@ -0,0 +1,21 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import get_common_metadata + + +def test_get_common_metadata(capsys): + get_common_metadata.get_common_metadata() + out, _ = capsys.readouterr() + assert "Dimensions and metrics" in out diff --git a/samples/snippets/get_metadata_by_property_id.py b/samples/snippets/get_metadata_by_property_id.py new file mode 100644 index 0000000..6950ced --- /dev/null +++ b/samples/snippets/get_metadata_by_property_id.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application retrieving dimension and metrics +metadata. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata +for more information. +""" +# [START analyticsdata_get_metadata_by_property_id] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import GetMetadataRequest + +from get_common_metadata import print_get_metadata_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + get_metadata_by_property_id(property_id) + + +def get_metadata_by_property_id(property_id="YOUR-GA4-PROPERTY-ID"): + """Retrieves dimensions and metrics available for a Google Analytics 4 + property, including custom fields.""" + client = BetaAnalyticsDataClient() + + request = GetMetadataRequest(name=f"properties/{property_id}/metadata") + response = client.get_metadata(request) + + print( + f"Dimensions and metrics available for Google Analytics 4 " + f"property {property_id} (including custom fields):" + ) + print_get_metadata_response(response) + + +# [END analyticsdata_get_metadata_by_property_id] + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/get_metadata_by_property_id_test.py b/samples/snippets/get_metadata_by_property_id_test.py new file mode 100644 index 0000000..958f4b1 --- /dev/null +++ b/samples/snippets/get_metadata_by_property_id_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import get_metadata_by_property_id + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_get_metadata_by_property_id(capsys): + get_metadata_by_property_id.get_metadata_by_property_id(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Dimensions and metrics" in out diff --git a/samples/snippets/quickstart.py b/samples/snippets/quickstart.py index 7572097..ea1d771 100644 --- a/samples/snippets/quickstart.py +++ b/samples/snippets/quickstart.py @@ -15,13 +15,10 @@ # limitations under the License. """Google Analytics Data API sample quickstart application. - This application demonstrates the usage of the Analytics Data API using service account credentials. - Before you start the application, please review the comments starting with "TODO(developer)" and update the code to use correct values. - Usage: pip3 install --upgrade google-analytics-data python3 quickstart.py @@ -48,7 +45,7 @@ def sample_run_report(property_id="YOUR-GA4-PROPERTY-ID"): # [START analyticsdata_run_report] request = RunReportRequest( - property="properties/" + str(property_id), + property=f"properties/{property_id}", dimensions=[Dimension(name="city")], metrics=[Metric(name="activeUsers")], date_ranges=[DateRange(start_date="2020-03-31", end_date="today")], diff --git a/samples/snippets/quickstart_json_credentials.py b/samples/snippets/quickstart_json_credentials.py index a30c8ea..97c2889 100644 --- a/samples/snippets/quickstart_json_credentials.py +++ b/samples/snippets/quickstart_json_credentials.py @@ -54,7 +54,7 @@ def sample_run_report(property_id="YOUR-GA4-PROPERTY-ID", credentials_json_path= # [START analyticsdata_json_credentials_run_report] request = RunReportRequest( - property="properties/" + str(property_id), + property=f"properties/{property_id}", dimensions=[Dimension(name="city")], metrics=[Metric(name="activeUsers")], date_ranges=[DateRange(start_date="2020-03-31", end_date="today")], diff --git a/samples/snippets/quickstart_oauth2.py b/samples/snippets/quickstart_oauth2.py index 83aae0b..aa488ee 100644 --- a/samples/snippets/quickstart_oauth2.py +++ b/samples/snippets/quickstart_oauth2.py @@ -15,19 +15,16 @@ # limitations under the License. """Google Analytics Data API sample quickstart application. - This application demonstrates the usage of the Analytics Data API using OAuth2 credentials. - Before you start the application, please review the comments starting with "TODO(developer)" and update the code to use correct values. - Usage: pip3 install --upgrade google-auth-oauthlib pip3 install --upgrade google-analytics-data python3 quickstart_oauth2.py """ -# [START analyticsdata_quickstart_oauth2] +# [START analyticsdata_oauth2_quickstart] from google.analytics.data import BetaAnalyticsDataClient from google.analytics.data_v1beta.types import DateRange from google.analytics.data_v1beta.types import Dimension @@ -44,7 +41,7 @@ def sample_run_report(credentials=None, property_id="YOUR-GA4-PROPERTY-ID"): client = BetaAnalyticsDataClient(credentials=credentials) request = RunReportRequest( - property="properties/" + str(property_id), + property=f"properties/{property_id}", dimensions=[Dimension(name="city")], metrics=[Metric(name="activeUsers")], date_ranges=[DateRange(start_date="2020-03-31", end_date="today")], @@ -59,7 +56,7 @@ def sample_run_report(credentials=None, property_id="YOUR-GA4-PROPERTY-ID"): def get_credentials(): """Creates an OAuth2 credentials instance.""" - # [START analyticsdata_initialize] + # [START analyticsdata_oauth2_initialize] appflow = flow.InstalledAppFlow.from_client_secrets_file( "client_secrets.json", scopes=["https://www.googleapis.com/auth/analytics.readonly"], @@ -75,7 +72,7 @@ def get_credentials(): else: appflow.run_console() return appflow.credentials - # [END analyticsdata_initialize] + # [END analyticsdata_oauth2_initialize] def main(): @@ -83,7 +80,8 @@ def main(): sample_run_report(credentials) -# [END analyticsdata_quickstart_oauth2] +# [END analyticsdata_oauth2_quickstart] + if __name__ == "__main__": main() diff --git a/samples/snippets/run_batch_report.py b/samples/snippets/run_batch_report.py new file mode 100644 index 0000000..dfd155e --- /dev/null +++ b/samples/snippets/run_batch_report.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the batch creation +of multiple reports. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/batchRunReports +for more information. +""" +# [START analyticsdata_run_batch_report] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import BatchRunReportsRequest +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_batch_report(property_id) + + +def run_batch_report(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a batch report on a Google Analytics 4 property.""" + client = BetaAnalyticsDataClient() + + request = BatchRunReportsRequest( + property=f"properties/{property_id}", + requests=[ + RunReportRequest( + dimensions=[ + Dimension(name="country"), + Dimension(name="region"), + Dimension(name="city"), + ], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="2021-01-03", end_date="2021-01-09")], + ), + RunReportRequest( + dimensions=[ + Dimension(name="browser"), + ], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="2021-01-01", end_date="2021-01-31")], + ), + ], + ) + response = client.batch_run_reports(request) + + print("Batch report results:") + for report in response.reports: + print_run_report_response(report) + + +# [END analyticsdata_run_batch_report] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_batch_report_test.py b/samples/snippets/run_batch_report_test.py new file mode 100644 index 0000000..880c10b --- /dev/null +++ b/samples/snippets/run_batch_report_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_batch_report + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_batch_report(capsys): + run_batch_report.run_batch_report(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Batch report result" in out diff --git a/samples/snippets/run_pivot_report.py b/samples/snippets/run_pivot_report.py new file mode 100644 index 0000000..dc3ce91 --- /dev/null +++ b/samples/snippets/run_pivot_report.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation of +a pivot report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runPivotReport +for more information. +""" +# [START analyticsdata_run_pivot_report] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import OrderBy +from google.analytics.data_v1beta.types import Pivot +from google.analytics.data_v1beta.types import RunPivotReportRequest + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_pivot_report(property_id) + + +def run_pivot_report(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a pivot query to build a report of session counts by country, + pivoted by the browser dimension..""" + client = BetaAnalyticsDataClient() + + request = RunPivotReportRequest( + property=f"properties/{property_id}", + date_ranges=[ + DateRange(start_date="2021-01-01", end_date="2021-01-30"), + ], + pivots=[ + Pivot( + field_names=["country"], + limit=250, + order_bys=[ + OrderBy( + dimension=OrderBy.DimensionOrderBy(dimension_name="country") + ) + ], + ), + Pivot( + field_names=["browser"], + offset=3, + limit=3, + order_bys=[ + OrderBy( + metric=OrderBy.MetricOrderBy(metric_name="sessions"), desc=True + ) + ], + ), + ], + metrics=[Metric(name="sessions")], + dimensions=[ + Dimension(name="country"), + Dimension(name="browser"), + ], + ) + response = client.run_pivot_report(request) + print_run_pivot_report_response(response) + + +def print_run_pivot_report_response(response): + """Prints results of a runPivotReport call.""" + # [START analyticsdata_print_run_pivot_report_response] + print("Report result:") + for row in response.rows: + for dimension_value in row.dimension_values: + print(dimension_value.value) + + for metric_value in row.metric_values: + print(metric_value.value) + # [END analyticsdata_print_run_pivot_report_response] + + +# [END analyticsdata_run_pivot_report] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_pivot_report_test.py b/samples/snippets/run_pivot_report_test.py new file mode 100644 index 0000000..da010a1 --- /dev/null +++ b/samples/snippets/run_pivot_report_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_pivot_report + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_pivot_report(capsys): + run_pivot_report.run_pivot_report(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_realtime_report.py b/samples/snippets/run_realtime_report.py new file mode 100644 index 0000000..f106a16 --- /dev/null +++ b/samples/snippets/run_realtime_report.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation of +a realtime report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runRealtimeReport +for more information. +""" +# [START analyticsdata_run_realtime_report] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunRealtimeReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_realtime_report(property_id) + + +def run_realtime_report(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a realtime report on a Google Analytics 4 property.""" + client = BetaAnalyticsDataClient() + + request = RunRealtimeReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="country")], + metrics=[Metric(name="activeUsers")], + ) + response = client.run_realtime_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_realtime_report] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_realtime_report_test.py b/samples/snippets/run_realtime_report_test.py new file mode 100644 index 0000000..b0a643e --- /dev/null +++ b/samples/snippets/run_realtime_report_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_realtime_report + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_realtime_report(capsys): + run_realtime_report.run_realtime_report(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_realtime_report_with_multiple_dimensions.py b/samples/snippets/run_realtime_report_with_multiple_dimensions.py new file mode 100644 index 0000000..3726681 --- /dev/null +++ b/samples/snippets/run_realtime_report_with_multiple_dimensions.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation of +a realtime report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport +for more information. +""" +# [START analyticsdata_run_realtime_report_with_multiple_dimensions] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunRealtimeReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_realtime_report_with_multiple_dimensions(property_id) + + +def run_realtime_report_with_multiple_dimensions(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a realtime report on a Google Analytics 4 property.""" + client = BetaAnalyticsDataClient() + + request = RunRealtimeReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="country"), Dimension(name="city")], + metrics=[Metric(name="activeUsers")], + ) + response = client.run_realtime_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_realtime_report_with_multiple_dimensions] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_realtime_report_with_multiple_dimensions_test.py b/samples/snippets/run_realtime_report_with_multiple_dimensions_test.py new file mode 100644 index 0000000..2f0f057 --- /dev/null +++ b/samples/snippets/run_realtime_report_with_multiple_dimensions_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_multiple_dimensions + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_multiple_dimensions(capsys): + run_report_with_multiple_dimensions.run_report_with_multiple_dimensions( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_realtime_report_with_multiple_metrics.py b/samples/snippets/run_realtime_report_with_multiple_metrics.py new file mode 100644 index 0000000..c87731d --- /dev/null +++ b/samples/snippets/run_realtime_report_with_multiple_metrics.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation of +a realtime report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport +for more information. +""" +# [START analyticsdata_run_realtime_report_with_multiple_metrics] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunRealtimeReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_realtime_report_with_multiple_metrics(property_id) + + +def run_realtime_report_with_multiple_metrics(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a realtime report on a Google Analytics 4 property.""" + client = BetaAnalyticsDataClient() + + request = RunRealtimeReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="unifiedScreenName")], + metrics=[Metric(name="screenPageViews"), Metric(name="conversions")], + ) + response = client.run_realtime_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_realtime_report_with_multiple_metrics] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_realtime_report_with_multiple_metrics_test.py b/samples/snippets/run_realtime_report_with_multiple_metrics_test.py new file mode 100644 index 0000000..92ab1eb --- /dev/null +++ b/samples/snippets/run_realtime_report_with_multiple_metrics_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_multiple_metrics + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_multiple_metrics(capsys): + run_report_with_multiple_metrics.run_report_with_multiple_metrics(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report.py b/samples/snippets/run_report.py new file mode 100644 index 0000000..c76f5ea --- /dev/null +++ b/samples/snippets/run_report.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation +of a basic report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport +for more information. +""" +# [START analyticsdata_run_report] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import MetricType +from google.analytics.data_v1beta.types import RunReportRequest + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report(property_id) + + +def run_report(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report of active users grouped by country.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="country")], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="2020-09-01", end_date="2020-09-15")], + ) + response = client.run_report(request) + print_run_report_response(response) + + +def print_run_report_response(response): + """Prints results of a runReport call.""" + # [START analyticsdata_print_run_report_response_header] + print(f"{response.row_count} rows received") + for dimensionHeader in response.dimension_headers: + print(f"Dimension header name: {dimensionHeader.name}") + for metricHeader in response.metric_headers: + metric_type = MetricType(metricHeader.type_).name + print(f"Metric header name: {metricHeader.name} ({metric_type})") + # [END analyticsdata_print_run_report_response_header] + + # [START analyticsdata_print_run_report_response_rows] + print("Report result:") + for row in response.rows: + for dimension_value in row.dimension_values: + print(dimension_value.value) + + for metric_value in row.metric_values: + print(metric_value.value) + # [END analyticsdata_print_run_report_response_rows] + + +# [END analyticsdata_run_report] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_test.py b/samples/snippets/run_report_test.py new file mode 100644 index 0000000..d6e6f2f --- /dev/null +++ b/samples/snippets/run_report_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_basic(capsys): + run_report.run_report(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_aggregations.py b/samples/snippets/run_report_with_aggregations.py new file mode 100644 index 0000000..3b77fd8 --- /dev/null +++ b/samples/snippets/run_report_with_aggregations.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +metric aggregations in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.metric_aggregations +for more information. +""" +# [START analyticsdata_run_report_with_aggregations] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import MetricAggregation +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_aggregations(property_id) + + +def run_report_with_aggregations(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report which includes total, maximum and minimum values for + each metric.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="country")], + metrics=[Metric(name="sessions")], + date_ranges=[DateRange(start_date="365daysAgo", end_date="today")], + metric_aggregations=[ + MetricAggregation.TOTAL, + MetricAggregation.MAXIMUM, + MetricAggregation.MINIMUM, + ], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_aggregations] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_aggregations_test.py b/samples/snippets/run_report_with_aggregations_test.py new file mode 100644 index 0000000..420c412 --- /dev/null +++ b/samples/snippets/run_report_with_aggregations_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_aggregations + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_aggregations(capsys): + run_report_with_aggregations.run_report_with_aggregations(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_cohorts.py b/samples/snippets/run_report_with_cohorts.py new file mode 100644 index 0000000..4bf15a5 --- /dev/null +++ b/samples/snippets/run_report_with_cohorts.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstratinf the usage of +cohort specification in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.cohort_spec +for more information. +""" +# [START analyticsdata_run_report_with_cohorts] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import Cohort +from google.analytics.data_v1beta.types import CohortSpec +from google.analytics.data_v1beta.types import CohortsRange +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_cohorts(property_id) + + +def run_report_with_cohorts(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report on a cohort of users whose first session happened on the + same week. The number of active users and user retention rate is calculated + for the cohort using WEEKLY granularity.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="cohort"), Dimension(name="cohortNthWeek")], + metrics=[ + Metric(name="cohortActiveUsers"), + Metric( + name="cohortRetentionRate", + expression="cohortActiveUsers/cohortTotalUsers", + ), + ], + cohort_spec=CohortSpec( + cohorts=[ + Cohort( + dimension="firstSessionDate", + name="cohort", + date_range=DateRange( + start_date="2021-01-03", end_date="2021-01-09" + ), + ) + ], + cohorts_range=CohortsRange( + start_offset=0, + end_offset=4, + granularity=CohortsRange.Granularity.WEEKLY, + ), + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_cohorts] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_cohorts_test.py b/samples/snippets/run_report_with_cohorts_test.py new file mode 100644 index 0000000..06907e7 --- /dev/null +++ b/samples/snippets/run_report_with_cohorts_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_cohorts + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_cohorts(capsys): + run_report_with_cohorts.run_report_with_cohorts(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_custom_parameters.py b/samples/snippets/run_report_with_custom_parameters.py new file mode 100644 index 0000000..e0a3191 --- /dev/null +++ b/samples/snippets/run_report_with_custom_parameters.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application. +""" +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import RunReportRequest + + +def run_report_with_custom_parameters(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a simple report on a Google Analytics 4 property.""" + client = BetaAnalyticsDataClient() + + # [START run_report_with_custom_parameters] + request = RunReportRequest() + response = client.run_report(request) + # [END run_report_with_custom_parameters] + + print("Report result:") + for row in response.rows: + print(row.dimension_values[0].value, row.metric_values[0].value) + + +if __name__ == "__main__": + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_custom_parameters(property_id) diff --git a/samples/snippets/run_report_with_date_ranges.py b/samples/snippets/run_report_with_date_ranges.py new file mode 100644 index 0000000..73fae80 --- /dev/null +++ b/samples/snippets/run_report_with_date_ranges.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +date ranges in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.date_ranges +for more information. +""" +# [START analyticsdata_run_report_with_date_ranges] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_date_ranges(property_id) + + +def run_report_with_date_ranges(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using two date ranges.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + date_ranges=[ + DateRange(start_date="2019-08-01", end_date="2019-08-14"), + DateRange(start_date="2020-08-01", end_date="2020-08-14"), + ], + dimensions=[Dimension(name="platform")], + metrics=[Metric(name="activeUsers")], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_date_ranges] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_date_ranges_test.py b/samples/snippets/run_report_with_date_ranges_test.py new file mode 100644 index 0000000..552f969 --- /dev/null +++ b/samples/snippets/run_report_with_date_ranges_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_date_ranges + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_date_ranges(capsys): + run_report_with_date_ranges.run_report_with_date_ranges(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_dimension_and_metric_filters.py b/samples/snippets/run_report_with_dimension_and_metric_filters.py new file mode 100644 index 0000000..8935e32 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_and_metric_filters.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +dimension and metric filters in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.dimension_filter +for more information. +""" +# [START analyticsdata_run_report_with_dimension_and_metric_filters] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Filter +from google.analytics.data_v1beta.types import FilterExpression +from google.analytics.data_v1beta.types import FilterExpressionList +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import NumericValue +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_dimension_and_metric_filters(property_id) + + +def run_report_with_dimension_and_metric_filters(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using both metric and dimension filters. A dimension filter + limits the report to include only users who made an in-app purchase using + Android platform. A metric filter specifies that only users with session + counts larger than 1,000 should be included.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="city")], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="2020-03-31", end_date="today")], + metric_filter=FilterExpression( + filter=Filter( + field_name="sessions", + numeric_filter=Filter.NumericFilter( + operation=Filter.NumericFilter.Operation.GREATER_THAN, + value=NumericValue(int64_value=1000), + ), + ) + ), + dimension_filter=FilterExpression( + and_group=FilterExpressionList( + expressions=[ + FilterExpression( + filter=Filter( + field_name="platform", + string_filter=Filter.StringFilter( + match_type=Filter.StringFilter.MatchType.EXACT, + value="Android", + ), + ) + ), + FilterExpression( + filter=Filter( + field_name="eventName", + string_filter=Filter.StringFilter( + match_type=Filter.StringFilter.MatchType.EXACT, + value="in_app_purchase", + ), + ) + ), + ] + ) + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_dimension_and_metric_filters] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_dimension_and_metric_filters_test.py b/samples/snippets/run_report_with_dimension_and_metric_filters_test.py new file mode 100644 index 0000000..5499574 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_and_metric_filters_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_dimension_and_metric_filters + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_dimension_and_metric_filters(capsys): + run_report_with_dimension_and_metric_filters.run_report_with_dimension_and_metric_filters( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_dimension_exclude_filter.py b/samples/snippets/run_report_with_dimension_exclude_filter.py new file mode 100644 index 0000000..938cee9 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_exclude_filter.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +dimension and metric filters in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.dimension_filter +for more information. +""" +# [START analyticsdata_run_report_with_dimension_exclude_filter] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Filter +from google.analytics.data_v1beta.types import FilterExpression +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_dimension_exclude_filter(property_id) + + +def run_report_with_dimension_exclude_filter(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using a filter with `not_expression`. The dimension filter + selects for when `pageTitle` is not `My Homepage`. + + This sample uses relative date range values. See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/DateRange + for more information. + """ + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="pageTitle")], + metrics=[Metric(name="sessions")], + date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")], + dimension_filter=FilterExpression( + not_expression=FilterExpression( + filter=Filter( + field_name="pageTitle", + string_filter=Filter.StringFilter(value="My Homepage"), + ) + ) + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_dimension_exclude_filter] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_dimension_exclude_filter_test.py b/samples/snippets/run_report_with_dimension_exclude_filter_test.py new file mode 100644 index 0000000..3cef3fb --- /dev/null +++ b/samples/snippets/run_report_with_dimension_exclude_filter_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_dimension_exclude_filter + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_dimension_exclude_filter(capsys): + run_report_with_dimension_exclude_filter.run_report_with_dimension_exclude_filter( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_dimension_filter.py b/samples/snippets/run_report_with_dimension_filter.py new file mode 100644 index 0000000..d9568a7 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_filter.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +dimension and metric filters in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.dimension_filter +for more information. +""" +# [START analyticsdata_run_report_with_dimension_filter] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Filter +from google.analytics.data_v1beta.types import FilterExpression +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_dimension_filter(property_id) + + +def run_report_with_dimension_filter(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using a dimension filter. The call returns a time series + report of `eventCount` when `eventName` is `first_open` for each date. + + This sample uses relative date range values. See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/DateRange + for more information. + """ + + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="date")], + metrics=[Metric(name="eventCount")], + date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")], + dimension_filter=FilterExpression( + filter=Filter( + field_name="eventName", + string_filter=Filter.StringFilter(value="first_open"), + ) + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_dimension_filter] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_dimension_filter_test.py b/samples/snippets/run_report_with_dimension_filter_test.py new file mode 100644 index 0000000..b4e5791 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_filter_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_dimension_filter + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_dimension_filter(capsys): + run_report_with_dimension_filter.run_report_with_dimension_filter(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_dimension_in_list_filter.py b/samples/snippets/run_report_with_dimension_in_list_filter.py new file mode 100644 index 0000000..e4bd7e3 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_in_list_filter.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +dimension and metric filters in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.dimension_filter +for more information. +""" +# [START analyticsdata_run_report_with_dimension_in_list_filter] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Filter +from google.analytics.data_v1beta.types import FilterExpression +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_dimension_in_list_filter(property_id) + + +def run_report_with_dimension_in_list_filter(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using a dimension filter with `in_list_filter` expression. + The filter selects for when `eventName` is set to one of three event names + specified in the query. + + This sample uses relative date range values. See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/DateRange + for more information. + """ + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="eventName")], + metrics=[Metric(name="sessions")], + date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")], + dimension_filter=FilterExpression( + filter=Filter( + field_name="eventName", + in_list_filter=Filter.InListFilter( + values=[ + "purchase", + "in_app_purchase", + "app_store_subscription_renew", + ] + ), + ) + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_dimension_in_list_filter] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_dimension_in_list_filter_test.py b/samples/snippets/run_report_with_dimension_in_list_filter_test.py new file mode 100644 index 0000000..60f34a5 --- /dev/null +++ b/samples/snippets/run_report_with_dimension_in_list_filter_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_dimension_in_list_filter + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_dimension_in_list_filter(capsys): + run_report_with_dimension_in_list_filter.run_report_with_dimension_in_list_filter( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_multiple_dimension_filters.py b/samples/snippets/run_report_with_multiple_dimension_filters.py new file mode 100644 index 0000000..e1002af --- /dev/null +++ b/samples/snippets/run_report_with_multiple_dimension_filters.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +dimension and metric filters in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.dimension_filter +for more information. +""" +# [START analyticsdata_run_report_with_multiple_dimension_filters] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Filter +from google.analytics.data_v1beta.types import FilterExpression +from google.analytics.data_v1beta.types import FilterExpressionList +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_multiple_dimension_filters(property_id) + + +def run_report_with_multiple_dimension_filters(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using multiple dimension filters joined as `and_group` + expression. The filter selects for when both `browser` is `Chrome` and + `countryId` is `US`. + + This sample uses relative date range values. See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/DateRange + for more information. + """ + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="browser")], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")], + dimension_filter=FilterExpression( + and_group=FilterExpressionList( + expressions=[ + FilterExpression( + filter=Filter( + field_name="browser", + string_filter=Filter.StringFilter(value="Chrome"), + ) + ), + FilterExpression( + filter=Filter( + field_name="countryId", + string_filter=Filter.StringFilter(value="US"), + ) + ), + ] + ) + ), + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_multiple_dimension_filters] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_multiple_dimension_filters_test.py b/samples/snippets/run_report_with_multiple_dimension_filters_test.py new file mode 100644 index 0000000..82f2160 --- /dev/null +++ b/samples/snippets/run_report_with_multiple_dimension_filters_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_multiple_dimension_filters + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_multiple_dimension_filters(capsys): + run_report_with_multiple_dimension_filters.run_report_with_multiple_dimension_filters( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_multiple_dimensions.py b/samples/snippets/run_report_with_multiple_dimensions.py new file mode 100644 index 0000000..78a4a1c --- /dev/null +++ b/samples/snippets/run_report_with_multiple_dimensions.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation +of a basic report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport +for more information. +""" +# [START analyticsdata_run_report_with_multiple_dimensions] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_multiple_dimensions(property_id) + + +def run_report_with_multiple_dimensions(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report of active users grouped by three dimensions.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[ + Dimension(name="country"), + Dimension(name="region"), + Dimension(name="city"), + ], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="7daysAgo", end_date="today")], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_multiple_dimensions] + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_multiple_dimensions_test.py b/samples/snippets/run_report_with_multiple_dimensions_test.py new file mode 100644 index 0000000..2f0f057 --- /dev/null +++ b/samples/snippets/run_report_with_multiple_dimensions_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_multiple_dimensions + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_multiple_dimensions(capsys): + run_report_with_multiple_dimensions.run_report_with_multiple_dimensions( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_multiple_metrics.py b/samples/snippets/run_report_with_multiple_metrics.py new file mode 100644 index 0000000..d3546df --- /dev/null +++ b/samples/snippets/run_report_with_multiple_metrics.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the creation +of a basic report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport +for more information. +""" +# [START analyticsdata_run_report_with_multiple_metrics] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_multiple_metrics(property_id) + + +def run_report_with_multiple_metrics(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report of active users, new users and total revenue grouped by + date dimension.""" + client = BetaAnalyticsDataClient() + + # Runs a report of active users grouped by three dimensions. + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="date")], + metrics=[ + Metric(name="activeUsers"), + Metric(name="newUsers"), + Metric(name="totalRevenue"), + ], + date_ranges=[DateRange(start_date="7daysAgo", end_date="today")], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_multiple_metrics] + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_multiple_metrics_test.py b/samples/snippets/run_report_with_multiple_metrics_test.py new file mode 100644 index 0000000..92ab1eb --- /dev/null +++ b/samples/snippets/run_report_with_multiple_metrics_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_multiple_metrics + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_multiple_metrics(capsys): + run_report_with_multiple_metrics.run_report_with_multiple_metrics(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_named_date_ranges.py b/samples/snippets/run_report_with_named_date_ranges.py new file mode 100644 index 0000000..a4f0d17 --- /dev/null +++ b/samples/snippets/run_report_with_named_date_ranges.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +date ranges in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/DateRange#FIELDS.name +for more information. +""" +# [START analyticsdata_run_report_with_date_ranges] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_named_date_ranges(property_id) + + +def run_report_with_named_date_ranges(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report using named date ranges.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + date_ranges=[ + DateRange(start_date="2020-01-01", end_date="2020-01-31", name="year_ago"), + DateRange( + start_date="2021-01-01", end_date="2021-01-31", name="current_year" + ), + ], + dimensions=[Dimension(name="country")], + metrics=[Metric(name="sessions")], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_date_ranges] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_named_date_ranges_test.py b/samples/snippets/run_report_with_named_date_ranges_test.py new file mode 100644 index 0000000..0c0637f --- /dev/null +++ b/samples/snippets/run_report_with_named_date_ranges_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_named_date_ranges + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_named_date_ranges(capsys): + run_report_with_named_date_ranges.run_report_with_named_date_ranges( + TEST_PROPERTY_ID + ) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_ordering.py b/samples/snippets/run_report_with_ordering.py new file mode 100644 index 0000000..f55bf5c --- /dev/null +++ b/samples/snippets/run_report_with_ordering.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the ordering of + report rows. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.order_bys +for more information. +""" +# [START analyticsdata_run_report_with_ordering] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import OrderBy +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_ordering(property_id) + + +def run_report_with_ordering(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report of active users grouped by three dimensions, ordered by + the total revenue in descending order.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[Dimension(name="date")], + metrics=[ + Metric(name="activeUsers"), + Metric(name="newUsers"), + Metric(name="totalRevenue"), + ], + date_ranges=[DateRange(start_date="7daysAgo", end_date="today")], + order_bys=[ + OrderBy(metric=OrderBy.MetricOrderBy(metric_name="totalRevenue"), desc=True) + ], + ) + response = client.run_report(request) + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_ordering] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_ordering_test.py b/samples/snippets/run_report_with_ordering_test.py new file mode 100644 index 0000000..28c7297 --- /dev/null +++ b/samples/snippets/run_report_with_ordering_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_ordering + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_ordering(capsys): + run_report_with_ordering.run_report_with_ordering(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_pagination.py b/samples/snippets/run_report_with_pagination.py new file mode 100644 index 0000000..487f325 --- /dev/null +++ b/samples/snippets/run_report_with_pagination.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the use of +pagination to retrieve large result sets. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.offset +for more information. +""" +# [START analyticsdata_run_report_with_pagination] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + +from run_report import print_run_report_response + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_pagination(property_id) + + +def run_report_with_pagination(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report several times, each time retrieving a portion of result + using pagination.""" + client = BetaAnalyticsDataClient() + + # [START analyticsdata_run_report_with_pagination_page1] + request = RunReportRequest( + property=f"properties/{property_id}", + date_ranges=[DateRange(start_date="365daysAgo", end_date="yesterday")], + dimensions=[ + Dimension(name="firstUserSource"), + Dimension(name="firstUserMedium"), + Dimension(name="firstUserCampaignName"), + ], + metrics=[ + Metric(name="sessions"), + Metric(name="conversions"), + Metric(name="totalRevenue"), + ], + limit=100000, + offset=0, + ) + response = client.run_report(request) + # [END analyticsdata_run_report_with_pagination_page1] + print_run_report_response(response) + + # Run the same report with a different offset value to retrieve the second + # page of a response. + # [START analyticsdata_run_report_with_pagination_page2] + request = RunReportRequest( + property=f"properties/{property_id}", + date_ranges=[DateRange(start_date="365daysAgo", end_date="yesterday")], + dimensions=[ + Dimension(name="firstUserSource"), + Dimension(name="firstUserMedium"), + Dimension(name="firstUserCampaignName"), + ], + metrics=[ + Metric(name="sessions"), + Metric(name="conversions"), + Metric(name="totalRevenue"), + ], + limit=100000, + offset=100000, + ) + response = client.run_report(request) + # [END analyticsdata_run_report_with_pagination_page2] + print_run_report_response(response) + + +# [END analyticsdata_run_report_with_pagination] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_pagination_test.py b/samples/snippets/run_report_with_pagination_test.py new file mode 100644 index 0000000..b9b65e7 --- /dev/null +++ b/samples/snippets/run_report_with_pagination_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_pagination + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_pagination(capsys): + run_report_with_pagination.run_report_with_pagination(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out diff --git a/samples/snippets/run_report_with_property_quota.py b/samples/snippets/run_report_with_property_quota.py new file mode 100644 index 0000000..f62414a --- /dev/null +++ b/samples/snippets/run_report_with_property_quota.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Analytics Data API sample application demonstrating the usage of +property quota metadata. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.return_property_quota +for more information. +""" +# [START analyticsdata_run_report_with_property_quota] +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import DateRange +from google.analytics.data_v1beta.types import Dimension +from google.analytics.data_v1beta.types import Metric +from google.analytics.data_v1beta.types import RunReportRequest + + +def run_sample(): + """Runs the sample.""" + # TODO(developer): Replace this variable with your Google Analytics 4 + # property ID before running the sample. + property_id = "YOUR-GA4-PROPERTY-ID" + run_report_with_property_quota(property_id) + + +def run_report_with_property_quota(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a report and prints property quota information.""" + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + return_property_quota=True, + dimensions=[Dimension(name="country")], + metrics=[ + Metric(name="activeUsers"), + ], + date_ranges=[DateRange(start_date="7daysAgo", end_date="today")], + ) + response = client.run_report(request) + + # [START analyticsdata_run_report_with_property_quota_print_response] + if response.property_quota: + print( + f"Tokens per day quota consumed: {response.property_quota.tokens_per_day.consumed}, " + f"remaining: {response.property_quota.tokens_per_day.remaining}." + ) + + print( + f"Tokens per hour quota consumed: {response.property_quota.tokens_per_hour.consumed}, " + f"remaining: {response.property_quota.tokens_per_hour.remaining}." + ) + + print( + f"Concurrent requests quota consumed: {response.property_quota.concurrent_requests.consumed}, " + f"remaining: {response.property_quota.concurrent_requests.remaining}." + ) + + print( + f"Server errors per project per hour quota consumed: {response.property_quota.server_errors_per_project_per_hour.consumed}, " + f"remaining: {response.property_quota.server_errors_per_project_per_hour.remaining}." + ) + print( + f"Potentially thresholded requests per hour quota consumed: {response.property_quota.potentially_thresholded_requests_per_hour.consumed}, " + f"remaining: {response.property_quota.potentially_thresholded_requests_per_hour.remaining}." + ) + # [END analyticsdata_run_report_with_property_quota_print_response] + + +# [END analyticsdata_run_report_with_property_quota] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_report_with_property_quota_test.py b/samples/snippets/run_report_with_property_quota_test.py new file mode 100644 index 0000000..1b17fb8 --- /dev/null +++ b/samples/snippets/run_report_with_property_quota_test.py @@ -0,0 +1,25 @@ +# Copyright 2021 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import run_report_with_property_quota + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_report_with_property_quota(capsys): + run_report_with_property_quota.run_report_with_property_quota(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Tokens per day quota consumed" in out From dc0f3ab9cc7b6e6ca93e79c207cadf30b8600975 Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Fri, 16 Apr 2021 17:22:08 -0400 Subject: [PATCH 03/14] chore: prevent normalization of semver versioning (#64) * chore: prevent normalization of semver versioning * chore: update workaround to make sic work --- setup.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e8c419..c100c12 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,21 @@ import os import setuptools # type: ignore +# Disable version normalization performed by setuptools.setup() +try: + # Try the approach of using sic(), added in setuptools 46.1.0 + from setuptools import sic +except ImportError: + # Try the approach of replacing packaging.version.Version + sic = lambda v: v + try: + # setuptools >=39.0.0 uses packaging from setuptools.extern + from setuptools.extern import packaging + except ImportError: + # setuptools <39.0.0 uses packaging from pkg_resources.extern + from pkg_resources.extern import packaging + packaging.version.Version = packaging.version.LegacyVersion + version = "0.5.0" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -30,7 +45,7 @@ setuptools.setup( name="google-analytics-data", - version=version, + version=sic(version), long_description=readme, author="Google LLC", author_email="googleapis-packages@google.com", From 430dc5478437422e697cb92a8285d7dcd0b0b53e Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:00:25 -0400 Subject: [PATCH 04/14] chore(revert): revert preventing normalization (#66) reverts previous commit for preventing normalization of versioning --- setup.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/setup.py b/setup.py index c100c12..6e8c419 100644 --- a/setup.py +++ b/setup.py @@ -19,21 +19,6 @@ import os import setuptools # type: ignore -# Disable version normalization performed by setuptools.setup() -try: - # Try the approach of using sic(), added in setuptools 46.1.0 - from setuptools import sic -except ImportError: - # Try the approach of replacing packaging.version.Version - sic = lambda v: v - try: - # setuptools >=39.0.0 uses packaging from setuptools.extern - from setuptools.extern import packaging - except ImportError: - # setuptools <39.0.0 uses packaging from pkg_resources.extern - from pkg_resources.extern import packaging - packaging.version.Version = packaging.version.LegacyVersion - version = "0.5.0" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -45,7 +30,7 @@ setuptools.setup( name="google-analytics-data", - version=sic(version), + version=version, long_description=readme, author="Google LLC", author_email="googleapis-packages@google.com", From 3cd5ba3ab5d3dbff44c60a58cfa5677aa1568a6d Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Wed, 28 Apr 2021 11:46:25 -0400 Subject: [PATCH 05/14] chore: use `gcp-sphinx-docfx-yaml` (#68) makes use of the updated plugin for generating DocFX YAMLs --- noxfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 1f30a08..a8c05a9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -205,9 +205,7 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - # sphinx-docfx-yaml supports up to sphinx version 1.5.5. - # https://github.com/docascode/sphinx-docfx-yaml/issues/97 - session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") + session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( From d1fac043be5d963af0868f5319660c53e80d7e5e Mon Sep 17 00:00:00 2001 From: "google-cloud-policy-bot[bot]" <80869356+google-cloud-policy-bot[bot]@users.noreply.github.com> Date: Wed, 12 May 2021 13:32:06 +0000 Subject: [PATCH 06/14] chore: add SECURITY.md (#69) chore: add SECURITY.md --- SECURITY.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..8b58ae9 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,7 @@ +# Security Policy + +To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). + +The Google Security Team will respond within 5 working days of your report on g.co/vulnz. + +We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. From e6c44fd7913381aaf67836060241038749b89291 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 12 May 2021 17:36:51 -0400 Subject: [PATCH 07/14] chore: add library type to .repo-metadata.json (#71) --- .repo-metadata.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.repo-metadata.json b/.repo-metadata.json index 019ad78..bbf8320 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -6,6 +6,7 @@ "issue_tracker": "https://issuetracker.google.com/issues?q=componentid:187400%2B%20", "release_level": "beta", "language": "python", + "library_type": "GAPIC_AUTO", "repo": "googleapis/python-analytics-data", "distribution_name": "google-analytics-data", "api_id": "analyticsdata.googleapis.com", From 675ae9fb45bc4ea1adbbba1a302f04daf6368fbf Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 14 May 2021 22:50:02 -0400 Subject: [PATCH 08/14] chore: migrate to owl bot (#72) This PR migrates from autosynth to [owl bot](https://github.com/googleapis/repo-automation-bots/tree/master/packages/owl-bot). owl bot will save time for maintainers as it will automatically open PRs when there are updates in [googleapis-gen](https://github.com/googleapis/googleapis-gen/tree/master/google) without requiring maintainers to run `synthtool` to build the client from protos. Additionally, similar to autosynth, PRs will be automatically opened when there are template updates. fix(deps): require google-api-core>=1.22.2 --- .github/.OwlBot.lock.yaml | 4 + .github/.OwlBot.yaml | 26 +++++ .github/header-checker-lint.yml | 2 +- .kokoro/release.sh | 4 +- .kokoro/release/common.cfg | 14 +-- .pre-commit-config.yaml | 16 +++- CONTRIBUTING.rst | 16 +--- docs/_static/custom.css | 13 ++- docs/conf.py | 13 +++ noxfile.py | 36 ++++--- synth.py => owlbot.py | 20 ++-- renovate.json | 5 +- setup.py | 2 +- synth.metadata | 165 -------------------------------- testing/constraints-3.6.txt | 4 +- 15 files changed, 105 insertions(+), 235 deletions(-) create mode 100644 .github/.OwlBot.lock.yaml create mode 100644 .github/.OwlBot.yaml rename synth.py => owlbot.py (73%) delete mode 100644 synth.metadata diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml new file mode 100644 index 0000000..d49860b --- /dev/null +++ b/.github/.OwlBot.lock.yaml @@ -0,0 +1,4 @@ +docker: + digest: sha256:457583330eec64daa02aeb7a72a04d33e7be2428f646671ce4045dcbc0191b1e + image: gcr.io/repo-automation-bots/owlbot-python:latest + diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml new file mode 100644 index 0000000..4414ad9 --- /dev/null +++ b/.github/.OwlBot.yaml @@ -0,0 +1,26 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker: + image: gcr.io/repo-automation-bots/owlbot-python:latest + +deep-remove-regex: + - /owl-bot-staging + +deep-copy-regex: + - source: /google/analytics/data/(v.*)/.*-py/(.*) + dest: /owl-bot-staging/$1/$2 + +begin-after-commit-hash: a21f1091413a260393548c1b2ac44b7347923f08 + diff --git a/.github/header-checker-lint.yml b/.github/header-checker-lint.yml index fc281c0..6fe78aa 100644 --- a/.github/header-checker-lint.yml +++ b/.github/header-checker-lint.yml @@ -1,6 +1,6 @@ {"allowedCopyrightHolders": ["Google LLC"], "allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"], - "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt"], + "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt", "**/__init__.py", "samples/**/constraints.txt", "samples/**/constraints-test.txt"], "sourceFileExtensions": [ "ts", "js", diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 5e94b60..3c81019 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google_cloud_pypi_password") +TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") cd github/python-analytics-data python3 setup.py sdist bdist_wheel -twine upload --username gcloudpypi --password "${TWINE_PASSWORD}" dist/* +twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index f0df3a7..c5b901a 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,18 +23,8 @@ env_vars: { value: "github/python-analytics-data/.kokoro/release.sh" } -# Fetch PyPI password -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "google_cloud_pypi_password" - } - } -} - # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" -} \ No newline at end of file + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9024b1..1bbd787 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,17 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: @@ -12,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.1 hooks: - id: flake8 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6f3e68d..559f9db 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -160,21 +160,7 @@ Running System Tests auth settings and change some configuration in your project to run all the tests. -- System tests will be run against an actual project and - so you'll need to provide some environment variables to facilitate - authentication to your project: - - - ``GOOGLE_APPLICATION_CREDENTIALS``: The path to a JSON key file; - Such a file can be downloaded directly from the developer's console by clicking - "Generate new JSON key". See private key - `docs `__ - for more details. - -- Once you have downloaded your json keys, set the environment variable - ``GOOGLE_APPLICATION_CREDENTIALS`` to the absolute path of the json file:: - - $ export GOOGLE_APPLICATION_CREDENTIALS="/Users//path/to/app_credentials.json" - +- System tests will be run against an actual project. You should use local credentials from gcloud when possible. See `Best practices for application authentication `__. Some tests require a service account. For those tests see `Authenticating as a service account `__. ************* Test Coverage diff --git a/docs/_static/custom.css b/docs/_static/custom.css index bcd37bb..b0a2954 100644 --- a/docs/_static/custom.css +++ b/docs/_static/custom.css @@ -1,9 +1,20 @@ div#python2-eol { border-color: red; border-width: medium; -} +} /* Ensure minimum width for 'Parameters' / 'Returns' column */ dl.field-list > dt { min-width: 100px } + +/* Insert space between methods for readability */ +dl.method { + padding-top: 10px; + padding-bottom: 10px +} + +/* Insert empty space between classes */ +dl.class { + padding-bottom: 50px +} diff --git a/docs/conf.py b/docs/conf.py index f261e5b..7c5c210 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,17 @@ # -*- coding: utf-8 -*- +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # google-analytics-data documentation build configuration file # diff --git a/noxfile.py b/noxfile.py index a8c05a9..c09ac63 100644 --- a/noxfile.py +++ b/noxfile.py @@ -18,6 +18,7 @@ from __future__ import absolute_import import os +import pathlib import shutil import nox @@ -30,6 +31,8 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + # 'docfx' is excluded since it only needs to run in 'docs-presubmit' nox.options.sessions = [ "unit", @@ -59,16 +62,9 @@ def lint(session): session.run("flake8", "google", "tests") -@nox.session(python="3.6") +@nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. - - Format code to uniform standard. - - This currently uses Python 3.6 due to the automated Kokoro run of synthtool. - That run uses an image that doesn't have 3.6 installed. Before updating this - check the state of the `gcp_ubuntu_config` we use for that Kokoro run. - """ + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( "black", *BLACK_PATHS, @@ -84,13 +80,15 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. - session.install("asyncmock", "pytest-asyncio") - session.install( - "mock", "pytest", "pytest-cov", + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) + session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - session.install("-e", ".") + session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) + + session.install("-e", ".", "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -117,15 +115,15 @@ def unit(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": session.skip("RUN_SYSTEM_TESTS is set to false, skipping") - # Sanity check: Only run tests if the environment variable is set. - if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): - session.skip("Credentials must be set via environment variable") # Install pyopenssl for mTLS testing. if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": session.install("pyopenssl") @@ -141,10 +139,8 @@ def system(session): # Install all test dependencies, then install this package into the # virtualenv's dist-packages. - session.install( - "mock", "pytest", "google-cloud-testutils", - ) - session.install("-e", ".") + session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: diff --git a/synth.py b/owlbot.py similarity index 73% rename from synth.py rename to owlbot.py index 27ce6d0..4e47074 100644 --- a/synth.py +++ b/owlbot.py @@ -19,31 +19,23 @@ import synthtool.gcp as gcp from synthtool.languages import python -gapic = gcp.GAPICBazel() common = gcp.CommonTemplates() -versions = ["v1alpha", "v1beta"] - -# ---------------------------------------------------------------------------- -# Generate analytics data GAPIC layer -# ---------------------------------------------------------------------------- -for version in versions: - library = gapic.py_library( - service="analyticsdata", - version=version, - bazel_target=f"//google/analytics/data/{version}:google-analytics-data-{version}-py", - ) +default_version = "v1beta" +for library in s.get_staging_dirs(default_version): s.move( library, excludes=[ "setup.py", "README.rst", "docs/index.rst", - f"scripts/fixup_data_{version}_keywords.py", + f"scripts/fixup_data_{library.name}_keywords.py", ], ) +s.remove_staging_dirs() + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- @@ -66,4 +58,4 @@ """``^[a-zA-Z0-9_]$``""", ) -s.shell.run(["nox", "-s", "blacken"], hide_output=False) +s.shell.run(["nox", "-s", "blacken"], hide_output=False) \ No newline at end of file diff --git a/renovate.json b/renovate.json index f08bc22..c048955 100644 --- a/renovate.json +++ b/renovate.json @@ -2,5 +2,8 @@ "extends": [ "config:base", ":preserveSemverRanges" ], - "ignorePaths": [".pre-commit-config.yaml"] + "ignorePaths": [".pre-commit-config.yaml"], + "pip_requirements": { + "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"] + } } diff --git a/setup.py b/setup.py index 6e8c419..96ffb0c 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ platforms="Posix; MacOS X; Windows", include_package_data=True, install_requires=( - "google-api-core[grpc] >= 1.22.0, < 2.0.0dev", + "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", "libcst >= 0.2.5", "proto-plus >= 1.4.0", ), diff --git a/synth.metadata b/synth.metadata deleted file mode 100644 index 1729cec..0000000 --- a/synth.metadata +++ /dev/null @@ -1,165 +0,0 @@ -{ - "sources": [ - { - "git": { - "name": ".", - "remote": "https://github.com/googleapis/python-analytics-data.git", - "sha": "1c1d58f1ee88e50ce92c40b0ec58c19cec631297" - } - }, - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "95dd24960cf9f794ef583e59ad9f1fabe1c4a924", - "internalRef": "365882072" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "79c8dd7ee768292f933012d3a69a5b4676404cda" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "79c8dd7ee768292f933012d3a69a5b4676404cda" - } - } - ], - "destinations": [ - { - "client": { - "source": "googleapis", - "apiName": "analyticsdata", - "apiVersion": "v1alpha", - "language": "python", - "generator": "bazel" - } - }, - { - "client": { - "source": "googleapis", - "apiName": "analyticsdata", - "apiVersion": "v1beta", - "language": "python", - "generator": "bazel" - } - } - ], - "generatedFiles": [ - ".coveragerc", - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/header-checker-lint.yml", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic-head.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic-head.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic-head.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples-against-head.sh", - ".kokoro/test-samples-impl.sh", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/data_v1alpha/alpha_analytics_data.rst", - "docs/data_v1alpha/services.rst", - "docs/data_v1alpha/types.rst", - "docs/data_v1beta/beta_analytics_data.rst", - "docs/data_v1beta/services.rst", - "docs/data_v1beta/types.rst", - "docs/multiprocessing.rst", - "google/analytics/data/__init__.py", - "google/analytics/data/py.typed", - "google/analytics/data_v1alpha/__init__.py", - "google/analytics/data_v1alpha/py.typed", - "google/analytics/data_v1alpha/services/__init__.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/client.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py", - "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py", - "google/analytics/data_v1alpha/types/__init__.py", - "google/analytics/data_v1alpha/types/analytics_data_api.py", - "google/analytics/data_v1alpha/types/data.py", - "google/analytics/data_v1beta/__init__.py", - "google/analytics/data_v1beta/py.typed", - "google/analytics/data_v1beta/services/__init__.py", - "google/analytics/data_v1beta/services/beta_analytics_data/__init__.py", - "google/analytics/data_v1beta/services/beta_analytics_data/async_client.py", - "google/analytics/data_v1beta/services/beta_analytics_data/client.py", - "google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py", - "google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py", - "google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py", - "google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py", - "google/analytics/data_v1beta/types/__init__.py", - "google/analytics/data_v1beta/types/analytics_data_api.py", - "google/analytics/data_v1beta/types/data.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "scripts/decrypt-secrets.sh", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/data_v1alpha/__init__.py", - "tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py", - "tests/unit/gapic/data_v1beta/__init__.py", - "tests/unit/gapic/data_v1beta/test_beta_analytics_data.py" - ] -} \ No newline at end of file diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index e4e5e44..16e003f 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,6 +5,6 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.22.0 +google-api-core==1.22.2 libcst==0.2.5 -proto-plus==1.4.0 \ No newline at end of file +proto-plus==1.4.0 From f241d228ebd1815b4250459bfb6c996dc8cbaad4 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 15 May 2021 14:20:02 +0200 Subject: [PATCH 09/14] chore(deps): update dependency pytest to v6.2.4 (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pytest](https://docs.pytest.org/en/latest/) ([source](https://togithub.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | `==6.1.1` -> `==6.2.4` | [![age](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/compatibility-slim/6.1.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/confidence-slim/6.1.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
pytest-dev/pytest ### [`v6.2.4`](https://togithub.com/pytest-dev/pytest/releases/6.2.4) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.3...6.2.4) # pytest 6.2.4 (2021-05-04) ## Bug Fixes - [#​8539](https://togithub.com/pytest-dev/pytest/issues/8539): Fixed assertion rewriting on Python 3.10. ### [`v6.2.3`](https://togithub.com/pytest-dev/pytest/releases/6.2.3) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.2...6.2.3) # pytest 6.2.3 (2021-04-03) ## Bug Fixes - [#​8414](https://togithub.com/pytest-dev/pytest/issues/8414): pytest used to create directories under `/tmp` with world-readable permissions. This means that any user in the system was able to read information written by tests in temporary directories (such as those created by the `tmp_path`/`tmpdir` fixture). Now the directories are created with private permissions. pytest used silenty use a pre-existing `/tmp/pytest-of-` directory, even if owned by another user. This means another user could pre-create such a directory and gain control of another user\\'s temporary directory. Now such a condition results in an error. ### [`v6.2.2`](https://togithub.com/pytest-dev/pytest/releases/6.2.2) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.1...6.2.2) ##### pytest 6.2.2 (2021-01-25) ##### Bug Fixes - [#​8152](https://togithub.com/pytest-dev/pytest/issues/8152): Fixed "(<Skipped instance>)" being shown as a skip reason in the verbose test summary line when the reason is empty. - [#​8249](https://togithub.com/pytest-dev/pytest/issues/8249): Fix the `faulthandler` plugin for occasions when running with `twisted.logger` and using `pytest --capture=no`. ### [`v6.2.1`](https://togithub.com/pytest-dev/pytest/releases/6.2.1) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.0...6.2.1) # pytest 6.2.1 (2020-12-15) ## Bug Fixes - [#​7678](https://togithub.com/pytest-dev/pytest/issues/7678): Fixed bug where `ImportPathMismatchError` would be raised for files compiled in the host and loaded later from an UNC mounted path (Windows). - [#​8132](https://togithub.com/pytest-dev/pytest/issues/8132): Fixed regression in `approx`: in 6.2.0 `approx` no longer raises `TypeError` when dealing with non-numeric types, falling back to normal comparison. Before 6.2.0, array types like tf.DeviceArray fell through to the scalar case, and happened to compare correctly to a scalar if they had only one element. After 6.2.0, these types began failing, because they inherited neither from standard Python number hierarchy nor from `numpy.ndarray`. `approx` now converts arguments to `numpy.ndarray` if they expose the array protocol and are not scalars. This treats array-like objects like numpy arrays, regardless of size. ### [`v6.2.0`](https://togithub.com/pytest-dev/pytest/releases/6.2.0) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.1.2...6.2.0) # pytest 6.2.0 (2020-12-12) ## Breaking Changes - [#​7808](https://togithub.com/pytest-dev/pytest/issues/7808): pytest now supports python3.6+ only. ## Deprecations - [#​7469](https://togithub.com/pytest-dev/pytest/issues/7469): Directly constructing/calling the following classes/functions is now deprecated: - `_pytest.cacheprovider.Cache` - `_pytest.cacheprovider.Cache.for_config()` - `_pytest.cacheprovider.Cache.clear_cache()` - `_pytest.cacheprovider.Cache.cache_dir_from_config()` - `_pytest.capture.CaptureFixture` - `_pytest.fixtures.FixtureRequest` - `_pytest.fixtures.SubRequest` - `_pytest.logging.LogCaptureFixture` - `_pytest.pytester.Pytester` - `_pytest.pytester.Testdir` - `_pytest.recwarn.WarningsRecorder` - `_pytest.recwarn.WarningsChecker` - `_pytest.tmpdir.TempPathFactory` - `_pytest.tmpdir.TempdirFactory` These have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 7.0.0. - [#​7530](https://togithub.com/pytest-dev/pytest/issues/7530): The `--strict` command-line option has been deprecated, use `--strict-markers` instead. We have plans to maybe in the future to reintroduce `--strict` and make it an encompassing flag for all strictness related options (`--strict-markers` and `--strict-config` at the moment, more might be introduced in the future). - [#​7988](https://togithub.com/pytest-dev/pytest/issues/7988): The `@pytest.yield_fixture` decorator/function is now deprecated. Use pytest.fixture instead. `yield_fixture` has been an alias for `fixture` for a very long time, so can be search/replaced safely. ## Features - [#​5299](https://togithub.com/pytest-dev/pytest/issues/5299): pytest now warns about unraisable exceptions and unhandled thread exceptions that occur in tests on Python>=3.8. See unraisable for more information. - [#​7425](https://togithub.com/pytest-dev/pytest/issues/7425): New pytester fixture, which is identical to testdir but its methods return pathlib.Path when appropriate instead of `py.path.local`. This is part of the movement to use pathlib.Path objects internally, in order to remove the dependency to `py` in the future. Internally, the old Testdir <\_pytest.pytester.Testdir> is now a thin wrapper around Pytester <\_pytest.pytester.Pytester>, preserving the old interface. - [#​7695](https://togithub.com/pytest-dev/pytest/issues/7695): A new hook was added, pytest_markeval_namespace which should return a dictionary. This dictionary will be used to augment the "global" variables available to evaluate skipif/xfail/xpass markers. Pseudo example `conftest.py`: ```{.sourceCode .python} def pytest_markeval_namespace(): return {"color": "red"} ``` `test_func.py`: ```{.sourceCode .python} @​pytest.mark.skipif("color == 'blue'", reason="Color is not red") def test_func(): assert False ``` - [#​8006](https://togithub.com/pytest-dev/pytest/issues/8006): It is now possible to construct a ~pytest.MonkeyPatch object directly as `pytest.MonkeyPatch()`, in cases when the monkeypatch fixture cannot be used. Previously some users imported it from the private \_pytest.monkeypatch.MonkeyPatch namespace. Additionally, MonkeyPatch.context <pytest.MonkeyPatch.context> is now a classmethod, and can be used as `with MonkeyPatch.context() as mp: ...`. This is the recommended way to use `MonkeyPatch` directly, since unlike the `monkeypatch` fixture, an instance created directly is not `undo()`-ed automatically. ## Improvements - [#​1265](https://togithub.com/pytest-dev/pytest/issues/1265): Added an `__str__` implementation to the ~pytest.pytester.LineMatcher class which is returned from `pytester.run_pytest().stdout` and similar. It returns the entire output, like the existing `str()` method. - [#​2044](https://togithub.com/pytest-dev/pytest/issues/2044): Verbose mode now shows the reason that a test was skipped in the test's terminal line after the "SKIPPED", "XFAIL" or "XPASS". - [#​7469](https://togithub.com/pytest-dev/pytest/issues/7469) The types of builtin pytest fixtures are now exported so they may be used in type annotations of test functions. The newly-exported types are: - `pytest.FixtureRequest` for the request fixture. - `pytest.Cache` for the cache fixture. - `pytest.CaptureFixture[str]` for the capfd and capsys fixtures. - `pytest.CaptureFixture[bytes]` for the capfdbinary and capsysbinary fixtures. - `pytest.LogCaptureFixture` for the caplog fixture. - `pytest.Pytester` for the pytester fixture. - `pytest.Testdir` for the testdir fixture. - `pytest.TempdirFactory` for the tmpdir_factory fixture. - `pytest.TempPathFactory` for the tmp_path_factory fixture. - `pytest.MonkeyPatch` for the monkeypatch fixture. - `pytest.WarningsRecorder` for the recwarn fixture. Constructing them is not supported (except for MonkeyPatch); they are only meant for use in type annotations. Doing so will emit a deprecation warning, and may become a hard-error in pytest 7.0. Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy. - [#​7527](https://togithub.com/pytest-dev/pytest/issues/7527): When a comparison between namedtuple <collections.namedtuple> instances of the same type fails, pytest now shows the differing field names (possibly nested) instead of their indexes. - [#​7615](https://togithub.com/pytest-dev/pytest/issues/7615): Node.warn <\_pytest.nodes.Node.warn> now permits any subclass of Warning, not just PytestWarning <pytest.PytestWarning>. - [#​7701](https://togithub.com/pytest-dev/pytest/issues/7701): Improved reporting when using `--collected-only`. It will now show the number of collected tests in the summary stats. - [#​7710](https://togithub.com/pytest-dev/pytest/issues/7710): Use strict equality comparison for non-numeric types in pytest.approx instead of raising TypeError. This was the undocumented behavior before 3.7, but is now officially a supported feature. - [#​7938](https://togithub.com/pytest-dev/pytest/issues/7938): New `--sw-skip` argument which is a shorthand for `--stepwise-skip`. - [#​8023](https://togithub.com/pytest-dev/pytest/issues/8023): Added `'node_modules'` to default value for norecursedirs. - [#​8032](https://togithub.com/pytest-dev/pytest/issues/8032): doClassCleanups <unittest.TestCase.doClassCleanups> (introduced in unittest in Python and 3.8) is now called appropriately. ## Bug Fixes - [#​4824](https://togithub.com/pytest-dev/pytest/issues/4824): Fixed quadratic behavior and improved performance of collection of items using autouse fixtures and xunit fixtures. - [#​7758](https://togithub.com/pytest-dev/pytest/issues/7758): Fixed an issue where some files in packages are getting lost from `--lf` even though they contain tests that failed. Regressed in pytest 5.4.0. - [#​7911](https://togithub.com/pytest-dev/pytest/issues/7911): Directories created by by tmp_path and tmpdir are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites. - [#​7913](https://togithub.com/pytest-dev/pytest/issues/7913): Fixed a crash or hang in pytester.spawn <\_pytest.pytester.Pytester.spawn> when the readline module is involved. - [#​7951](https://togithub.com/pytest-dev/pytest/issues/7951): Fixed handling of recursive symlinks when collecting tests. - [#​7981](https://togithub.com/pytest-dev/pytest/issues/7981): Fixed symlinked directories not being followed during collection. Regressed in pytest 6.1.0. - [#​8016](https://togithub.com/pytest-dev/pytest/issues/8016): Fixed only one doctest being collected when using `pytest --doctest-modules path/to/an/__init__.py`. ## Improved Documentation - [#​7429](https://togithub.com/pytest-dev/pytest/issues/7429): Add more information and use cases about skipping doctests. - [#​7780](https://togithub.com/pytest-dev/pytest/issues/7780): Classes which should not be inherited from are now marked `final class` in the API reference. - [#​7872](https://togithub.com/pytest-dev/pytest/issues/7872): `_pytest.config.argparsing.Parser.addini()` accepts explicit `None` and `"string"`. - [#​7878](https://togithub.com/pytest-dev/pytest/issues/7878): In pull request section, ask to commit after editing changelog and authors file. ## Trivial/Internal Changes - [#​7802](https://togithub.com/pytest-dev/pytest/issues/7802): The `attrs` dependency requirement is now >=19.2.0 instead of >=17.4.0. - [#​8014](https://togithub.com/pytest-dev/pytest/issues/8014): .pyc files created by pytest's assertion rewriting now conform to the newer PEP-552 format on Python>=3.7. (These files are internal and only interpreted by pytest itself.) ### [`v6.1.2`](https://togithub.com/pytest-dev/pytest/releases/6.1.2) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.1.1...6.1.2) # pytest 6.1.2 (2020-10-28) ## Bug Fixes - [#​7758](https://togithub.com/pytest-dev/pytest/issues/7758): Fixed an issue where some files in packages are getting lost from `--lf` even though they contain tests that failed. Regressed in pytest 5.4.0. - [#​7911](https://togithub.com/pytest-dev/pytest/issues/7911): Directories created by tmpdir are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites. ## Improved Documentation - [#​7815](https://togithub.com/pytest-dev/pytest/issues/7815): Improve deprecation warning message for `pytest._fillfuncargs()`.
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻️ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-analytics-data). --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index be53bec..95ea1e6 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.1.1 +pytest==6.2.4 From 2a03f8d9c2a1a1dcaa3a9b3477c84bac0d129ce2 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sun, 16 May 2021 11:08:03 +0000 Subject: [PATCH 10/14] chore: new owl bot post processor docker image (#74) gcr.io/repo-automation-bots/owlbot-python:latest@sha256:4c981a6b6f2b8914a448d7b3a01688365be03e3ed26dfee399a6aa77fb112eaa --- .github/.OwlBot.lock.yaml | 5 ++--- .pre-commit-config.yaml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index d49860b..864c176 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,4 +1,3 @@ docker: - digest: sha256:457583330eec64daa02aeb7a72a04d33e7be2428f646671ce4045dcbc0191b1e - image: gcr.io/repo-automation-bots/owlbot-python:latest - + image: gcr.io/repo-automation-bots/owlbot-python:latest + digest: sha256:4c981a6b6f2b8914a448d7b3a01688365be03e3ed26dfee399a6aa77fb112eaa diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bbd787..4f00c7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.1 + rev: 3.9.2 hooks: - id: flake8 From 641731d14a5023ae130c4f61a4635e19b2ee8999 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 22 May 2021 09:20:15 +0000 Subject: [PATCH 11/14] chore: new owl bot post processor docker image (#75) gcr.io/repo-automation-bots/owlbot-python:latest@sha256:3c3a445b3ddc99ccd5d31edc4b4519729635d20693900db32c4f587ed51f7479 --- .github/.OwlBot.lock.yaml | 2 +- noxfile.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 864c176..46e3f02 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/repo-automation-bots/owlbot-python:latest - digest: sha256:4c981a6b6f2b8914a448d7b3a01688365be03e3ed26dfee399a6aa77fb112eaa + digest: sha256:3c3a445b3ddc99ccd5d31edc4b4519729635d20693900db32c4f587ed51f7479 diff --git a/noxfile.py b/noxfile.py index c09ac63..85c07fd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -179,7 +179,7 @@ def docs(session): """Build the docs for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark") + session.install("sphinx==4.0.1", "alabaster", "recommonmark") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( @@ -201,7 +201,9 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml") + session.install( + "sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml" + ) shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( From c6cd1dcdc1bc93a203dcc59239afd645c8aba0c5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 28 May 2021 16:06:11 +0000 Subject: [PATCH 12/14] chore: new owl bot post processor docker image (#76) gcr.io/repo-automation-bots/owlbot-python:latest@sha256:0856ca711da1fd5ec9d6d7da6c50aa0bbf550fb94acb47b55159a640791987bf --- .github/.OwlBot.lock.yaml | 2 +- docs/multiprocessing.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 46e3f02..127c2cd 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/repo-automation-bots/owlbot-python:latest - digest: sha256:3c3a445b3ddc99ccd5d31edc4b4519729635d20693900db32c4f587ed51f7479 + digest: sha256:0856ca711da1fd5ec9d6d7da6c50aa0bbf550fb94acb47b55159a640791987bf diff --git a/docs/multiprocessing.rst b/docs/multiprocessing.rst index 1cb29d4..536d17b 100644 --- a/docs/multiprocessing.rst +++ b/docs/multiprocessing.rst @@ -1,7 +1,7 @@ .. note:: - Because this client uses :mod:`grpcio` library, it is safe to + Because this client uses :mod:`grpc` library, it is safe to share instances across threads. In multiprocessing scenarios, the best practice is to create client instances *after* the invocation of - :func:`os.fork` by :class:`multiprocessing.Pool` or + :func:`os.fork` by :class:`multiprocessing.pool.Pool` or :class:`multiprocessing.Process`. From 7c5c69d6e0c463bdcab0f5d7b675d02c504f047f Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 28 May 2021 17:08:04 +0000 Subject: [PATCH 13/14] chore: new owl bot post processor docker image (#77) Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:c66ba3c8d7bc8566f47df841f98cd0097b28fff0b1864c86f5817f4c8c3e8600 --- .github/.OwlBot.lock.yaml | 2 +- docs/conf.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 127c2cd..da616c9 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/repo-automation-bots/owlbot-python:latest - digest: sha256:0856ca711da1fd5ec9d6d7da6c50aa0bbf550fb94acb47b55159a640791987bf + digest: sha256:c66ba3c8d7bc8566f47df841f98cd0097b28fff0b1864c86f5817f4c8c3e8600 diff --git a/docs/conf.py b/docs/conf.py index 7c5c210..40cb0ab 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -363,6 +363,7 @@ "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), } From eaa931fc05a1d2df7d8a23b2a619af34a6ba8b75 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:16:07 +0000 Subject: [PATCH 14/14] chore: release 0.5.1 (#63) :robot: I have created a release \*beep\* \*boop\* --- ### [0.5.1](https://www.github.com/googleapis/python-analytics-data/compare/v0.5.0...v0.5.1) (2021-05-28) ### Bug Fixes * **deps:** require google-api-core>=1.22.2 ([675ae9f](https://www.github.com/googleapis/python-analytics-data/commit/675ae9fb45bc4ea1adbbba1a302f04daf6368fbf)) ### Documentation * add sample code for Data API v1 ([#57](https://www.github.com/googleapis/python-analytics-data/issues/57)) ([a1e63c5](https://www.github.com/googleapis/python-analytics-data/commit/a1e63c56f5fa5835c528724c9d861c18cb34d6ad)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- CHANGELOG.md | 12 ++++++++++++ setup.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e15e9a5..d1ee825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +### [0.5.1](https://www.github.com/googleapis/python-analytics-data/compare/v0.5.0...v0.5.1) (2021-05-28) + + +### Bug Fixes + +* **deps:** require google-api-core>=1.22.2 ([675ae9f](https://www.github.com/googleapis/python-analytics-data/commit/675ae9fb45bc4ea1adbbba1a302f04daf6368fbf)) + + +### Documentation + +* add sample code for Data API v1 ([#57](https://www.github.com/googleapis/python-analytics-data/issues/57)) ([a1e63c5](https://www.github.com/googleapis/python-analytics-data/commit/a1e63c56f5fa5835c528724c9d861c18cb34d6ad)) + ## [0.5.0](https://www.github.com/googleapis/python-analytics-data/compare/v0.4.1...v0.5.0) (2021-04-01) diff --git a/setup.py b/setup.py index 96ffb0c..3370d8d 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "0.5.0" +version = "0.5.1" package_root = os.path.abspath(os.path.dirname(__file__))