From 55271cf72d578f7d590008dc2c8493d2d8b963f5 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 19 Jul 2022 14:19:41 +0200 Subject: [PATCH 1/3] chore(deps): update all dependencies (#248) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- 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 8e50bc8..edda3d8 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-analytics-data==0.12.0 +google-analytics-data==0.12.1 google-auth-oauthlib==0.5.1 \ No newline at end of file From af9d1300e296a60b86f12021c133d2eb7a4f71c1 Mon Sep 17 00:00:00 2001 From: ikuleshov Date: Tue, 19 Jul 2022 15:08:04 +0200 Subject: [PATCH 2/3] docs(samples): add runFunnelReport sample (#258) * docs(samples): add runFunnelReport sample * docs(samples): add runFunnelReport sample * Merge remote-tracking branch 'origin/funnel' into funnel # Conflicts: # samples/snippets/run_funnel_report.py * docs(samples): add runFunnelReport sample * docs(samples): add runFunnelReport sample Co-authored-by: Anthonios Partheniou --- samples/snippets/requirements.txt | 2 +- samples/snippets/run_funnel_report.py | 205 +++++++++++++++++++++ samples/snippets/run_funnel_report_test.py | 25 +++ 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 samples/snippets/run_funnel_report.py create mode 100644 samples/snippets/run_funnel_report_test.py diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index edda3d8..17cfb3f 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-analytics-data==0.12.1 +google-analytics-data==0.13.0 google-auth-oauthlib==0.5.1 \ No newline at end of file diff --git a/samples/snippets/run_funnel_report.py b/samples/snippets/run_funnel_report.py new file mode 100644 index 0000000..446a7a0 --- /dev/null +++ b/samples/snippets/run_funnel_report.py @@ -0,0 +1,205 @@ +#!/usr/bin/env python + +# Copyright 2022 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 funnel report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/properties/runFunnelReport +for more information. +""" +# [START analyticsdata_run_funnel_report] +from google.analytics.data_v1alpha import AlphaAnalyticsDataClient +from google.analytics.data_v1alpha.types import DateRange +from google.analytics.data_v1alpha.types import Dimension +from google.analytics.data_v1alpha.types import Funnel +from google.analytics.data_v1alpha.types import FunnelBreakdown +from google.analytics.data_v1alpha.types import FunnelEventFilter +from google.analytics.data_v1alpha.types import FunnelFieldFilter +from google.analytics.data_v1alpha.types import FunnelFilterExpression +from google.analytics.data_v1alpha.types import FunnelFilterExpressionList +from google.analytics.data_v1alpha.types import FunnelStep +from google.analytics.data_v1alpha.types import RunFunnelReportRequest +from google.analytics.data_v1alpha.types import StringFilter + + +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_funnel_report(property_id) + + +def run_funnel_report(property_id="YOUR-GA4-PROPERTY-ID"): + """Runs a funnel query to build a report with 5 funnel steps. + Step 1: First open/visit (event name is `first_open` or `first_visit`). + Step 2: Organic visitors (`firstUserMedium` dimension contains the term + "organic"). + Step 3: Session start (event name is `session_start`). + Step 4: Screen/Page view (event name is `screen_view` or `page_view`). + Step 5: Purchase (event name is `purchase` or `in_app_purchase`). + + The report configuration reproduces the default funnel report provided in + the Funnel Exploration template of the Google Analytics UI. + See more at https://support.google.com/analytics/answer/9327974 + """ + client = AlphaAnalyticsDataClient() + + request = RunFunnelReportRequest( + property=f"properties/{property_id}", + date_ranges=[DateRange(start_date="30daysAgo", end_date="today")], + funnel_breakdown=FunnelBreakdown( + breakdown_dimension=Dimension(name="deviceCategory") + ), + funnel=Funnel( + steps=[ + FunnelStep( + name="First open/visit", + filter_expression=FunnelFilterExpression( + or_group=FunnelFilterExpressionList( + expressions=[ + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="first_open" + ) + ), + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="first_visit" + ) + ), + ] + ) + ), + ), + FunnelStep( + name="Organic visitors", + filter_expression=FunnelFilterExpression( + funnel_field_filter=FunnelFieldFilter( + field_name="firstUserMedium", + string_filter=StringFilter( + match_type=StringFilter.MatchType.CONTAINS, + case_sensitive=False, + value="organic", + ), + ) + ), + ), + FunnelStep( + name="Session start", + filter_expression=FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="session_start" + ) + ), + ), + FunnelStep( + name="Screen/Page view", + filter_expression=FunnelFilterExpression( + or_group=FunnelFilterExpressionList( + expressions=[ + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="screen_view" + ) + ), + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="page_view" + ) + ), + ] + ) + ), + ), + FunnelStep( + name="Purchase", + filter_expression=FunnelFilterExpression( + or_group=FunnelFilterExpressionList( + expressions=[ + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="purchase" + ) + ), + FunnelFilterExpression( + funnel_event_filter=FunnelEventFilter( + event_name="in_app_purchase" + ) + ), + ] + ) + ), + ), + ] + ), + ) + response = client.run_funnel_report(request) + print_run_funnel_report_response(response) + + +# [START analyticsdata_print_run_funnel_report_response] +def print_funnel_sub_report(funnel_sub_report): + """Prints the contents of a FunnelSubReport object.""" + print("Dimension headers:") + for dimension_header in funnel_sub_report.dimension_headers: + print(dimension_header.name) + + print("\nMetric headers:") + for metric_header in funnel_sub_report.metric_headers: + print(metric_header.name) + + print("\nDimensions and metric values for each row in the report:") + for row_idx, row in enumerate(funnel_sub_report.rows): + print("\nRow #{}".format(row_idx)) + for field_idx, dimension_value in enumerate(row.dimension_values): + dimension_name = funnel_sub_report.dimension_headers[field_idx].name + print("{}: '{}'".format(dimension_name, dimension_value.value)) + + for field_idx, metric_value in enumerate(row.metric_values): + metric_name = funnel_sub_report.metric_headers[field_idx].name + print("{}: '{}'".format(metric_name, metric_value.value)) + + print("\nSampling metadata for each date range:") + for metadata_idx, metadata in enumerate( + funnel_sub_report.metadata.sampling_metadatas + ): + print( + "Sampling metadata for date range #{}: samplesReadCount={}, " + "samplingSpaceSize={}".format( + metadata_idx, metadata.samples_read_count, metadata.sampling_space_size + ) + ) + + +def print_run_funnel_report_response(response): + """Prints results of a runFunnelReport call.""" + print("Report result:") + print("=== FUNNEL VISUALIZATION ===") + print_funnel_sub_report(response.funnel_visualization) + + print("=== FUNNEL TABLE ===") + print_funnel_sub_report(response.funnel_table) + + +# [END analyticsdata_print_run_funnel_report_response] + + +# [END analyticsdata_run_funnel_report] + + +if __name__ == "__main__": + run_sample() diff --git a/samples/snippets/run_funnel_report_test.py b/samples/snippets/run_funnel_report_test.py new file mode 100644 index 0000000..e8b2aaa --- /dev/null +++ b/samples/snippets/run_funnel_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_funnel_report + +TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") + + +def test_run_funnel_report(capsys): + run_funnel_report.run_funnel_report(TEST_PROPERTY_ID) + out, _ = capsys.readouterr() + assert "Report result" in out From 34baea675a866546337d1f74281eb9583d88409b Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 19 Jul 2022 13:16:11 +0000 Subject: [PATCH 3/3] chore(main): release 0.13.1 (#259) :robot: I have created a release *beep* *boop* --- ## [0.13.1](https://github.com/googleapis/python-analytics-data/compare/v0.13.0...v0.13.1) (2022-07-19) ### Documentation * **samples:** add runFunnelReport sample ([#258](https://github.com/googleapis/python-analytics-data/issues/258)) ([af9d130](https://github.com/googleapis/python-analytics-data/commit/af9d1300e296a60b86f12021c133d2eb7a4f71c1)) --- 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 | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db553ea..2e8312f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.13.1](https://github.com/googleapis/python-analytics-data/compare/v0.13.0...v0.13.1) (2022-07-19) + + +### Documentation + +* **samples:** add runFunnelReport sample ([#258](https://github.com/googleapis/python-analytics-data/issues/258)) ([af9d130](https://github.com/googleapis/python-analytics-data/commit/af9d1300e296a60b86f12021c133d2eb7a4f71c1)) + ## [0.13.0](https://github.com/googleapis/python-analytics-data/compare/v0.12.1...v0.13.0) (2022-07-17) diff --git a/setup.py b/setup.py index ee7946a..6343069 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "0.13.0" +version = "0.13.1" package_root = os.path.abspath(os.path.dirname(__file__))