@@ -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