|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2021 Google Inc. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +"""Google Analytics Admin API sample application which updates the Android app |
| 18 | +data stream. |
| 19 | +
|
| 20 | +See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.androidAppDataStreams/update |
| 21 | +for more information. |
| 22 | +""" |
| 23 | +# [START analyticsadmin_properties_android_app_data_streams_update] |
| 24 | +from google.analytics.admin import AnalyticsAdminServiceClient |
| 25 | +from google.analytics.admin_v1alpha.types import AndroidAppDataStream |
| 26 | +from google.protobuf.field_mask_pb2 import FieldMask |
| 27 | + |
| 28 | + |
| 29 | +def run_sample(): |
| 30 | + """Runs the sample.""" |
| 31 | + |
| 32 | + # !!! ATTENTION !!! |
| 33 | + # Running this sample may change/delete your Google Analytics account |
| 34 | + # configuration. Make sure to not use the Google Analytics property ID from |
| 35 | + # your production environment below. |
| 36 | + |
| 37 | + # TODO(developer): Replace this variable with your Google Analytics 4 |
| 38 | + # property ID (e.g. "123456") before running the sample. |
| 39 | + property_id = "YOUR-GA4-PROPERTY-ID" |
| 40 | + |
| 41 | + # TODO(developer): Replace this variable with your Android app data stream ID |
| 42 | + # (e.g. "123456") before running the sample. |
| 43 | + stream_id = "YOUR-ANDROID-APP-DATA-STREAM-ID" |
| 44 | + |
| 45 | + update_android_app_data_stream(property_id, stream_id) |
| 46 | + |
| 47 | + |
| 48 | +def update_android_app_data_stream(property_id, stream_id): |
| 49 | + """Updates the Android app data stream.""" |
| 50 | + client = AnalyticsAdminServiceClient() |
| 51 | + # This call updates the display name of the Android app data stream, as |
| 52 | + # indicated by the value of the `update_mask` field. The Android app data |
| 53 | + # stream to update is specified in the `name` field of the |
| 54 | + # `AndroidAppDataStream` instance. |
| 55 | + android_app_data_stream = client.update_android_app_data_stream( |
| 56 | + android_app_data_stream=AndroidAppDataStream( |
| 57 | + name=f"properties/{property_id}/androidAppDataStreams/{stream_id}", |
| 58 | + display_name="This is an updated test Android app data stream", |
| 59 | + ), |
| 60 | + update_mask=FieldMask(paths=["display_name"]), |
| 61 | + ) |
| 62 | + |
| 63 | + print("Result:") |
| 64 | + print(android_app_data_stream) |
| 65 | + |
| 66 | + |
| 67 | +# [END analyticsadmin_properties_android_app_data_streams_update] |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + run_sample() |
0 commit comments