Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example code for PMax campaigns to add search theme signal #883

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions examples/advanced_operations/add_performance_max_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def main(client, customer_id, audience_id):
headline_asset_resource_names,
description_asset_resource_names,
)
asset_group_signal_operations = create_asset_group_signal_operations(
client, customer_id, audience_id
yangda marked this conversation as resolved.
Show resolved Hide resolved
)

mutate_operations = [
# It's important to create these entities in this order because
Expand All @@ -130,16 +133,9 @@ def main(client, customer_id, audience_id):
# other mutate operations
*campaign_criterion_operations,
*asset_group_operations,
*asset_group_signal_operations,
]

# Append an asset group signal operation is an audience ID is given.
if audience_id:
mutate_operations.append(
create_asset_group_signal_operation(
client, customer_id, audience_id
)
)

# Send the operations in a single Mutate request.
response = googleads_service.mutate(
customer_id=customer_id, mutate_operations=mutate_operations
Expand Down Expand Up @@ -632,8 +628,8 @@ def print_response_details(response):
)


# [START add_performance_max_campaign_9]
def create_asset_group_signal_operation(client, customer_id, audience_id):

def create_asset_group_signal_operations(client, customer_id, audience_id):
"""Creates a list of MutateOperations that may create asset group signals.

Args:
Expand All @@ -644,25 +640,40 @@ def create_asset_group_signal_operation(client, customer_id, audience_id):
Returns:
MutateOperations that create new asset group signals.
"""
if not audience_id:
return None

googleads_service = client.get_service("GoogleAdsService")
asset_group_resource_name = googleads_service.asset_group_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID
)

operations = []

if audience_id:
# Create an audience asset group signal.
# To learn more about Audience Signals, see:
# https://developers.google.com/google-ads/api/performance-max/asset-group-signals#audiences
# [START add_performance_max_campaign_9]
mutate_operation = client.get_type("MutateOperation")
operation = mutate_operation.asset_group_signal_operation.create
operation.asset_group = asset_group_resource_name
operation.audience.audience = googleads_service.audience_path(
customer_id, audience_id
)
operations.append(mutate_operation)
# [END add_performance_max_campaign_9]

# Create a search theme asset group signal.
# To learn more about Search Themes Signals, see:
# https://developers.google.com/google-ads/api/performance-max/asset-group-signals#search_themes
# [START add_performance_max_campaign_10]
mutate_operation = client.get_type("MutateOperation")
operation = mutate_operation.asset_group_signal_operation.create
# To learn more about Audience Signals, see:
# https://developers.google.com/google-ads/api/docs/performance-max/asset-groups#audience_signals
operation.asset_group = asset_group_resource_name
operation.audience.audience = googleads_service.audience_path(
customer_id, audience_id
)
operation.search_theme.text = "travel"
operations.append(mutate_operation)
# [END add_performance_max_campaign_10]

return mutate_operation
# [END add_performance_max_campaign_9]
return operations



# [END add_performance_max_campaign]
Expand Down