Skip to content

Commit 1d5e949

Browse files
authored
Fix Smart campaign example to correctly create location criteria. (#516)
1 parent 6794993 commit 1d5e949

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

examples/advanced_operations/add_app_campaign.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ def _set_campaign_targeting_criteria(
170170
campaign_resource_name: the campaign to apply targeting to
171171
"""
172172
campaign_criterion_service = client.get_service("CampaignCriterionService")
173-
location_type = client.enums.CriterionTypeEnum.LOCATION
174-
language_type = client.enums.CriterionTypeEnum.LANGUAGE
175173
geo_target_constant_service = client.get_service("GeoTargetConstantService")
176174
language_constant_service = client.get_service("LanguageConstantService")
177175

@@ -187,7 +185,6 @@ def _set_campaign_targeting_criteria(
187185
)
188186
campaign_criterion = campaign_criterion_operation.create
189187
campaign_criterion.campaign = campaign_resource_name
190-
campaign_criterion.type_ = location_type
191188
campaign_criterion.location.geo_target_constant = (
192189
geo_target_constant_service.geo_target_constant_path(location_id)
193190
)
@@ -200,7 +197,6 @@ def _set_campaign_targeting_criteria(
200197
)
201198
campaign_criterion = campaign_criterion_operation.create
202199
campaign_criterion.campaign = campaign_resource_name
203-
campaign_criterion.type_ = language_type
204200
campaign_criterion.language.language_constant = (
205201
language_constant_service.language_constant_path(language_id)
206202
)

examples/advanced_operations/add_smart_campaign.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def main(
8787
client, customer_id, business_location_id, business_name
8888
)
8989
campaign_criterion_operations = _create_campaign_criterion_operations(
90-
client, customer_id, keyword_theme_infos
90+
client, customer_id, keyword_theme_infos, suggestion_info
9191
)
9292
ad_group_operation = _create_ad_group_operation(client, customer_id)
9393
ad_group_ad_operation = _create_ad_group_ad_operation(
@@ -516,28 +516,26 @@ def _create_campaign_criterion_operations(
516516
campaign_criterion.campaign = campaign_service.campaign_path(
517517
customer_id, _SMART_CAMPAIGN_TEMPORARY_ID
518518
)
519-
# Set the criterion type to KEYWORD_THEME.
520-
campaign_criterion.type_ = client.enums.CriterionTypeEnum.KEYWORD_THEME
521519
# Set the keyword theme to the given KeywordThemeInfo.
522520
campaign_criterion.keyword_theme = info
523521
# Add the mutate operation to the list of other operations.
524522
operations.append(mutate_operation)
525523

526-
# Create location criterion to add location to target with the campaign
527-
mutate_operation = client.get_type("MutateOperation")
528-
campaign_criterion = (
529-
mutate_operation.campaign_criterion_operation.create
530-
)
531-
# Set the campaign ID to a temporary ID.
532-
campaign_criterion.campaign = campaign_service.campaign_path(
533-
customer_id, _SMART_CAMPAIGN_TEMPORARY_ID
534-
)
535-
# Set the criterion type to LOCATION.
536-
campaign_criterion.type_ = client.enums.CriterionTypeEnum.LOCATION
537-
# Set the location to the given location.
538-
campaign_criterion.location = suggestion_info.location_list.locations
539-
# Add the mutate operation to the list of other operations.
540-
operations.append(mutate_operation)
524+
# Create a location criterion for each location in the suggestion info
525+
# object to add corresponding location targeting to the Smart campaign
526+
for location_info in suggestion_info.location_list.locations:
527+
mutate_operation = client.get_type("MutateOperation")
528+
campaign_criterion = (
529+
mutate_operation.campaign_criterion_operation.create
530+
)
531+
# Set the campaign ID to a temporary ID.
532+
campaign_criterion.campaign = campaign_service.campaign_path(
533+
customer_id, _SMART_CAMPAIGN_TEMPORARY_ID
534+
)
535+
# Set the location to the given location.
536+
campaign_criterion.location = location_info
537+
# Add the mutate operation to the list of other operations.
538+
operations.append(mutate_operation)
541539

542540
return operations
543541
# [END add_smart_campaign_8]

0 commit comments

Comments
 (0)