Skip to content

Commit 796d0cd

Browse files
Update get_ad_group_bid_modifiers example and add examples for conversion custom variables (googleads#458)
1 parent 55a70c2 commit 796d0cd

3 files changed

Lines changed: 83 additions & 9 deletions

File tree

examples/advanced_operations/get_ad_group_bid_modifiers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def main(client, customer_id, page_size, ad_group_id=None):
4747
if ad_group_id:
4848
query += f" WHERE ad_group.id = {ad_group_id}"
4949

50+
# Limit results to 10,000 rows as the number of bid modifiers can be large.
51+
query += " LIMIT 10000"
52+
5053
search_request = client.get_type("SearchGoogleAdsRequest")
5154
search_request.customer_id = customer_id
5255
search_request.query = query

examples/remarketing/upload_call_conversion.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def main(
3434
call_start_date_time,
3535
conversion_date_time,
3636
conversion_value,
37+
conversion_custom_variable_id,
38+
conversion_custom_variable_value,
3739
):
3840
"""Imports offline call conversion values for calls related to your ads.
3941
@@ -51,6 +53,10 @@ def main(
5153
after the click time). The format is 'yyyy-mm-dd hh:mm:ss+|-hh:mm',
5254
e.g. '2021-01-01 12:32:45-08:00'.
5355
conversion_value: The conversion value in the desired currency.
56+
conversion_custom_variable_id: The ID of the conversion custom
57+
variable to associate with the upload.
58+
conversion_custom_variable_value: The str value of the conversion custom
59+
variable to associate with the upload.
5460
"""
5561
# Get the ConversionUploadService client.
5662
conversion_upload_service = client.get_service("ConversionUploadService")
@@ -66,13 +72,21 @@ def main(
6672
call_conversion.conversion_value = conversion_value
6773
call_conversion.currency_code = "USD"
6874

75+
if conversion_custom_variable_id and conversion_custom_variable_value:
76+
conversion_custom_variable = client.get_type("CustomVariable")
77+
conversion_custom_variable.conversion_custom_variable = (
78+
conversion_custom_variable_id
79+
)
80+
conversion_custom_variable.value = conversion_custom_variable_value
81+
call_conversion.custom_variables.append(conversion_custom_variable)
82+
6983
# Issue a request to upload the call conversion.
7084
request = client.get_type("UploadCallConversionsRequest")
7185
request.customer_id = customer_id
7286
request.conversions = [call_conversion]
7387
request.partial_failure = True
74-
upload_call_conversions_response = conversion_upload_service.upload_call_conversions(
75-
request=request
88+
upload_call_conversions_response = (
89+
conversion_upload_service.upload_call_conversions(request=request)
7690
)
7791

7892
# Print any partial errors returned.
@@ -141,7 +155,7 @@ def main(
141155
"--conversion_date_time",
142156
type=str,
143157
required=True,
144-
help="The the date and time of the conversion (should be after the "
158+
help="The date and time of the conversion (should be after the "
145159
"click time). The format is 'yyyy-mm-dd hh:mm:ss+|-hh:mm', e.g. "
146160
"'2019-01-01 12:32:45-08:00'.",
147161
)
@@ -152,6 +166,18 @@ def main(
152166
required=True,
153167
help="The conversion value in the desired currency.",
154168
)
169+
parser.add_argument(
170+
"-w",
171+
"--conversion_custom_variable_id",
172+
type=str,
173+
help="The ID of the conversion custom variable to associate with the upload.",
174+
)
175+
parser.add_argument(
176+
"-x",
177+
"--conversion_custom_variable_value",
178+
type=str,
179+
help="The value of the conversion custom variable to associate with the upload.",
180+
)
155181
args = parser.parse_args()
156182

157183
try:
@@ -163,6 +189,8 @@ def main(
163189
args.call_start_date_time,
164190
args.conversion_date_time,
165191
args.conversion_value,
192+
args.conversion_custom_variable_id,
193+
args.conversion_custom_variable_value,
166194
)
167195
except GoogleAdsException as ex:
168196
print(

examples/remarketing/upload_offline_conversion.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,54 @@ def main(
3535
gclid,
3636
conversion_date_time,
3737
conversion_value,
38+
conversion_custom_variable_id,
39+
conversion_custom_variable_value,
3840
):
39-
"""Creates a click conversion with a default currency of USD."""
41+
"""Creates a click conversion with a default currency of USD.
42+
43+
Args:
44+
client: An initialized GoogleAdsClient instance.
45+
customer_id: The client customer ID string.
46+
conversion_action_id: The ID of the conversion action to upload to.
47+
gclid: The Google Click Identifier ID.
48+
conversion_date_time: The the date and time of the conversion (should be
49+
after the click time). The format is 'yyyy-mm-dd hh:mm:ss+|-hh:mm',
50+
e.g. '2021-01-01 12:32:45-08:00'.
51+
conversion_value: The conversion value in the desired currency.
52+
conversion_custom_variable_id: The ID of the conversion custom
53+
variable to associate with the upload.
54+
conversion_custom_variable_value: The str value of the conversion custom
55+
variable to associate with the upload.
56+
"""
4057
click_conversion = client.get_type("ClickConversion")
4158
conversion_action_service = client.get_service("ConversionActionService")
42-
click_conversion.conversion_action = conversion_action_service.conversion_action_path(
43-
customer_id, conversion_action_id
59+
click_conversion.conversion_action = (
60+
conversion_action_service.conversion_action_path(
61+
customer_id, conversion_action_id
62+
)
4463
)
4564
click_conversion.gclid = gclid
4665
click_conversion.conversion_value = float(conversion_value)
4766
click_conversion.conversion_date_time = conversion_date_time
4867
click_conversion.currency_code = "USD"
4968

69+
if conversion_custom_variable_id and conversion_custom_variable_value:
70+
conversion_custom_variable = client.get_type("CustomVariable")
71+
conversion_custom_variable.conversion_custom_variable = (
72+
conversion_custom_variable_id
73+
)
74+
conversion_custom_variable.value = conversion_custom_variable_value
75+
click_conversion.custom_variables.append(conversion_custom_variable)
76+
5077
conversion_upload_service = client.get_service("ConversionUploadService")
5178
request = client.get_type("UploadClickConversionsRequest")
5279
request.customer_id = customer_id
5380
request.conversions = [click_conversion]
5481
request.partial_failure = True
55-
conversion_upload_response = conversion_upload_service.upload_click_conversions(
56-
request=request,
82+
conversion_upload_response = (
83+
conversion_upload_service.upload_click_conversions(
84+
request=request,
85+
)
5786
)
5887
uploaded_click_conversion = conversion_upload_response.results[0]
5988
print(
@@ -103,7 +132,7 @@ def main(
103132
"--conversion_date_time",
104133
type=str,
105134
required=True,
106-
help="The the date and time of the "
135+
help="The date and time of the "
107136
"conversion (should be after the click time). The "
108137
'format is "yyyy-mm-dd hh:mm:ss+|-hh:mm", e.g. '
109138
"“2019-01-01 12:32:45-08:00”",
@@ -115,6 +144,18 @@ def main(
115144
required=True,
116145
help="The conversion value.",
117146
)
147+
parser.add_argument(
148+
"-w",
149+
"--conversion_custom_variable_id",
150+
type=str,
151+
help="The ID of the conversion custom variable to associate with the upload.",
152+
)
153+
parser.add_argument(
154+
"-x",
155+
"--conversion_custom_variable_value",
156+
type=str,
157+
help="The value of the conversion custom variable to associate with the upload.",
158+
)
118159
args = parser.parse_args()
119160

120161
try:
@@ -125,6 +166,8 @@ def main(
125166
args.gclid,
126167
args.conversion_date_time,
127168
args.conversion_value,
169+
args.conversion_custom_variable_id,
170+
args.conversion_custom_variable_value,
128171
)
129172
except GoogleAdsException as ex:
130173
print(

0 commit comments

Comments
 (0)