diff --git a/packages/google-analytics-admin/samples/noxfile_config.py b/packages/google-analytics-admin/samples/noxfile_config.py index b883a88ea367..f218482525c6 100644 --- a/packages/google-analytics-admin/samples/noxfile_config.py +++ b/packages/google-analytics-admin/samples/noxfile_config.py @@ -1,23 +1,19 @@ TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": True, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + "gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. "envs": { - "GA_TEST_PROPERTY_ID": "222596558", - "GA_TEST_ACCOUNT_ID": "123", - "GA_TEST_USER_LINK_ID": "123", - "GA_TEST_ANDROID_APP_DATA_STREAM_ID": "123", - "GA_TEST_IOS_APP_DATA_STREAM_ID": "123", - "GA_TEST_WEB_DATA_STREAM_ID": "123", + "GA_TEST_PROPERTY_ID": "276206997", + "GA_TEST_ACCOUNT_ID": "199820965", + "GA_TEST_USER_LINK_ID": "103401743041912607932", + "GA_TEST_PROPERTY_USER_LINK_ID": "105231969274497648555", + "GA_TEST_ANDROID_APP_DATA_STREAM_ID": "2828100949", + "GA_TEST_IOS_APP_DATA_STREAM_ID": "2828089289", + "GA_TEST_WEB_DATA_STREAM_ID": "2828068992", }, } diff --git a/packages/google-analytics-admin/samples/properties_firebase_links_create.py b/packages/google-analytics-admin/samples/properties_firebase_links_create.py index d259612df332..843179e19c8c 100644 --- a/packages/google-analytics-admin/samples/properties_firebase_links_create.py +++ b/packages/google-analytics-admin/samples/properties_firebase_links_create.py @@ -49,10 +49,7 @@ def create_firebase_link(property_id, firebase_project_id): client = AnalyticsAdminServiceClient() firebase_link = client.create_firebase_link( parent=f"properties/{property_id}", - firebase_link=FirebaseLink( - project=f"projects/{firebase_project_id}", - maximum_user_access="READ_AND_ANALYZE", - ), + firebase_link=FirebaseLink(project=f"projects/{firebase_project_id}"), ) print("Result:") diff --git a/packages/google-analytics-admin/samples/properties_firebase_links_list.py b/packages/google-analytics-admin/samples/properties_firebase_links_list.py index 0d5c2f175bfa..560363c305a7 100644 --- a/packages/google-analytics-admin/samples/properties_firebase_links_list.py +++ b/packages/google-analytics-admin/samples/properties_firebase_links_list.py @@ -22,7 +22,6 @@ """ # [START analyticsadmin_properties_firebase_links_list] from google.analytics.admin import AnalyticsAdminServiceClient -from google.analytics.admin_v1alpha.types import MaximumUserAccess def run_sample(): @@ -49,10 +48,6 @@ def print_firebase_link(firebase_link): """Prints the Firebase link details.""" print(f"Resource name: {firebase_link.name}") print(f"Firebase project: {firebase_link.project}") - print( - f"Maximum user access to the GA4 property: " - f"{MaximumUserAccess(firebase_link.maximum_user_access).name}" - ) print(f"Create time: {firebase_link.create_time}") diff --git a/packages/google-analytics-admin/samples/properties_firebase_links_update.py b/packages/google-analytics-admin/samples/properties_firebase_links_update.py deleted file mode 100644 index 085f74d5a0e6..000000000000 --- a/packages/google-analytics-admin/samples/properties_firebase_links_update.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/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 Admin API sample application which updates the Firebase -link on the specified Google Analytics 4 property. - -See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.firebaseLinks/update -for more information. -""" -# [START analyticsadmin_properties_firebase_links_update] -from google.analytics.admin import AnalyticsAdminServiceClient -from google.analytics.admin_v1alpha.types import FirebaseLink -from google.protobuf.field_mask_pb2 import FieldMask - - -def run_sample(): - """Runs the sample.""" - - # !!! ATTENTION !!! - # Running this sample may change/delete your Google Analytics account - # configuration. Make sure to not use the Google Analytics property ID from - # your production environment below. - - # TODO(developer): Replace this variable with your Google Analytics 4 - # property ID (e.g. "123456") before running the sample. - property_id = "YOUR-GA4-PROPERTY-ID" - - # TODO(developer): Replace this variable with your Firebase link ID - # (e.g. "123456") before running the sample. - firebase_link_id = "YOUR-FIREBASE-LINK-ID" - - update_firebase_link(property_id, firebase_link_id) - - -def update_firebase_link(property_id, firebase_link_id): - """Updates the Firebase link.""" - client = AnalyticsAdminServiceClient() - # This call updates the maximum user access to the GA4 property of the - # Firebase link as indicated by the value of the `update_mask` field. - # The Firebase link to update is specified in the `name` field of the - # `FirebaseLink` instance. - firebase_link = client.update_firebase_link( - firebase_link=FirebaseLink( - name=f"properties/{property_id}/firebaseLinks/{firebase_link_id}", - maximum_user_access="EDITOR_WITHOUT_LINK_MANAGEMENT", - ), - update_mask=FieldMask(paths=["maximum_user_access"]), - ) - - print("Result:") - print(firebase_link) - - -# [END analyticsadmin_properties_firebase_links_update] - - -if __name__ == "__main__": - run_sample() diff --git a/packages/google-analytics-admin/samples/properties_firebase_links_update_test.py b/packages/google-analytics-admin/samples/properties_firebase_links_update_test.py deleted file mode 100644 index dc07fb60e124..000000000000 --- a/packages/google-analytics-admin/samples/properties_firebase_links_update_test.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2021 Google LLC 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 pytest - -import properties_firebase_links_update - - -FAKE_PROPERTY_ID = "1" -FAKE_FIREBASE_LINK_ID = "1" - - -def test_properties_firebase_links_update(): - # This test ensures that the call is valid and reaches the server, even - # though the operation does not succeed due to permission error. - with pytest.raises(Exception, match="403 The caller does not have permission"): - properties_firebase_links_update.update_firebase_link( - FAKE_PROPERTY_ID, FAKE_FIREBASE_LINK_ID - ) diff --git a/packages/google-analytics-admin/samples/properties_google_ads_links_list.py b/packages/google-analytics-admin/samples/properties_google_ads_links_list.py index 1aa7e065064a..7109f1e317de 100644 --- a/packages/google-analytics-admin/samples/properties_google_ads_links_list.py +++ b/packages/google-analytics-admin/samples/properties_google_ads_links_list.py @@ -50,7 +50,7 @@ def print_google_ads_link(google_ads_link): print(f"Google Ads customer ID: {google_ads_link.customer_id}") print(f"Can manage clients: {google_ads_link.can_manage_clients}") print(f"Ads personalization enabled: {google_ads_link.ads_personalization_enabled}") - print(f"Email address of the link creator: {google_ads_link.email_address}") + print(f"Email address of the link creator: {google_ads_link.creator_email_address}") print(f"Create time: {google_ads_link.create_time}") print(f"Update time: {google_ads_link.update_time}") diff --git a/packages/google-analytics-admin/samples/properties_google_ads_links_list_test.py b/packages/google-analytics-admin/samples/properties_google_ads_links_list_test.py index 1f850a4feb6b..5396da0eb670 100644 --- a/packages/google-analytics-admin/samples/properties_google_ads_links_list_test.py +++ b/packages/google-analytics-admin/samples/properties_google_ads_links_list_test.py @@ -19,7 +19,7 @@ TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") -def test_properties_firebase_links_list(capsys): +def test_properties_google_ads_links_list(capsys): properties_google_ads_links_list.list_google_ads_links(TEST_PROPERTY_ID) out, _ = capsys.readouterr() assert "Result" in out diff --git a/packages/google-analytics-admin/samples/properties_ios_app_data_streams_get.py b/packages/google-analytics-admin/samples/properties_ios_app_data_streams_get.py index 02b775da91d5..50a617af6f6a 100644 --- a/packages/google-analytics-admin/samples/properties_ios_app_data_streams_get.py +++ b/packages/google-analytics-admin/samples/properties_ios_app_data_streams_get.py @@ -53,7 +53,7 @@ def print_ios_app_data_stream(ios_app_data_stream): print(f"Resource name: {ios_app_data_stream.name}") print(f"Display name: {ios_app_data_stream.display_name}") print(f"Firebase app ID: {ios_app_data_stream.firebase_app_id}") - print(f"Bundle ID: {ios_app_data_stream.bundleId}") + print(f"Bundle ID: {ios_app_data_stream.bundle_id}") print(f"Create time: {ios_app_data_stream.create_time}") print(f"Update time: {ios_app_data_stream.update_time}") diff --git a/packages/google-analytics-admin/samples/properties_user_links_batch_get_test.py b/packages/google-analytics-admin/samples/properties_user_links_batch_get_test.py index a862070d5561..4c8c4bb5b58e 100644 --- a/packages/google-analytics-admin/samples/properties_user_links_batch_get_test.py +++ b/packages/google-analytics-admin/samples/properties_user_links_batch_get_test.py @@ -17,7 +17,7 @@ import properties_user_links_batch_get TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") -TEST_USER_LINK_ID = os.getenv("GA_USER_LINK_ID") +TEST_USER_LINK_ID = os.getenv("GA_TEST_PROPERTY_USER_LINK_ID") def test_properties_user_links_batch_get(capsys): diff --git a/packages/google-analytics-admin/samples/properties_user_links_get_test.py b/packages/google-analytics-admin/samples/properties_user_links_get_test.py index dca1ca87c35d..14c99708e979 100644 --- a/packages/google-analytics-admin/samples/properties_user_links_get_test.py +++ b/packages/google-analytics-admin/samples/properties_user_links_get_test.py @@ -17,7 +17,7 @@ import properties_user_links_get TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") -TEST_USER_LINK_ID = os.getenv("GA_USER_LINK_ID") +TEST_USER_LINK_ID = os.getenv("GA_TEST_PROPERTY_USER_LINK_ID") def test_properties_user_links_get(capsys): diff --git a/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings.py b/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings.py deleted file mode 100644 index 65d7225d4c50..000000000000 --- a/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2021 Google LLC 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 Admin API sample application which prints the enhanced -measurement settings for the web stream. - -See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.webDataStreams/getEnhancedMeasurementSettings -for more information. -""" -# [START analyticsadmin_properties_web_data_streams_get_enhanced_measurement_settings] -from google.analytics.admin import AnalyticsAdminServiceClient - - -def run_sample(): - """Runs the sample.""" - # TODO(developer): Replace this variable with your Google Analytics 4 - # property ID (e.g. "123456") before running the sample. - property_id = "YOUR-GA4-PROPERTY-ID" - - # TODO(developer): Replace this variable with your web data stream ID - # (e.g. "123456") before running the sample. - stream_id = "YOUR-WEB-DATA-STREAM-ID" - - get_enhanced_measurement_settings(property_id, stream_id) - - -def get_enhanced_measurement_settings(property_id, stream_id): - """Retrieves the enhanced measurement settings for the web stream.""" - client = AnalyticsAdminServiceClient() - enhanced_measurement_settings = client.get_enhanced_measurement_settings( - name=f"properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings" - ) - - print("Result:") - print_enhanced_measurement_settings(enhanced_measurement_settings) - - -def print_enhanced_measurement_settings(enhanced_measurement_settings): - """Prints the enhanced measurement settings for a web stream.""" - print(f"Resource name: {enhanced_measurement_settings.name}") - print(f"Stream enabled: {enhanced_measurement_settings.streamEnabled}") - print(f"Page views enabled: {enhanced_measurement_settings.pageViewsEnabled}") - print(f"Scrolls enabled: {enhanced_measurement_settings.scrollsEnabled}") - print( - f"Outbound clicks enabled: {enhanced_measurement_settings.outboundClicksEnabled}" - ) - print(f"Site search enabled: {enhanced_measurement_settings.siteSearchEnabled}") - print( - f"Video engagement enabled: {enhanced_measurement_settings.videoEngagementEnabled}" - ) - print( - f"File downloads enabled: {enhanced_measurement_settings.fileDownloadsEnabled}" - ) - print(f"Page loads enabled: {enhanced_measurement_settings.pageLoadsEnabled}") - print(f"Page changes enabled: {enhanced_measurement_settings.pageChangesEnabled}") - print( - f"Search query parameter: {enhanced_measurement_settings.searchQueryParameter}" - ) - print(f"Uri query parameter: {enhanced_measurement_settings.uriQueryParameter}") - - -# [END analyticsadmin_properties_web_data_streams_get_enhanced_measurement_settings] - - -if __name__ == "__main__": - run_sample() diff --git a/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings_test.py b/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings_test.py deleted file mode 100644 index 34d7ccd44ca9..000000000000 --- a/packages/google-analytics-admin/samples/properties_web_data_streams_get_enhanced_measurement_settings_test.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2021 Google LLC 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 properties_web_data_streams_get_enhanced_measurement_settings - - -TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") -TEST_WEB_DATA_STREAM_ID = os.getenv("GA_TEST_WEB_DATA_STREAM_ID") - - -def test_properties_web_data_streams_get_enhanced_measurement_settings(capsys): - properties_web_data_streams_get_enhanced_measurement_settings.get_enhanced_measurement_settings( - TEST_PROPERTY_ID, TEST_WEB_DATA_STREAM_ID - ) - out, _ = capsys.readouterr() - assert "Result" in out diff --git a/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings.py b/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings.py deleted file mode 100644 index f02e1fb0d2db..000000000000 --- a/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2021 Google LLC 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 Admin API sample application which updates the enhanced -measurement settings for the web stream. - -See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.webDataStreams/updateEnhancedMeasurementSettings -for more information. -""" -# [START analyticsadmin_properties_web_data_streams_update_enhanced_measurement_settings] -from google.analytics.admin import AnalyticsAdminServiceClient -from google.analytics.admin_v1alpha.types import EnhancedMeasurementSettings -from google.protobuf.field_mask_pb2 import FieldMask - - - -def run_sample(): - """Runs the sample.""" - - # !!! ATTENTION !!! - # Running this sample may change/delete your Google Analytics account - # configuration. Make sure to not use the Google Analytics property ID from - # your production environment below. - - # TODO(developer): Replace this variable with your Google Analytics 4 - # property ID (e.g. "123456") before running the sample. - property_id = "YOUR-GA4-PROPERTY-ID" - - # TODO(developer): Replace this variable with your web data stream ID - # (e.g. "123456") before running the sample. - stream_id = "YOUR-WEB-DATA-STREAM-ID" - - update_enhanced_measurement_settings(property_id, stream_id) - - -def update_enhanced_measurement_settings(property_id, stream_id): - """Updates the enhanced measurement settings for the web stream.""" - client = AnalyticsAdminServiceClient() - # This call updates the `streamEnabled`, `fileDownloadsEnabled` measurement - # settings of the web data stream, as indicated by the value of the - # `update_mask` field. The web data stream to update is specified in the - # `name` field of the `EnhancedMeasurementSettings` instance. - enhanced_measurement_settings = client.update_enhanced_measurement_settings( - enhanced_measurement_settings=EnhancedMeasurementSettings( - name=f"properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings", - stream_enabled=False, - file_downloads_enabled=False, - ), - update_mask=FieldMask(paths=["stream_enabled", "file_downloads_enabled"]), - ) - - print("Result:") - print(enhanced_measurement_settings) - - -# [END analyticsadmin_properties_web_data_streams_update_enhanced_measurement_settings] - - -if __name__ == "__main__": - run_sample() diff --git a/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings_test.py b/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings_test.py deleted file mode 100644 index d692a0eb2653..000000000000 --- a/packages/google-analytics-admin/samples/properties_web_data_streams_update_enhanced_measurement_settings_test.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2021 Google LLC 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 pytest - -import properties_web_data_streams_update_enhanced_measurement_settings - - -FAKE_PROPERTY_ID = "1" -FAKE_STREAM_ID = "1" - - -def test_properties_web_data_streams_update(): - # This test ensures that the call is valid and reaches the server, even - # though the operation does not succeed due to permission error. - with pytest.raises(Exception, match="403 The caller does not have permission"): - properties_web_data_streams_update_enhanced_measurement_settings.update_enhanced_measurement_settings( - FAKE_PROPERTY_ID, FAKE_STREAM_ID - ) diff --git a/packages/google-analytics-admin/samples/quickstart.py b/packages/google-analytics-admin/samples/quickstart.py index 5653af44dc01..0e22289ac9d0 100644 --- a/packages/google-analytics-admin/samples/quickstart.py +++ b/packages/google-analytics-admin/samples/quickstart.py @@ -49,20 +49,24 @@ pip install google-analytics-admin """ + # [START ga_admin_list_accounts] def list_accounts(): - """Lists the available Google Analytics accounts.""" - from google.analytics.admin import AnalyticsAdminServiceClient - # Using a default constructor instructs the client to use the credentials - # specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. - client = AnalyticsAdminServiceClient() - - # Displays the configuration information for all Google Analytics accounts - # available to the authenticated user. - for account in client.list_accounts(): - print(account) + """Lists the available Google Analytics accounts.""" + from google.analytics.admin import AnalyticsAdminServiceClient + + # Using a default constructor instructs the client to use the credentials + # specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = AnalyticsAdminServiceClient() + + # Displays the configuration information for all Google Analytics accounts + # available to the authenticated user. + for account in client.list_accounts(): + print(account) + + # [END ga_admin_list_accounts] if __name__ == "__main__": - list_accounts() + list_accounts() diff --git a/packages/google-analytics-admin/samples/requirements-test.txt b/packages/google-analytics-admin/samples/requirements-test.txt new file mode 100644 index 000000000000..9299a7a8b069 --- /dev/null +++ b/packages/google-analytics-admin/samples/requirements-test.txt @@ -0,0 +1 @@ +pytest==6.2.5 \ No newline at end of file