Skip to content

Commit 7cda117

Browse files
Add missing region tags to examples (googleads#408)
1 parent e44a050 commit 7cda117

23 files changed

Lines changed: 160 additions & 103 deletions

examples/account_management/get_change_details.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
_DEFAULT_PAGE_SIZE = 1000
3131

3232

33+
# [START get_change_details]
3334
def main(client, customer_id):
3435
"""Gets specific details about the most recent changes in the given account.
3536
@@ -140,7 +141,7 @@ def main(client, customer_id):
140141
print(
141142
f"\t{changed_field} changed from {old_value} to {new_value}"
142143
)
143-
144+
# [END get_change_details]
144145

145146

146147
if __name__ == "__main__":

examples/account_management/reject_merchant_center_link.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def main(client, customer_id, merchant_center_account_id):
4545
"MerchantCenterLinkService"
4646
)
4747
# Get the extant customer account to Merchant Center account links.
48-
list_merchant_center_links_response = (
49-
merchant_center_link_service.list_merchant_center_links(
50-
customer_id=customer_id
51-
)
48+
list_merchant_center_links_response = merchant_center_link_service.list_merchant_center_links(
49+
customer_id=customer_id
5250
)
5351

5452
number_of_links = len(
@@ -98,6 +96,7 @@ def main(client, customer_id, merchant_center_account_id):
9896
)
9997

10098

99+
# [START reject_merchant_center_link]
101100
def _remove_merchant_center_link(
102101
client, merchant_center_link_service, customer_id, merchant_center_link
103102
):
@@ -124,6 +123,7 @@ def _remove_merchant_center_link(
124123
"Removed Merchant Center link with resource name "
125124
f"'{response.result.resource_name}'."
126125
)
126+
# [END reject_merchant_center_link]
127127

128128

129129
if __name__ == "__main__":

examples/advanced_operations/add_local_campaign.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def main(client, customer_id):
5555
)
5656

5757

58+
# [START add_local_campaign]
5859
def _create_campaign_budget(client, customer_id):
5960
"""Adds a campaign budget to the given client account.
6061
@@ -84,8 +85,10 @@ def _create_campaign_budget(client, customer_id):
8485
resource_name = response.results[0].resource_name
8586
print(f"Created campaign budget with resource name: '{resource_name}'")
8687
return resource_name
88+
# [END add_local_campaign]
8789

8890

91+
# [START add_local_campaign_1]
8992
def _create_campaign(client, customer_id, budget_resource_name):
9093
"""Adds a Local campaign to the given client account using the given budget.
9194
@@ -151,8 +154,10 @@ def _create_campaign(client, customer_id, budget_resource_name):
151154
resource_name = response.results[0].resource_name
152155
print(f"Created Local Campaign with resource name: '{resource_name}'")
153156
return resource_name
157+
# [END add_local_campaign_1]
154158

155159

160+
# [START add_local_campaign_2]
156161
def _create_ad_group(client, customer_id, campaign_resource_name):
157162
"""Adds an ad group to the given client account under the given campaign.
158163
@@ -181,8 +186,10 @@ def _create_ad_group(client, customer_id, campaign_resource_name):
181186
resource_name = response.results[0].resource_name
182187
print(f"Created AdGroup with resource name: '{resource_name}'")
183188
return resource_name
189+
# [END add_local_campaign_2]
184190

185191

192+
# [START add_local_campaign_3]
186193
def _create_local_ad(client, customer_id, ad_group_resource_name):
187194
"""Adds a local ad to the given client account under the given ad group.
188195
@@ -252,8 +259,10 @@ def _create_ad_text_asset(client, text):
252259
ad_text_asset = client.get_type("AdTextAsset")
253260
ad_text_asset.text = text
254261
return ad_text_asset
262+
# [END add_local_campaign_3]
255263

256264

265+
# [START add_local_campaign_4]
257266
def _create_image_asset(client, customer_id, image_url, image_name):
258267
"""Creates an asset with the given image URL and name.
259268
@@ -294,8 +303,10 @@ def _get_image_bytes(url):
294303
"""
295304
response = requests.get(url)
296305
return response.content
306+
# [END add_local_campaign_4]
297307

298308

309+
# [START add_local_campaign_5]
299310
def _create_youtube_video_asset(
300311
client, customer_id, youtube_video_id, youtube_video_name
301312
):
@@ -326,6 +337,7 @@ def _create_youtube_video_asset(
326337
f"'{resource_name}'"
327338
)
328339
return resource_name
340+
# [END add_local_campaign_5]
329341

330342

331343
if __name__ == "__main__":

examples/extensions/add_affiliate_location_extensions.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def main(client, customer_id, chain_id, campaign_id):
6565
)
6666

6767

68+
# [START add_affiliate_location_extensions]
6869
def _create_affiliate_location_extension_feed(client, customer_id, chain_id):
6970
"""Creates the Affiliate Location Extension feed.
7071
@@ -114,6 +115,7 @@ def _create_affiliate_location_extension_feed(client, customer_id, chain_id):
114115
f"{feed_resource_name}."
115116
)
116117
return feed_resource_name
118+
# [END add_affiliate_location_extensions]
117119

118120

119121
def _remove_location_extension_feeds(client, customer_id):
@@ -252,6 +254,7 @@ def _remove_customer_feeds(client, customer_id, customer_feeds):
252254
)
253255

254256

257+
# [START add_affiliate_location_extensions_1]
255258
def _get_affiliate_location_extension_feed_mapping(
256259
client, customer_id, feed_resource_name
257260
):
@@ -294,8 +297,10 @@ def _get_affiliate_location_extension_feed_mapping(
294297
return None
295298
else:
296299
return row.feed_mapping
300+
# [END add_affiliate_location_extensions_1]
297301

298302

303+
# [START add_affiliate_location_extensions_2]
299304
def _wait_for_feed_to_be_ready(client, customer_id, feed_resource_name):
300305
"""Waits for the Affliate location extension feed to be ready.
301306
@@ -340,8 +345,10 @@ def _wait_for_feed_to_be_ready(client, customer_id, feed_resource_name):
340345
f"Feed is not ready after "
341346
f"{MAX_FEEDMAPPING_RETRIEVAL_ATTEMPTS} retries."
342347
)
348+
# [END add_affiliate_location_extensions_2]
343349

344350

351+
# [START add_affiliate_location_extensions_3]
345352
def _create_campaign_feed(
346353
client, customer_id, campaign_id, feed_mapping, feed_resource_name, chain_id
347354
):
@@ -385,19 +392,19 @@ def _create_campaign_feed(
385392
"CampaignService"
386393
).campaign_path(customer_id, campaign_id)
387394

388-
mutate_campaign_feeds_response = (
389-
campaign_feed_service.mutate_campaign_feeds(
390-
customer_id=customer_id, operations=[campaign_feed_operation]
391-
)
395+
mutate_campaign_feeds_response = campaign_feed_service.mutate_campaign_feeds(
396+
customer_id=customer_id, operations=[campaign_feed_operation]
392397
)
393398

394399
# Display the result.
395400
print(
396401
"Campaign feed created with resource name: "
397402
f"{mutate_campaign_feeds_response.results[0].resource_name}."
398403
)
404+
# [END add_affiliate_location_extensions_3]
399405

400406

407+
# [START add_affiliate_location_extensions_4]
401408
def _get_attribute_id_for_chain_id(client, feed_mapping):
402409
"""Gets the feed attribute ID for the retail chain ID.
403410
@@ -423,6 +430,7 @@ def _get_attribute_id_for_chain_id(client, feed_mapping):
423430
"No AffiliateLocationField with a retail chain ID was "
424431
"found in the FeedMapping."
425432
)
433+
# [END add_affiliate_location_extensions_4]
426434

427435

428436
if __name__ == "__main__":
@@ -462,10 +470,7 @@ def _get_attribute_id_for_chain_id(client, feed_mapping):
462470

463471
try:
464472
main(
465-
googleads_client,
466-
args.customer_id,
467-
args.chain_id,
468-
args.campaign_id,
473+
googleads_client, args.customer_id, args.chain_id, args.campaign_id,
469474
)
470475
except GoogleAdsException as ex:
471476
print(

examples/extensions/add_google_my_business_location_extensions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def main(
6060
# will add them automatically because this will be a system generated feed.
6161
# See here for more details:
6262
# https://developers.google.com/google-ads/api/docs/location-extensions/google-ads-location-extensions
63+
# [START add_google_my_business_location_extensions]
6364
feed_operation = client.get_type("FeedOperation")
6465
gmb_feed = feed_operation.create
6566
gmb_feed.name = f"Google My Business Feed #{uuid4()}"
@@ -100,6 +101,7 @@ def main(
100101
# time.
101102
_delete_location_extension_feeds(client, customer_id)
102103

104+
# [START add_google_my_business_location_extensions_1]
103105
# Add the feed. Since it is a system generated feed, Google Ads will
104106
# automatically:
105107
# 1. Set up the FeedAttributes on the feed.
@@ -110,7 +112,10 @@ def main(
110112
)
111113
feed_resource_name = feed_response.results[0].resource_name
112114
print(f"GMB feed created with resource name '{feed_resource_name}'.")
115+
# [END add_google_my_business_location_extensions_1]
116+
# [END add_google_my_business_location_extensions]
113117

118+
# [START add_google_my_business_location_extensions_2]
114119
# After the completion of the Feed ADD operation above the added feed
115120
# will not be available for usage in a CustomerFeed until the sync
116121
# between the Google Ads and GMB accounts completes.
@@ -138,6 +143,7 @@ def main(
138143
customer_feed_resource_name = feed_mapping.resource_name
139144
print(f"GMB feed {feed_resource_name} is now ready.")
140145
break
146+
# [END add_google_my_business_location_extensions_2]
141147

142148
if customer_feed_resource_name is None:
143149
print(
@@ -147,6 +153,7 @@ def main(
147153
)
148154
sys.exit(1)
149155
else:
156+
# [START add_google_my_business_location_extensions_3]
150157
# Create a CustomerFeed operation and configure the CustomerFeed to
151158
# associate the feed with this customer for the LOCATION placeholder
152159
# type.
@@ -178,6 +185,7 @@ def main(
178185
"Customer feed created with resource name "
179186
f"'{customer_feed_response.results[0].resource_name}'."
180187
)
188+
# [END add_google_my_business_location_extensions_3]
181189

182190

183191
def _delete_location_extension_feeds(client, customer_id):

examples/extensions/remove_entire_sitelink_campaign_extension_setting.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from google.ads.googleads.errors import GoogleAdsException
3333

3434

35+
# [START remove_entire_sitelink_campaign_extension_setting]
3536
def main(client, customer_id, campaign_id):
3637
"""The main method that creates all necessary entities for the example.
3738
@@ -42,10 +43,8 @@ def main(client, customer_id, campaign_id):
4243
"""
4344
# Initialize an array of MutateOperations
4445
mutate_operations = []
45-
sitelink_campaign_extension_setting_mutate_operation = (
46-
_create_sitelink_campaign_extension_setting_mutate_operation(
47-
client, customer_id, campaign_id
48-
)
46+
sitelink_campaign_extension_setting_mutate_operation = _create_sitelink_campaign_extension_setting_mutate_operation(
47+
client, customer_id, campaign_id
4948
)
5049
mutate_operations.append(
5150
sitelink_campaign_extension_setting_mutate_operation
@@ -55,10 +54,8 @@ def main(client, customer_id, campaign_id):
5554
extension_feed_item_resource_names = _get_all_sitelink_extension_feed_items(
5655
client, ga_service, customer_id, campaign_id
5756
)
58-
extension_feed_item_mutate_operations = (
59-
_create_extension_feed_item_mutate_operations(
60-
client, extension_feed_item_resource_names
61-
)
57+
extension_feed_item_mutate_operations = _create_extension_feed_item_mutate_operations(
58+
client, extension_feed_item_resource_names
6259
)
6360
mutate_operations.extend(extension_feed_item_mutate_operations)
6461

@@ -84,6 +81,7 @@ def main(client, customer_id, campaign_id):
8481
"Removed an extension feed item with resource name "
8582
f'"{mutate_operation_response.extension_feed_item_result.resource_name}".'
8683
)
84+
# [END remove_entire_sitelink_campaign_extension_setting]
8785

8886

8987
def _create_sitelink_campaign_extension_setting_mutate_operation(
@@ -116,6 +114,7 @@ def _create_sitelink_campaign_extension_setting_mutate_operation(
116114
return mutate_operation
117115

118116

117+
# [START remove_entire_sitelink_campaign_extension_setting_1]
119118
def _get_all_sitelink_extension_feed_items(
120119
client, ga_service, customer_id, campaign_id
121120
):
@@ -168,6 +167,7 @@ def _get_all_sitelink_extension_feed_items(
168167
sys.exit(1)
169168

170169
return extension_feed_item_resource_names
170+
# [END remove_entire_sitelink_campaign_extension_setting_1]
171171

172172

173173
def _create_extension_feed_item_mutate_operations(
@@ -211,11 +211,7 @@ def _create_extension_feed_item_mutate_operations(
211211
help="The Google Ads customer ID",
212212
)
213213
parser.add_argument(
214-
"-i",
215-
"--campaign_id",
216-
type=str,
217-
required=True,
218-
help="The campaign ID",
214+
"-i", "--campaign_id", type=str, required=True, help="The campaign ID",
219215
)
220216
args = parser.parse_args()
221217

examples/extensions/update_sitelink.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from google.ads.googleads.errors import GoogleAdsException
2525

2626

27+
# [START update_sitelink]
2728
def main(client, customer_id, feed_item_id, sitelink_text):
2829
"""The main method that creates all necessary entities for the example.
2930
@@ -39,10 +40,8 @@ def main(client, customer_id, feed_item_id, sitelink_text):
3940
)
4041
extension_feed_item = extension_feed_item_operation.update
4142
# Update the extension feed item using the specified feed item ID
42-
extension_feed_item.resource_name = (
43-
extension_feed_item_service.extension_feed_item_path(
44-
customer_id, feed_item_id
45-
)
43+
extension_feed_item.resource_name = extension_feed_item_service.extension_feed_item_path(
44+
customer_id, feed_item_id
4645
)
4746
extension_feed_item.sitelink_feed_item.link_text = sitelink_text
4847

@@ -60,6 +59,7 @@ def main(client, customer_id, feed_item_id, sitelink_text):
6059
"Updated extension feed item with resource name: "
6160
f'"{response.results[0].resource_name}".'
6261
)
62+
# [END update_sitelink]
6363

6464

6565
if __name__ == "__main__":

0 commit comments

Comments
 (0)