-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add samples for Measurement Protocol Secrets management methods (…
…#152) * update test configuration * remove custom noxfile configs for now * remove MaximumUserAccess rom sample * add comment in noxfile_config.py * run blacken session * lint * add pytest * Update noxfile_config.py * Update noxfile_config.py * delete enhanced measurement settings samples as this functionality is no longer supported in v1alpha * fix the samples tests * do not use the `maximum_user_access` field and `update` operation in properties.firebase_links tests as this is no longer supported in v1alpha * use `creator_email_address` instead of `email_address` field in properties.google_ads_links_list() test as the field has been renamed in v1alpha * fix the samples test * add samples for Measurement Protocol Secrets management methods * add samples for Measurement Protocol Secrets management methods * add samples for Measurement Protocol Secrets management methods * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update samples/properties_web_data_streams_measurement_protocol_secrets_delete.py Co-authored-by: Anthonios Partheniou <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
- Loading branch information
Showing
31 changed files
with
1,435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...-admin/samples/properties_android_app_data_streams_measurement_protocol_secrets_create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/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 creates a measurement | ||
protocol secret for the Android app data stream. | ||
See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.androidAppDataStreams.measurementProtocolSecrets/create | ||
for more information. | ||
""" | ||
# [START analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_create] | ||
from google.analytics.admin import AnalyticsAdminServiceClient | ||
from google.analytics.admin_v1alpha import MeasurementProtocolSecret | ||
|
||
|
||
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 Android app data stream ID | ||
# (e.g. "123456") before running the sample. | ||
stream_id = "YOUR-ANDROID-APP-DATA-STREAM-ID" | ||
|
||
create_measurement_protocol_secret(property_id, stream_id) | ||
|
||
|
||
def create_measurement_protocol_secret(property_id, stream_id): | ||
"""Creates a measurement protocol secret for the Android app data stream.""" | ||
client = AnalyticsAdminServiceClient() | ||
measurement_protocol_secret = client.create_measurement_protocol_secret( | ||
parent=f"properties/{property_id}/androidAppDataStreams/{stream_id}", | ||
measurement_protocol_secret=MeasurementProtocolSecret( | ||
display_name="New secret" | ||
), | ||
) | ||
|
||
print("Result:") | ||
print(f"Resource name: {measurement_protocol_secret.name}") | ||
print(f"Secret value: {measurement_protocol_secret.secret_value}") | ||
print(f"Display name: {measurement_protocol_secret.display_name}") | ||
|
||
|
||
# [END analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_create] | ||
|
||
|
||
if __name__ == "__main__": | ||
run_sample() |
30 changes: 30 additions & 0 deletions
30
...n/samples/properties_android_app_data_streams_measurement_protocol_secrets_create_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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_android_app_data_streams_measurement_protocol_secrets_create | ||
|
||
|
||
FAKE_PROPERTY_ID = "1" | ||
FAKE_STREAM_ID = "1" | ||
|
||
|
||
def test_properties_android_app_data_streams_measurement_protocol_secrets_create(): | ||
# 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_android_app_data_streams_measurement_protocol_secrets_create.create_measurement_protocol_secret( | ||
FAKE_PROPERTY_ID, FAKE_STREAM_ID | ||
) |
64 changes: 64 additions & 0 deletions
64
...-admin/samples/properties_android_app_data_streams_measurement_protocol_secrets_delete.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Admin API sample application which deletes the measurement | ||
protocol secret for the Android app data stream. | ||
See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.androidAppDataStreams.measurementProtocolSecrets/delete | ||
for more information. | ||
""" | ||
# [START analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_delete] | ||
from google.analytics.admin import AnalyticsAdminServiceClient | ||
|
||
|
||
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 Android app data stream ID | ||
# (e.g. "123456") before running the sample. | ||
stream_id = "YOUR-ANDROID-APP-DATA-STREAM-ID" | ||
|
||
# TODO(developer): Replace this variable with your measurement protocol | ||
# secret ID (e.g. "123456") before running the sample. | ||
secret_id = "YOUR-MEASUREMENT-PROTOCOL-SECRET-ID" | ||
|
||
delete_measurement_protocol_secret(property_id, stream_id, secret_id) | ||
|
||
|
||
def delete_measurement_protocol_secret(property_id, stream_id, secret_id): | ||
"""Deletes the measurement protocol secret for the Android app data | ||
stream.""" | ||
client = AnalyticsAdminServiceClient() | ||
client.delete_measurement_protocol_secret( | ||
name=f"properties/{property_id}/androidAppDataStreams/{stream_id}/measurementProtocolSecrets/{secret_id}" | ||
) | ||
print("Measurement protocol secret deleted") | ||
|
||
|
||
# [END analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_delete] | ||
|
||
|
||
if __name__ == "__main__": | ||
run_sample() |
31 changes: 31 additions & 0 deletions
31
...n/samples/properties_android_app_data_streams_measurement_protocol_secrets_delete_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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_android_app_data_streams_measurement_protocol_secrets_delete | ||
|
||
|
||
FAKE_PROPERTY_ID = "1" | ||
FAKE_STREAM_ID = "1" | ||
FAKE_SECRET_ID = "1" | ||
|
||
|
||
def test_properties_android_app_data_streams_measurement_protocol_secrets_delete(): | ||
# 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_android_app_data_streams_measurement_protocol_secrets_delete.delete_measurement_protocol_secret( | ||
FAKE_PROPERTY_ID, FAKE_STREAM_ID, FAKE_SECRET_ID | ||
) |
61 changes: 61 additions & 0 deletions
61
...ics-admin/samples/properties_android_app_data_streams_measurement_protocol_secrets_get.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/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 retrieves the details | ||
for the measurement protocol secret. | ||
See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.androidAppDataStreams.measurementProtocolSecrets/get | ||
for more information. | ||
""" | ||
# [START analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_get] | ||
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 Android app data stream ID | ||
# (e.g. "123456") before running the sample. | ||
stream_id = "YOUR-ANDROID-APP-DATA-STREAM-ID" | ||
|
||
# TODO(developer): Replace this variable with your measurement protocol | ||
# secret ID (e.g. "123456") before running the sample. | ||
secret_id = "YOUR-MEASUREMENT-PROTOCOL-SECRET-ID" | ||
|
||
get_measurement_protocol_secret(property_id, stream_id, secret_id) | ||
|
||
|
||
def get_measurement_protocol_secret(property_id, stream_id, secret_id): | ||
"""Retrieves the details for the measurement protocol secret.""" | ||
client = AnalyticsAdminServiceClient() | ||
measurement_protocol_secret = client.get_measurement_protocol_secret( | ||
name=f"properties/{property_id}/androidAppDataStreams/{stream_id}/measurementProtocolSecrets/{secret_id}" | ||
) | ||
|
||
print("Result:") | ||
print(f"Resource name: {measurement_protocol_secret.name}") | ||
print(f"Secret value: {measurement_protocol_secret.secret_value}") | ||
print(f"Display name: {measurement_protocol_secret.display_name}") | ||
|
||
|
||
# [END analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_get] | ||
|
||
|
||
if __name__ == "__main__": | ||
run_sample() |
29 changes: 29 additions & 0 deletions
29
...dmin/samples/properties_android_app_data_streams_measurement_protocol_secrets_get_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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_android_app_data_streams_measurement_protocol_secrets_get | ||
|
||
TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") | ||
TEST_STREAM_ID = os.getenv("GA_TEST_ANDROID_APP_DATA_STREAM_ID") | ||
TEST_SECRET_ID = os.getenv("GA_TEST_ANDROID_APP_DATA_SECRET_ID") | ||
|
||
|
||
def test_properties_android_app_data_streams_measurement_protocol_secrets_get(capsys): | ||
properties_android_app_data_streams_measurement_protocol_secrets_get.get_measurement_protocol_secret( | ||
TEST_PROPERTY_ID, TEST_STREAM_ID, TEST_SECRET_ID | ||
) | ||
out, _ = capsys.readouterr() | ||
assert "Result" in out |
59 changes: 59 additions & 0 deletions
59
...cs-admin/samples/properties_android_app_data_streams_measurement_protocol_secrets_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/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 lists measurement | ||
protocol secrets for the Android app data stream. | ||
See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.androidAppDataStreams.measurementProtocolSecrets/list | ||
for more information. | ||
""" | ||
# [START analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_list] | ||
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 Android app data stream ID | ||
# (e.g. "123456") before running the sample. | ||
stream_id = "YOUR-ANDROID-APP-DATA-STREAM-ID" | ||
list_measurement_protocol_secrets(property_id, stream_id) | ||
|
||
|
||
def list_measurement_protocol_secrets(property_id, stream_id): | ||
"""Lists measurement protocol secrets for the Android app data stream.""" | ||
client = AnalyticsAdminServiceClient() | ||
results = client.list_measurement_protocol_secrets( | ||
parent=f"properties/{property_id}/androidAppDataStreams/{stream_id}" | ||
) | ||
|
||
print("Result:") | ||
for measurement_protocol_secret in results: | ||
print("Result:") | ||
print(f"Resource name: {measurement_protocol_secret.name}") | ||
print(f"Secret value: {measurement_protocol_secret.secret_value}") | ||
print(f"Display name: {measurement_protocol_secret.display_name}") | ||
print() | ||
|
||
|
||
# [END analyticsadmin_properties_android_app_data_streams_measurement_protocol_secrets_list] | ||
|
||
|
||
if __name__ == "__main__": | ||
run_sample() |
29 changes: 29 additions & 0 deletions
29
...min/samples/properties_android_app_data_streams_measurement_protocol_secrets_list_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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_android_app_data_streams_measurement_protocol_secrets_list | ||
|
||
|
||
TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID") | ||
TEST_STREAM_ID = os.getenv("GA_TEST_ANDROID_APP_DATA_STREAM_ID") | ||
|
||
|
||
def test_properties_android_app_data_streams_measurement_protocol_secrets_list(capsys): | ||
properties_android_app_data_streams_measurement_protocol_secrets_list.list_measurement_protocol_secrets( | ||
TEST_PROPERTY_ID, TEST_STREAM_ID | ||
) | ||
out, _ = capsys.readouterr() | ||
assert "Result" in out |
Oops, something went wrong.