51
51
_COUNTRY_CODE = "AR"
52
52
53
53
54
- def main (client , customer_id , omit_image_extensions , customizer_attribute_name = None ):
54
+ def main (
55
+ client , customer_id , omit_image_extensions , customizer_attribute_name = None
56
+ ):
55
57
"""
56
58
The main method that creates all necessary entities for the example.
57
59
@@ -75,7 +77,9 @@ def main(client, customer_id, omit_image_extensions, customizer_attribute_name=N
75
77
# Create a budget, which can be shared by multiple campaigns.
76
78
campaign_budget = create_campaign_budget (client , customer_id )
77
79
78
- campaign_resource_name = create_campaign (client , customer_id , campaign_budget )
80
+ campaign_resource_name = create_campaign (
81
+ client , customer_id , campaign_budget
82
+ )
79
83
80
84
ad_group_resource_name = create_ad_group (
81
85
client , customer_id , campaign_resource_name
@@ -122,7 +126,9 @@ def create_customizer_attribute(client, customer_id, customizer_attribute_name):
122
126
123
127
# Issue a mutate request to add the customizer attribute and prints its
124
128
# information.
125
- customizer_attribute_service = client .get_service ("CustomizerAttributeService" )
129
+ customizer_attribute_service = client .get_service (
130
+ "CustomizerAttributeService"
131
+ )
126
132
response = customizer_attribute_service .mutate_customizer_attributes (
127
133
customer_id = customer_id , operations = [operation ]
128
134
)
@@ -153,13 +159,19 @@ def link_customizer_attribute_to_customer(
153
159
# Create a customer customizer with the value to be used in the responsive
154
160
# search ad.
155
161
customer_customizer = operation .create
156
- customer_customizer .customizer_attribute = customizer_attribute_resource_name
157
- customer_customizer .value .type_ = client .enums .CustomizerAttributeTypeEnum .PRICE
162
+ customer_customizer .customizer_attribute = (
163
+ customizer_attribute_resource_name
164
+ )
165
+ customer_customizer .value .type_ = (
166
+ client .enums .CustomizerAttributeTypeEnum .PRICE
167
+ )
158
168
# The ad customizer will dynamically replace the placeholder with this value
159
169
# when the ad serves.
160
170
customer_customizer .value .string_value = "100USD"
161
171
162
- customer_customizer_service = client .get_service ("CustomerCustomizerService" )
172
+ customer_customizer_service = client .get_service (
173
+ "CustomerCustomizerService"
174
+ )
163
175
# Issue a mutate request to create the customer customizer and prints its
164
176
# information.
165
177
response = customer_customizer_service .mutate_customer_customizers (
@@ -192,7 +204,9 @@ def create_ad_text_asset(client, text, pinned_field=None):
192
204
return ad_text_asset
193
205
194
206
195
- def create_ad_text_asset_with_customizer (client , customizer_attribute_resource_name ):
207
+ def create_ad_text_asset_with_customizer (
208
+ client , customizer_attribute_resource_name
209
+ ):
196
210
"""Create an AdTextAsset.
197
211
Args:
198
212
client: an initialized GoogleAdsClient instance.
@@ -230,7 +244,9 @@ def create_campaign_budget(client, customer_id):
230
244
campaign_budget_operation = client .get_type ("CampaignBudgetOperation" )
231
245
campaign_budget = campaign_budget_operation .create
232
246
campaign_budget .name = f"Campaign budget { uuid .uuid4 ()} "
233
- campaign_budget .delivery_method = client .enums .BudgetDeliveryMethodEnum .STANDARD
247
+ campaign_budget .delivery_method = (
248
+ client .enums .BudgetDeliveryMethodEnum .STANDARD
249
+ )
234
250
campaign_budget .amount_micros = 500000
235
251
236
252
# Add budget.
@@ -256,7 +272,9 @@ def create_campaign(client, customer_id, campaign_budget):
256
272
campaign_operation = client .get_type ("CampaignOperation" )
257
273
campaign = campaign_operation .create
258
274
campaign .name = f"Testing RSA via API { uuid .uuid4 ()} "
259
- campaign .advertising_channel_type = client .enums .AdvertisingChannelTypeEnum .SEARCH
275
+ campaign .advertising_channel_type = (
276
+ client .enums .AdvertisingChannelTypeEnum .SEARCH
277
+ )
260
278
261
279
# Recommendation: Set the campaign to PAUSED when creating it to prevent
262
280
# the ads from immediately serving. Set to ENABLED once you've added
@@ -433,7 +451,9 @@ def add_keywords(client, customer_id, ad_group_resource_name):
433
451
ad_group_criterion .ad_group = ad_group_resource_name
434
452
ad_group_criterion .status = client .enums .AdGroupCriterionStatusEnum .ENABLED
435
453
ad_group_criterion .keyword .text = _KEYWORD_TEXT_EXACT_1
436
- ad_group_criterion .keyword .match_type = client .enums .KeywordMatchTypeEnum .EXACT
454
+ ad_group_criterion .keyword .match_type = (
455
+ client .enums .KeywordMatchTypeEnum .EXACT
456
+ )
437
457
438
458
# Uncomment the below line if you want to change this keyword to a negative target.
439
459
# ad_group_criterion.negative = True
@@ -450,7 +470,9 @@ def add_keywords(client, customer_id, ad_group_resource_name):
450
470
ad_group_criterion .ad_group = ad_group_resource_name
451
471
ad_group_criterion .status = client .enums .AdGroupCriterionStatusEnum .ENABLED
452
472
ad_group_criterion .keyword .text = _KEYWORD_TEXT_PHRASE_1
453
- ad_group_criterion .keyword .match_type = client .enums .KeywordMatchTypeEnum .PHRASE
473
+ ad_group_criterion .keyword .match_type = (
474
+ client .enums .KeywordMatchTypeEnum .PHRASE
475
+ )
454
476
455
477
# Uncomment the below line if you want to change this keyword to a negative target.
456
478
# ad_group_criterion.negative = True
@@ -467,7 +489,9 @@ def add_keywords(client, customer_id, ad_group_resource_name):
467
489
ad_group_criterion .ad_group = ad_group_resource_name
468
490
ad_group_criterion .status = client .enums .AdGroupCriterionStatusEnum .ENABLED
469
491
ad_group_criterion .keyword .text = _KEYWORD_TEXT_BROAD_1
470
- ad_group_criterion .keyword .match_type = client .enums .KeywordMatchTypeEnum .BROAD
492
+ ad_group_criterion .keyword .match_type = (
493
+ client .enums .KeywordMatchTypeEnum .BROAD
494
+ )
471
495
472
496
# Uncomment the below line if you want to change this keyword to a negative target.
473
497
# ad_group_criterion.negative = True
@@ -482,9 +506,11 @@ def add_keywords(client, customer_id, ad_group_resource_name):
482
506
campaign_criterion_operations = operations
483
507
484
508
# Add keywords
485
- ad_group_criterion_response = ad_group_criterion_service .mutate_ad_group_criteria (
486
- customer_id = customer_id ,
487
- operations = [* campaign_criterion_operations ],
509
+ ad_group_criterion_response = (
510
+ ad_group_criterion_service .mutate_ad_group_criteria (
511
+ customer_id = customer_id ,
512
+ operations = [* campaign_criterion_operations ],
513
+ )
488
514
)
489
515
for result in ad_group_criterion_response .results :
490
516
print ("Created keyword " f"{ result .resource_name } ." )
@@ -515,7 +541,9 @@ def add_geo_targeting(client, customer_id, campaign_resource_name):
515
541
[_GEO_LOCATION_1 , _GEO_LOCATION_2 , _GEO_LOCATION_3 ]
516
542
)
517
543
518
- results = geo_target_constant_service .suggest_geo_target_constants (gtc_request )
544
+ results = geo_target_constant_service .suggest_geo_target_constants (
545
+ gtc_request
546
+ )
519
547
520
548
operations = []
521
549
for suggestion in results .geo_target_constant_suggestions :
@@ -526,7 +554,9 @@ def add_geo_targeting(client, customer_id, campaign_resource_name):
526
554
f"from search term ({ suggestion .search_term } )."
527
555
)
528
556
# Create the campaign criterion for location targeting.
529
- campaign_criterion_operation = client .get_type ("CampaignCriterionOperation" )
557
+ campaign_criterion_operation = client .get_type (
558
+ "CampaignCriterionOperation"
559
+ )
530
560
campaign_criterion = campaign_criterion_operation .create
531
561
campaign_criterion .campaign = campaign_resource_name
532
562
campaign_criterion .location .geo_target_constant = (
@@ -535,8 +565,10 @@ def add_geo_targeting(client, customer_id, campaign_resource_name):
535
565
operations .append (campaign_criterion_operation )
536
566
537
567
campaign_criterion_service = client .get_service ("CampaignCriterionService" )
538
- campaign_criterion_response = campaign_criterion_service .mutate_campaign_criteria (
539
- customer_id = customer_id , operations = [* operations ]
568
+ campaign_criterion_response = (
569
+ campaign_criterion_service .mutate_campaign_criteria (
570
+ customer_id = customer_id , operations = [* operations ]
571
+ )
540
572
)
541
573
542
574
for result in campaign_criterion_response .results :
@@ -583,16 +615,23 @@ def add_images(client, customer_id, campaign_resource_name):
583
615
584
616
# Step 6.2 - Create Image Extension
585
617
extension_feed_item_service = client .get_service ("ExtensionFeedItemService" )
586
- extension_feed_item_operation = client .get_type ("ExtensionFeedItemOperation" )
618
+ extension_feed_item_operation = client .get_type (
619
+ "ExtensionFeedItemOperation"
620
+ )
587
621
extension_feed_item = extension_feed_item_operation .create
588
622
extension_feed_item .image_feed_item .image_asset = image_asset_resource_name
589
623
590
- extension_feed_response = extension_feed_item_service .mutate_extension_feed_items (
591
- customer_id = customer_id , operations = [extension_feed_item_operation ]
624
+ extension_feed_response = (
625
+ extension_feed_item_service .mutate_extension_feed_items (
626
+ customer_id = customer_id , operations = [extension_feed_item_operation ]
627
+ )
592
628
)
593
629
image_resource_name = extension_feed_response .results [0 ].resource_name
594
630
595
- print ("Created an image extension with resource name: " f"'{ image_resource_name } '" )
631
+ print (
632
+ "Created an image extension with resource name: "
633
+ f"'{ image_resource_name } '"
634
+ )
596
635
597
636
# Step 6.3 - Link Image Extension to RSA
598
637
campaign_extension_setting_service = client .get_service (
@@ -622,7 +661,7 @@ def add_images(client, customer_id, campaign_resource_name):
622
661
if __name__ == "__main__" :
623
662
# GoogleAdsClient will read the google-ads.yaml configuration file in the
624
663
# home directory if none is specified.
625
- googleads_client = GoogleAdsClient .load_from_storage (version = "v15 " )
664
+ googleads_client = GoogleAdsClient .load_from_storage (version = "v16 " )
626
665
627
666
parser = argparse .ArgumentParser (
628
667
description = ("Creates a Responsive Search Ad for specified customer." )
0 commit comments