Skip to content

Commit 32465e4

Browse files
committed
Filter out bad enums and add annotations to OCI example
Change-Id: I0f8a25f8bc62b3f9b9cc20a2683ab231f777cbbb
1 parent 78be456 commit 32465e4

File tree

6 files changed

+92
-39
lines changed

6 files changed

+92
-39
lines changed

examples/remarketing/add_customer_match_user_list.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,11 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
671671
"-d",
672672
"--ad_user_data_consent",
673673
type=str,
674-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
674+
choices=[
675+
e.name
676+
for e in googleads_client.enums.ConsentStatusEnum
677+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
678+
],
675679
help=(
676680
"The data consent status for ad user data for all members in "
677681
"the job."
@@ -681,7 +685,11 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
681685
"-p",
682686
"--ad_personalization_consent",
683687
type=str,
684-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
688+
choices=[
689+
e.name
690+
for e in googleads_client.enums.ConsentStatusEnum
691+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
692+
],
685693
help=(
686694
"The personalization consent status for ad user data for all "
687695
"members in the job."

examples/remarketing/upload_call_conversion.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ def main(
222222
"-d",
223223
"--ad_user_data_consent",
224224
type=str,
225-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
225+
choices=[
226+
e.name
227+
for e in googleads_client.enums.ConsentStatusEnum
228+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
229+
],
226230
help=(
227231
"The data consent status for ad user data for all members in "
228232
"the job."

examples/remarketing/upload_conversion_adjustment.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def main(
173173

174174

175175
if __name__ == "__main__":
176+
# GoogleAdsClient will read the google-ads.yaml configuration file in the
177+
# home directory if none is specified.
178+
googleads_client: GoogleAdsClient = GoogleAdsClient.load_from_storage(
179+
version="v20"
180+
)
181+
176182
parser: argparse.ArgumentParser = argparse.ArgumentParser(
177183
description="Uploads a conversion adjustment."
178184
)
@@ -198,9 +204,8 @@ def main(
198204
required=True,
199205
choices=[
200206
e.name
201-
for e in GoogleAdsClient.load_from_storage(
202-
version="v20"
203-
).enums.ConversionAdjustmentTypeEnum
207+
for e in googleads_client.enums.ConversionAdjustmentTypeEnum
208+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
204209
],
205210
help="The adjustment type, e.g. " "RETRACTION, RESTATEMENT",
206211
)
@@ -236,12 +241,6 @@ def main(
236241
)
237242
args: argparse.Namespace = parser.parse_args()
238243

239-
# GoogleAdsClient will read the google-ads.yaml configuration file in the
240-
# home directory if none is specified.
241-
googleads_client: GoogleAdsClient = GoogleAdsClient.load_from_storage(
242-
version="v20"
243-
)
244-
245244
try:
246245
main(
247246
googleads_client,

examples/remarketing/upload_enhanced_conversions_for_leads.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ def normalize_and_hash(s: str) -> str:
340340
"-n",
341341
"--ad_user_data_consent",
342342
type=str,
343-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
343+
choices=[
344+
e.name
345+
for e in googleads_client.enums.ConsentStatusEnum
346+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
347+
],
344348
help=(
345349
"The data consent status for ad user data for all members in "
346350
"the job."

examples/remarketing/upload_offline_conversion.py

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,40 @@
2222

2323
import argparse
2424
import sys
25+
from typing import Optional
2526

2627
from google.ads.googleads.client import GoogleAdsClient
2728
from google.ads.googleads.errors import GoogleAdsException
29+
from google.ads.googleads.v20.services.services.conversion_action_service import (
30+
ConversionActionServiceClient,
31+
)
32+
from google.ads.googleads.v20.services.services.conversion_upload_service import (
33+
ConversionUploadServiceClient,
34+
)
35+
from google.ads.googleads.v20.services.types.conversion_upload_service import (
36+
ClickConversion,
37+
ClickConversionResult,
38+
CustomVariable,
39+
UploadClickConversionsRequest,
40+
UploadClickConversionsResponse,
41+
)
2842

2943

3044
# [START upload_offline_conversion]
3145
def main(
32-
client,
33-
customer_id,
34-
conversion_action_id,
35-
gclid,
36-
conversion_date_time,
37-
conversion_value,
38-
conversion_custom_variable_id,
39-
conversion_custom_variable_value,
40-
gbraid,
41-
wbraid,
42-
order_id,
43-
ad_user_data_consent,
44-
):
46+
client: GoogleAdsClient,
47+
customer_id: str,
48+
conversion_action_id: str,
49+
gclid: Optional[str],
50+
conversion_date_time: str,
51+
conversion_value: str,
52+
conversion_custom_variable_id: Optional[str],
53+
conversion_custom_variable_value: Optional[str],
54+
gbraid: Optional[str],
55+
wbraid: Optional[str],
56+
order_id: Optional[str],
57+
ad_user_data_consent: Optional[str],
58+
) -> None:
4559
"""Creates a click conversion with a default currency of USD.
4660
4761
Args:
@@ -65,9 +79,13 @@ def main(
6579
order_id: The order ID for the click conversion.
6680
ad_user_data_consent: The ad user data consent for the click.
6781
"""
68-
click_conversion = client.get_type("ClickConversion")
69-
conversion_upload_service = client.get_service("ConversionUploadService")
70-
conversion_action_service = client.get_service("ConversionActionService")
82+
click_conversion: ClickConversion = client.get_type("ClickConversion")
83+
conversion_upload_service: ConversionUploadServiceClient = (
84+
client.get_service("ConversionUploadService")
85+
)
86+
conversion_action_service: ConversionActionServiceClient = (
87+
client.get_service("ConversionActionService")
88+
)
7189
click_conversion.conversion_action = (
7290
conversion_action_service.conversion_action_path(
7391
customer_id, conversion_action_id
@@ -87,7 +105,9 @@ def main(
87105
click_conversion.currency_code = "USD"
88106

89107
if conversion_custom_variable_id and conversion_custom_variable_value:
90-
conversion_custom_variable = client.get_type("CustomVariable")
108+
conversion_custom_variable: CustomVariable = client.get_type(
109+
"CustomVariable"
110+
)
91111
conversion_custom_variable.conversion_custom_variable = (
92112
conversion_upload_service.conversion_custom_variable_path(
93113
customer_id, conversion_custom_variable_id
@@ -114,16 +134,20 @@ def main(
114134
# multiple conversions to upload, it's most efficient to upload them in a
115135
# single request. See the following for per-request limits for reference:
116136
# https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload_service
117-
request = client.get_type("UploadClickConversionsRequest")
137+
request: UploadClickConversionsRequest = client.get_type(
138+
"UploadClickConversionsRequest"
139+
)
118140
request.customer_id = customer_id
119141
request.conversions.append(click_conversion)
120142
request.partial_failure = True
121-
conversion_upload_response = (
143+
conversion_upload_response: UploadClickConversionsResponse = (
122144
conversion_upload_service.upload_click_conversions(
123145
request=request,
124146
)
125147
)
126-
uploaded_click_conversion = conversion_upload_response.results[0]
148+
uploaded_click_conversion: ClickConversionResult = (
149+
conversion_upload_response.results[0]
150+
)
127151
print(
128152
f"Uploaded conversion that occurred at "
129153
f'"{uploaded_click_conversion.conversion_date_time}" from '
@@ -136,9 +160,11 @@ def main(
136160
if __name__ == "__main__":
137161
# GoogleAdsClient will read the google-ads.yaml configuration file in the
138162
# home directory if none is specified.
139-
googleads_client = GoogleAdsClient.load_from_storage(version="v20")
163+
googleads_client: GoogleAdsClient = GoogleAdsClient.load_from_storage(
164+
version="v20"
165+
)
140166

141-
parser = argparse.ArgumentParser(
167+
parser: argparse.ArgumentParser = argparse.ArgumentParser(
142168
description="Uploads an offline conversion."
143169
)
144170
# The following argument(s) should be provided to run the example.
@@ -224,10 +250,14 @@ def main(
224250
"-s",
225251
"--ad_user_data_consent",
226252
type=str,
227-
choices=[e.name for e in GoogleAdsClient.load_from_storage(version="v20").enums.ConsentStatusEnum],
253+
choices=[
254+
e.name
255+
for e in googleads_client.enums.ConsentStatusEnum
256+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
257+
],
228258
help=("The ad user data consent for the click."),
229259
)
230-
args = parser.parse_args()
260+
args: argparse.Namespace = parser.parse_args()
231261

232262
try:
233263
main(

examples/remarketing/upload_store_sales_transactions.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,11 @@ def check_job_status(
812812
parser.add_argument(
813813
"--ad_user_data_consent",
814814
type=str,
815-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
815+
choices=[
816+
e.name
817+
for e in googleads_client.enums.ConsentStatusEnum
818+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
819+
],
816820
help=(
817821
"The data consent status for ad user data for all members in "
818822
"the job."
@@ -821,7 +825,11 @@ def check_job_status(
821825
parser.add_argument(
822826
"--ad_personalization_consent",
823827
type=str,
824-
choices=[e.name for e in googleads_client.enums.ConsentStatusEnum],
828+
choices=[
829+
e.name
830+
for e in googleads_client.enums.ConsentStatusEnum
831+
if e.name not in ("UNSPECIFIED", "UNKNOWN")
832+
],
825833
help=(
826834
"The personalization consent status for ad user data for all "
827835
"members in the job."

0 commit comments

Comments
 (0)