Skip to content

Commit c4c9788

Browse files
PierrickVouletpierrick
andauthored
Add manual region tags (googleads#350)
* Add manual region tags * Add region tags * Refine code snippet content Co-authored-by: pierrick <[email protected]>
1 parent d342b72 commit c4c9788

10 files changed

Lines changed: 28 additions & 0 deletions

examples/advanced_operations/add_dynamic_page_feed.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def map_feed_urls(url):
267267
)
268268

269269

270+
# [START add_dynamic_page_feed]
270271
def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
271272
"""Updates the given campaign with the given feed details.
272273
@@ -293,6 +294,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
293294
campaign = None
294295
for row in results:
295296
campaign = row.campaign
297+
# [END add_dynamic_page_feed]
296298

297299
if not campaign:
298300
raise ValueError("Campaign with id #{} not found".format(campaign_id))
@@ -304,6 +306,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
304306
)
305307
)
306308

309+
# [START add_dynamic_page_feed_1]
307310
# Retrieve a new campaign operation
308311
campaign_operation = client.get_type("CampaignOperation", version="v6")
309312
# Copy the retrieved campaign onto the new campaign operation.
@@ -338,8 +341,10 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
338341

339342
# Display the results.
340343
print("Updated campaign #{}".format(resource_name))
344+
# [END add_dynamic_page_feed_1]
341345

342346

347+
# [START add_dynamic_page_feed_2]
343348
def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
344349
"""Adds Dynamic Search Ad targeting criteria to the given ad group.
345350
@@ -381,6 +386,7 @@ def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
381386
resource_name
382387
)
383388
)
389+
# [END add_dynamic_page_feed_2]
384390

385391

386392
if __name__ == "__main__":

examples/advanced_operations/add_dynamic_search_ads.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def create_budget(client, customer_id):
9494
return resource_name
9595

9696

97+
# [START add_dynamic_search_ads]
9798
def create_campaign(client, customer_id, budget_resource_name):
9899
"""Creates a Dynamic Search Ad Campaign under the given customer ID.
99100
@@ -139,10 +140,12 @@ def create_campaign(client, customer_id, budget_resource_name):
139140
resource_name = response.results[0].resource_name
140141

141142
print(f'Created campaign with resource_name: "{resource_name}"')
143+
# [END add_dynamic_search_ads]
142144

143145
return resource_name
144146

145147

148+
# [START add_dynamic_search_ads_1]
146149
def create_ad_group(client, customer_id, campaign_resource_name):
147150
"""Creates a Dynamic Search Ad Group under the given Campaign.
148151
@@ -183,10 +186,12 @@ def create_ad_group(client, customer_id, campaign_resource_name):
183186
resource_name = response.results[0].resource_name
184187

185188
print(f'Created Ad Group with resource_name: "{resource_name}"')
189+
# [END add_dynamic_search_ads_1]
186190

187191
return resource_name
188192

189193

194+
# [START add_dynamic_search_ads_2]
190195
def create_expanded_dsa(client, customer_id, ad_group_resource_name):
191196
"""Creates a dynamic search ad under the given ad group.
192197
@@ -219,6 +224,7 @@ def create_expanded_dsa(client, customer_id, ad_group_resource_name):
219224
resource_name = response.results[0].resource_name
220225

221226
print(f'Created Ad Group Ad with resource_name: "{resource_name}"')
227+
# [END add_dynamic_search_ads_2]
222228

223229

224230
def add_webpage_criterion(client, customer_id, ad_group_resource_name):

examples/basic_operations/add_expanded_text_ads.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import google.ads.google_ads.client
2626

2727

28+
# [START add_expanded_text_ads]
2829
def main(client, customer_id, ad_group_id, number_of_ads):
2930
ad_group_ad_service = client.get_service("AdGroupAdService", version="v6")
3031
ad_group_service = client.get_service("AdGroupService", version="v6")
@@ -79,6 +80,7 @@ def main(client, customer_id, ad_group_id, number_of_ads):
7980

8081
for result in ad_group_ad_response.results:
8182
print("Created ad group ad {}.".format(result.resource_name))
83+
# [END add_expanded_text_ads]
8284

8385

8486
if __name__ == "__main__":

examples/basic_operations/update_expanded_text_ad.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from google.api_core import protobuf_helpers
2828

2929

30+
# [START update_expanded_text_ad]
3031
def main(client, customer_id, ad_id):
3132
ad_service = client.get_service("AdService", version="v6")
3233

@@ -65,6 +66,7 @@ def main(client, customer_id, ad_id):
6566
f'Ad with resource name "{ad_response.results[0].resource_name}" '
6667
"was updated."
6768
)
69+
# [END update_expanded_text_ad]
6870

6971

7072
if __name__ == "__main__":

examples/misc/upload_image_asset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.ads.google_ads.errors import GoogleAdsException
2626

2727

28+
# [START upload_image_asset]
2829
def main(client, customer_id):
2930
"""Main method, to run this code example as a standalone application."""
3031

@@ -69,6 +70,7 @@ def main(client, customer_id):
6970
for field_path_element in error.location.field_path_elements:
7071
print(f"\t\tOn field: {field_path_element.field_name}")
7172
sys.exit(1)
73+
# [END upload_image_asset]
7274

7375

7476
if __name__ == "__main__":

examples/planning/add_keyword_plan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from google.ads.google_ads.errors import GoogleAdsException
2828

2929

30+
# [START add_keyword_plan]
3031
def main(client, customer_id):
3132
"""Adds a keyword plan, campaign, ad group, etc. to the customer account
3233
@@ -300,6 +301,7 @@ def create_keyword_plan_negative_campaign_keywords(
300301
"Created keyword plan campaign keyword with resource name: "
301302
f"{response.results[0].resource_name}"
302303
)
304+
# [END add_keyword_plan]
303305

304306

305307
if __name__ == "__main__":

examples/planning/generate_forecast_metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.ads.google_ads.errors import GoogleAdsException
2626

2727

28+
# [START generate_forecast_metrics]
2829
def main(client, customer_id, keyword_plan_id):
2930
keyword_plan_service = client.get_service("KeywordPlanService")
3031
resource_name = keyword_plan_service.keyword_plan_path(
@@ -67,6 +68,7 @@ def main(client, customer_id, keyword_plan_id):
6768
cpc_val = metrics.average_cpc
6869
cpc = "{:.2f}".format(cpc_val) if cpc_val else "unspecified"
6970
print("Estimated average cpc: {}\n".format(cpc))
71+
# [END generate_forecast_metrics]
7072

7173

7274
if __name__ == "__main__":

examples/planning/generate_keyword_ideas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
_DEFAULT_LANGUAGE_ID = "1000" # language ID for English
3131

3232

33+
# [START generate_keyword_ideas]
3334
def main(
3435
client, customer_id, location_ids, language_id, keyword_texts, page_url
3536
):
@@ -120,6 +121,7 @@ def main(
120121
for field_path_element in error.location.field_path_elements:
121122
print(f"\t\tOn field: {field_path_element.field_name}")
122123
sys.exit(1)
124+
# [END generate_keyword_ideas]
123125

124126

125127
if __name__ == "__main__":

examples/remarketing/add_customer_match_user_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def _create_customer_match_user_list(client, customer_id):
105105
return user_list_resource_name
106106

107107

108+
# [START add_customer_match_user_list]
108109
def _add_users_to_customer_match_user_list(
109110
client, customer_id, user_list_resource_name
110111
):
@@ -296,6 +297,7 @@ def _normalize_and_hash(s):
296297
A normalized (lowercase, remove whitespace) and SHA-256 hashed string.
297298
"""
298299
return hashlib.sha256(s.strip().lower().encode()).hexdigest()
300+
# [END add_customer_match_user_list]
299301

300302

301303
if __name__ == "__main__":

examples/remarketing/add_merchant_center_dynamic_remarketing_campaign.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.ads.google_ads.errors import GoogleAdsException
2929

3030

31+
# [START add_merchant_center_dynamic_remarketing_campaign]
3132
def main(
3233
client,
3334
customer_id,
@@ -304,6 +305,7 @@ def _attach_user_list(
304305
"Created ad group criterion with resource name "
305306
f"'{ad_group_criterion_response.results[0].resource_name}'."
306307
)
308+
# [END add_merchant_center_dynamic_remarketing_campaign]
307309

308310

309311
if __name__ == "__main__":

0 commit comments

Comments
 (0)