Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f787a04
update test configuration
ikuleshov Sep 2, 2021
79093d1
remove custom noxfile configs for now
parthea Sep 2, 2021
8f1f957
remove MaximumUserAccess rom sample
parthea Sep 2, 2021
b674e0d
add comment in noxfile_config.py
parthea Sep 2, 2021
de94a95
run blacken session
parthea Sep 2, 2021
761d8aa
lint
parthea Sep 2, 2021
ee91693
add pytest
parthea Sep 2, 2021
6cfcf4f
Merge branch 'main' into master
parthea Oct 4, 2021
f12b2b1
Merge branch 'main' into master
ikuleshov Oct 4, 2021
7a7c6d2
Update noxfile_config.py
ikuleshov Oct 5, 2021
9366fdc
Update noxfile_config.py
ikuleshov Oct 5, 2021
a3e4f17
Merge remote-tracking branch 'upstream/main'
ikuleshov Oct 5, 2021
7de1885
Merge remote-tracking branch 'origin/master'
ikuleshov Oct 5, 2021
a88d15e
delete enhanced measurement settings samples as this functionality is…
ikuleshov Oct 5, 2021
e76ba96
fix the samples tests
ikuleshov Oct 5, 2021
3836b72
do not use the `maximum_user_access` field and `update` operation in …
ikuleshov Oct 5, 2021
d235358
use `creator_email_address` instead of `email_address` field in prope…
ikuleshov Oct 5, 2021
d5b923a
fix the samples test
ikuleshov Oct 5, 2021
f3d6fa7
Merge remote-tracking branch 'upstream/main'
ikuleshov Oct 13, 2021
6da346c
add samples for Conversion Event management methods
ikuleshov Oct 13, 2021
8d553d9
add samples for Conversion Event management methods
ikuleshov Oct 13, 2021
ae04a4e
Merge remote-tracking branch 'origin/events' into events
ikuleshov Oct 13, 2021
a9a6be8
add samples for Conversion Event management methods
ikuleshov Oct 13, 2021
15c0d70
Merge remote-tracking branch 'origin/events' into events
ikuleshov Oct 13, 2021
3212d33
Merge branch 'main' into events
parthea Oct 19, 2021
b437358
Merge branch 'main' into events
ikuleshov Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/noxfile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"GA_TEST_ANDROID_APP_DATA_STREAM_ID": "2828100949",
"GA_TEST_IOS_APP_DATA_STREAM_ID": "2828089289",
"GA_TEST_WEB_DATA_STREAM_ID": "2828068992",
"GA_TEST_CONVERSION_EVENT_ID": "2719963095"
},
}
62 changes: 62 additions & 0 deletions samples/properties_conversion_events_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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 creates a conversion
event for the Google Analytics 4 property.

See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.conversionEvents/create
for more information.
"""
# [START analyticsadmin_properties_conversion_events_create]
from google.analytics.admin import AnalyticsAdminServiceClient
from google.analytics.admin_v1alpha import ConversionEvent


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 account 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"

create_conversion_event(property_id)


def create_conversion_event(property_id):
"""Creates a conversion event for the Google Analytics 4 property."""
client = AnalyticsAdminServiceClient()
conversion_event = client.create_conversion_event(
parent=f"properties/{property_id}",
conversion_event=ConversionEvent(event_name="test_purchase"),
)

print("Result:")
print(f"Resource name: {conversion_event.name}")
print(f"Event name: {conversion_event.event_name}")
print(f"Create time: {conversion_event.create_time}")
print(f"Deletable: {conversion_event.deletable}")
print(f"Custom: {conversion_event.custom}")


# [END analyticsadmin_properties_conversion_events_create]

if __name__ == "__main__":
run_sample()
26 changes: 26 additions & 0 deletions samples/properties_conversion_events_create_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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_conversion_events_create

FAKE_PROPERTY_ID = "1"


def test_properties_conversion_events_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_conversion_events_create.create_conversion_event(FAKE_PROPERTY_ID)
60 changes: 60 additions & 0 deletions samples/properties_conversion_events_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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 deletes a conversion
event for the Google Analytics 4 property.


See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.conversionEvents/delete
for more information.
"""
# [START analyticsadmin_properties_conversion_events_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 conversion event ID
# (e.g. "123456") before running the sample.
conversion_event_id = "YOUR-CONVERSION-EVENT-ID"

delete_conversion_event(property_id, conversion_event_id)


def delete_conversion_event(property_id, conversion_event_id):
"""Deletes the conversion event for the Google Analytics 4 property."""
client = AnalyticsAdminServiceClient()
client.delete_conversion_event(
name=f"properties/{property_id}/conversionEvents/{conversion_event_id}"
)
print("Conversion event deleted")


# [END analyticsadmin_properties_conversion_events_delete]


if __name__ == "__main__":
run_sample()
29 changes: 29 additions & 0 deletions samples/properties_conversion_events_delete_test.py
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 pytest

import properties_conversion_events_delete

FAKE_PROPERTY_ID = "1"
FAKE_CONVERSION_EVENT_ID = "1"


def test_properties_conversion_events_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_conversion_events_delete.delete_conversion_event(
FAKE_PROPERTY_ID, FAKE_CONVERSION_EVENT_ID
)
59 changes: 59 additions & 0 deletions samples/properties_conversion_events_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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 conversion
event details.

See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.conversionEvents/get
for more information.
"""
# [START analyticsadmin_properties_conversion_events_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 conversion event ID
# (e.g. "123456") before running the sample.
conversion_event_id = "YOUR-CONVERSION-EVENT-ID"

get_conversion_event(property_id, conversion_event_id)


def get_conversion_event(property_id, conversion_event_id):
"""Retrieves the details for the conversion event."""
client = AnalyticsAdminServiceClient()
conversion_event = client.get_conversion_event(
name=f"properties/{property_id}/conversionEvents/{conversion_event_id}"
)

print("Result:")
print(f"Resource name: {conversion_event.name}")
print(f"Event name: {conversion_event.event_name}")
print(f"Create time: {conversion_event.create_time}")
print(f"Deletable: {conversion_event.deletable}")
print(f"Custom: {conversion_event.custom}")


# [END analyticsadmin_properties_conversion_events_get]


if __name__ == "__main__":
run_sample()
28 changes: 28 additions & 0 deletions samples/properties_conversion_events_get_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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_conversion_events_get

TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID")
TEST_CONVERSION_EVENT_ID = os.getenv("GA_TEST_CONVERSION_EVENT_ID")


def test_properties_conversion_events_get(capsys):
properties_conversion_events_get.get_conversion_event(
TEST_PROPERTY_ID, TEST_CONVERSION_EVENT_ID
)
out, _ = capsys.readouterr()
assert "Result" in out
55 changes: 55 additions & 0 deletions samples/properties_conversion_events_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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 lists conversion events
for the Google Analytics 4 property.

See https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.conversionEvents/list
for more information.
"""
# [START analyticsadmin_properties_conversion_events_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"

list_conversion_events(property_id)


def list_conversion_events(property_id):
"""Lists conversion events for the Google Analytics 4 property."""
client = AnalyticsAdminServiceClient()
results = client.list_conversion_events(parent=f"properties/{property_id}")

print("Result:")
for conversion_event in results:
print(f"Resource name: {conversion_event.name}")
print(f"Event name: {conversion_event.event_name}")
print(f"Create time: {conversion_event.create_time}")
print(f"Deletable: {conversion_event.deletable}")
print(f"Custom: {conversion_event.custom}")
print()


# [END analyticsadmin_properties_conversion_events_list]


if __name__ == "__main__":
run_sample()
25 changes: 25 additions & 0 deletions samples/properties_conversion_events_list_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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_conversion_events_list

TEST_PROPERTY_ID = os.getenv("GA_TEST_PROPERTY_ID")


def test_properties_conversion_events_list(capsys):
properties_conversion_events_list.list_conversion_events(TEST_PROPERTY_ID)
out, _ = capsys.readouterr()
assert "Result" in out