1616
1717
1818import argparse
19+ from typing import Optional , Sequence
1920import sys
2021
2122from google .ads .googleads .client import GoogleAdsClient
2223from google .ads .googleads .errors import GoogleAdsException
24+ from google .ads .googleads .v20 .services .types .asset_service import AssetOperation
25+ from google .ads .googleads .v20 .resources .types .asset import Asset
26+ from google .ads .googleads .v20 .common .types .criteria import AdScheduleInfo
27+ from google .ads .googleads .v20 .enums .types .day_of_week import DayOfWeekEnum
28+ from google .ads .googleads .v20 .enums .types .minute_of_hour import MinuteOfHourEnum
29+ from google .ads .googleads .v20 .enums .types .call_conversion_reporting_state import CallConversionReportingStateEnum
30+ from google .ads .googleads .v20 .services .types .customer_asset_service import CustomerAssetOperation
31+ from google .ads .googleads .v20 .resources .types .customer_asset import CustomerAsset
32+ from google .ads .googleads .v20 .enums .types .asset_field_type import AssetFieldTypeEnum
2333
2434# Country code is a two-letter ISO-3166 code, for a list of all codes see:
2535# https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-17
26- _DEFAULT_PHONE_COUNTRY = "US"
36+ _DEFAULT_PHONE_COUNTRY : str = "US"
2737
2838
2939def main (
30- client , customer_id , phone_number , phone_country , conversion_action_id
31- ):
40+ client : GoogleAdsClient ,
41+ customer_id : str ,
42+ phone_number : str ,
43+ phone_country : str ,
44+ conversion_action_id : Optional [str ],
45+ ) -> None :
3246 """The main method that creates all necessary entities for the example.
3347
3448 Args:
@@ -38,15 +52,19 @@ def main(
3852 phone_country: a two-letter ISO-3166 code.
3953 conversion_action_id: an ID for a conversion action.
4054 """
41- asset_resource_name = add_call_asset (
55+ asset_resource_name : str = add_call_asset (
4256 client , customer_id , phone_number , phone_country , conversion_action_id
4357 )
4458 link_asset_to_account (client , customer_id , asset_resource_name )
4559
4660
4761def add_call_asset (
48- client , customer_id , phone_number , phone_country , conversion_action_id
49- ):
62+ client : GoogleAdsClient ,
63+ customer_id : str ,
64+ phone_number : str ,
65+ phone_country : str ,
66+ conversion_action_id : Optional [str ],
67+ ) -> str :
5068 """Creates a new asset for the call.
5169
5270 Args:
@@ -59,13 +77,13 @@ def add_call_asset(
5977 Returns:
6078 a resource name for a new call asset.
6179 """
62- operation = client .get_type ("AssetOperation" )
80+ operation : AssetOperation = client .get_type ("AssetOperation" )
6381 # Creates the call asset.
64- asset = operation .create .call_asset
82+ asset : Asset = operation .create .call_asset
6583 asset .country_code = phone_country
6684 asset .phone_number = phone_number
6785 # Optional: Specifies day and time intervals for which the asset may serve.
68- ad_schedule = client .get_type ("AdScheduleInfo" )
86+ ad_schedule : AdScheduleInfo = client .get_type ("AdScheduleInfo" )
6987 # Sets the day of this schedule as Monday.
7088 ad_schedule .day_of_week = client .enums .DayOfWeekEnum .MONDAY
7189 # Sets the start hour to 9am.
@@ -93,35 +111,39 @@ def add_call_asset(
93111 response = asset_service .mutate_assets (
94112 customer_id = customer_id , operations = [operation ]
95113 )
96- resource_name = response .results [0 ].resource_name
114+ resource_name : str = response .results [0 ].resource_name
97115 print (f"Created a call asset with resource name: '{ resource_name } '" )
98116
99117 return resource_name
100118
101119
102- def link_asset_to_account (client , customer_id , asset_resource_name ):
120+ def link_asset_to_account (
121+ client : GoogleAdsClient , customer_id : str , asset_resource_name : str
122+ ) -> None :
103123 """Links the call asset at the account level to serve in eligible campaigns.
104124
105125 Args:
106126 client: an initialized GoogleAdsClient instance.
107127 customer_id: a client customer ID.
108128 asset_resource_name: a resource name for the call asset.
109129 """
110- operation = client .get_type ("CustomerAssetOperation" )
111- customer_asset = operation .create
130+ operation : CustomerAssetOperation = client .get_type (
131+ "CustomerAssetOperation"
132+ )
133+ customer_asset : CustomerAsset = operation .create
112134 customer_asset .asset = asset_resource_name
113135 customer_asset .field_type = client .enums .AssetFieldTypeEnum .CALL
114136
115137 customer_asset_service = client .get_service ("CustomerAssetService" )
116138 response = customer_asset_service .mutate_customer_assets (
117139 customer_id = customer_id , operations = [operation ]
118140 )
119- resource_name = response .results [0 ].resource_name
141+ resource_name : str = response .results [0 ].resource_name
120142 print (f"Created a customer asset with resource name: '{ resource_name } '" )
121143
122144
123145if __name__ == "__main__" :
124- parser = argparse .ArgumentParser (
146+ parser : argparse . ArgumentParser = argparse .ArgumentParser (
125147 description = ("Adds a call asset to a specific account." )
126148 )
127149 # The following argument(s) should be provided to run the example.
@@ -157,11 +179,13 @@ def link_asset_to_account(client, customer_id, asset_resource_name):
157179 help = ("An optional conversion action ID to attribute conversions to." ),
158180 )
159181
160- args = parser .parse_args ()
182+ args : argparse . Namespace = parser .parse_args ()
161183
162184 # GoogleAdsClient will read the google-ads.yaml configuration file in the
163185 # home directory if none is specified.
164- googleads_client = GoogleAdsClient .load_from_storage (version = "v19" )
186+ googleads_client : GoogleAdsClient = GoogleAdsClient .load_from_storage (
187+ version = "v20"
188+ )
165189
166190 try :
167191 main (
0 commit comments