Skip to content

Commit

Permalink
Add manual region tags (#350)
Browse files Browse the repository at this point in the history
* Add manual region tags

* Add region tags

* Refine code snippet content

Co-authored-by: pierrick <[email protected]>
  • Loading branch information
PierrickVoulet and pierrick committed Dec 7, 2020
1 parent d342b72 commit c4c9788
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/advanced_operations/add_dynamic_page_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 267,7 @@ def map_feed_urls(url):
)


# [START add_dynamic_page_feed]
def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
"""Updates the given campaign with the given feed details.
Expand All @@ -293,6 294,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
campaign = None
for row in results:
campaign = row.campaign
# [END add_dynamic_page_feed]

if not campaign:
raise ValueError("Campaign with id #{} not found".format(campaign_id))
Expand All @@ -304,6 306,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
)
)

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

# Display the results.
print("Updated campaign #{}".format(resource_name))
# [END add_dynamic_page_feed_1]


# [START add_dynamic_page_feed_2]
def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
"""Adds Dynamic Search Ad targeting criteria to the given ad group.
Expand Down Expand Up @@ -381,6 386,7 @@ def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
resource_name
)
)
# [END add_dynamic_page_feed_2]


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions examples/advanced_operations/add_dynamic_search_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 94,7 @@ def create_budget(client, customer_id):
return resource_name


# [START add_dynamic_search_ads]
def create_campaign(client, customer_id, budget_resource_name):
"""Creates a Dynamic Search Ad Campaign under the given customer ID.
Expand Down Expand Up @@ -139,10 140,12 @@ def create_campaign(client, customer_id, budget_resource_name):
resource_name = response.results[0].resource_name

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

return resource_name


# [START add_dynamic_search_ads_1]
def create_ad_group(client, customer_id, campaign_resource_name):
"""Creates a Dynamic Search Ad Group under the given Campaign.
Expand Down Expand Up @@ -183,10 186,12 @@ def create_ad_group(client, customer_id, campaign_resource_name):
resource_name = response.results[0].resource_name

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

return resource_name


# [START add_dynamic_search_ads_2]
def create_expanded_dsa(client, customer_id, ad_group_resource_name):
"""Creates a dynamic search ad under the given ad group.
Expand Down Expand Up @@ -219,6 224,7 @@ def create_expanded_dsa(client, customer_id, ad_group_resource_name):
resource_name = response.results[0].resource_name

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


def add_webpage_criterion(client, customer_id, ad_group_resource_name):
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_operations/add_expanded_text_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@
import google.ads.google_ads.client


# [START add_expanded_text_ads]
def main(client, customer_id, ad_group_id, number_of_ads):
ad_group_ad_service = client.get_service("AdGroupAdService", version="v6")
ad_group_service = client.get_service("AdGroupService", version="v6")
Expand Down Expand Up @@ -79,6 80,7 @@ def main(client, customer_id, ad_group_id, number_of_ads):

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


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_operations/update_expanded_text_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
from google.api_core import protobuf_helpers


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

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


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/misc/upload_image_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@
from google.ads.google_ads.errors import GoogleAdsException


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

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


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/planning/add_keyword_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
from google.ads.google_ads.errors import GoogleAdsException


# [START add_keyword_plan]
def main(client, customer_id):
"""Adds a keyword plan, campaign, ad group, etc. to the customer account
Expand Down Expand Up @@ -300,6 301,7 @@ def create_keyword_plan_negative_campaign_keywords(
"Created keyword plan campaign keyword with resource name: "
f"{response.results[0].resource_name}"
)
# [END add_keyword_plan]


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/planning/generate_forecast_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@
from google.ads.google_ads.errors import GoogleAdsException


# [START generate_forecast_metrics]
def main(client, customer_id, keyword_plan_id):
keyword_plan_service = client.get_service("KeywordPlanService")
resource_name = keyword_plan_service.keyword_plan_path(
Expand Down Expand Up @@ -67,6 68,7 @@ def main(client, customer_id, keyword_plan_id):
cpc_val = metrics.average_cpc
cpc = "{:.2f}".format(cpc_val) if cpc_val else "unspecified"
print("Estimated average cpc: {}\n".format(cpc))
# [END generate_forecast_metrics]


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/planning/generate_keyword_ideas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 30,7 @@
_DEFAULT_LANGUAGE_ID = "1000" # language ID for English


# [START generate_keyword_ideas]
def main(
client, customer_id, location_ids, language_id, keyword_texts, page_url
):
Expand Down Expand Up @@ -120,6 121,7 @@ def main(
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)
# [END generate_keyword_ideas]


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/remarketing/add_customer_match_user_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 105,7 @@ def _create_customer_match_user_list(client, customer_id):
return user_list_resource_name


# [START add_customer_match_user_list]
def _add_users_to_customer_match_user_list(
client, customer_id, user_list_resource_name
):
Expand Down Expand Up @@ -296,6 297,7 @@ def _normalize_and_hash(s):
A normalized (lowercase, remove whitespace) and SHA-256 hashed string.
"""
return hashlib.sha256(s.strip().lower().encode()).hexdigest()
# [END add_customer_match_user_list]


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,7 @@
from google.ads.google_ads.errors import GoogleAdsException


# [START add_merchant_center_dynamic_remarketing_campaign]
def main(
client,
customer_id,
Expand Down Expand Up @@ -304,6 305,7 @@ def _attach_user_list(
"Created ad group criterion with resource name "
f"'{ad_group_criterion_response.results[0].resource_name}'."
)
# [END add_merchant_center_dynamic_remarketing_campaign]


if __name__ == "__main__":
Expand Down

0 comments on commit c4c9788

Please sign in to comment.