Skip to content

Commit

Permalink
Changes for march release. (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenRKarl authored Apr 4, 2022
1 parent 23b6342 commit 8d18441
Show file tree
Hide file tree
Showing 17 changed files with 1,555 additions and 313 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
* 15.1.0
- Fix issue preventing streaming responses from being logged.
- Expose logging utilities for external interceptor logic.
- Various example updates and improvements.

* 15.0.0
- Google Ads API v10_0 release.
- Remove all "get" methods from services.
- Remove services that only contained "get" methods.
- Remove support got Google Ads API v7_0.

* 14.1.0
- Google Ads API v9_0 release
- Update gRPC transport logic to replace "gapic" user-agent with "gccl"
Expand Down
148 changes: 82 additions & 66 deletions examples/advanced_operations/add_performance_max_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@


# [START add_performance_max_campaign]
def main(
client,
customer_id,
):
def main(client, customer_id, audience_id):
"""The main method that creates all necessary entities for the example.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
audience_id: an optional audience ID.
"""
# [START add_performance_max_campaign_1]
googleads_service = client.get_service("GoogleAdsService")
Expand All @@ -77,22 +75,11 @@ def main(
#
# Create the headlines.
headline_asset_resource_names = _create_multiple_text_assets(
client,
customer_id,
[
"Travel",
"Travel Reviews",
"Book travel",
],
client, customer_id, ["Travel", "Travel Reviews", "Book travel",],
)
# Create the descriptions.
description_asset_resource_names = _create_multiple_text_assets(
client,
customer_id,
[
"Take to the air!",
"Fly to the sky!",
],
client, customer_id, ["Take to the air!", "Fly to the sky!",],
)

# The below methods create and return MutateOperations that we later
Expand All @@ -103,18 +90,13 @@ def main(
# successfully or fail entirely, leaving no orphaned entities. See:
# https://developers.google.com/google-ads/api/docs/mutating/overview
campaign_budget_operation = _create_campaign_budget_operation(
client,
customer_id,
client, customer_id,
)
performance_max_campaign_operation = (
_create_performance_max_campaign_operation(
client,
customer_id,
)
performance_max_campaign_operation = _create_performance_max_campaign_operation(
client, customer_id,
)
campaign_criterion_operations = _create_campaign_criterion_operations(
client,
customer_id,
client, customer_id,
)
asset_group_operations = _create_asset_group_operation(
client,
Expand All @@ -123,28 +105,37 @@ def main(
description_asset_resource_names,
)

mutate_operations = [
# It's important to create these entities in this order because
# they depend on each other.
campaign_budget_operation,
performance_max_campaign_operation,
# Expand the list of multiple operations into the list of
# other mutate operations
*campaign_criterion_operations,
*asset_group_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=[
# It's important to create these entities in this order because
# they depend on each other.
campaign_budget_operation,
performance_max_campaign_operation,
# Expand the list of multiple operations into the list of
# other mutate operations
*campaign_criterion_operations,
*asset_group_operations,
],
customer_id=customer_id, mutate_operations=mutate_operations
)

_print_response_details(response)
# [END add_performance_max_campaign_1]


# [START add_performance_max_campaign_2]
def _create_campaign_budget_operation(
client,
customer_id,
client, customer_id,
):
"""Creates a MutateOperation that creates a new CampaignBudget.
Expand Down Expand Up @@ -182,8 +173,7 @@ def _create_campaign_budget_operation(

# [START add_performance_max_campaign_3]
def _create_performance_max_campaign_operation(
client,
customer_id,
client, customer_id,
):
"""Creates a MutateOperation that creates a new Performance Max campaign.
Expand Down Expand Up @@ -252,8 +242,7 @@ def _create_performance_max_campaign_operation(

# [START add_performance_max_campaign_4]
def _create_campaign_criterion_operations(
client,
customer_id,
client, customer_id,
):
"""Creates a list of MutateOperations that create new campaign criteria.
Expand Down Expand Up @@ -284,8 +273,8 @@ def _create_campaign_criterion_operations(
campaign_criterion.campaign = campaign_service.campaign_path(
customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID
)
campaign_criterion.location.geo_target_constant = (
geo_target_constant_service.geo_target_constant_path("1023191")
campaign_criterion.location.geo_target_constant = geo_target_constant_service.geo_target_constant_path(
"1023191"
)
campaign_criterion.negative = False
operations.append(mutate_operation)
Expand All @@ -296,8 +285,8 @@ def _create_campaign_criterion_operations(
campaign_criterion.campaign = campaign_service.campaign_path(
customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID
)
campaign_criterion.location.geo_target_constant = (
geo_target_constant_service.geo_target_constant_path("1022762")
campaign_criterion.location.geo_target_constant = geo_target_constant_service.geo_target_constant_path(
"1022762"
)
campaign_criterion.negative = True
operations.append(mutate_operation)
Expand All @@ -311,9 +300,9 @@ def _create_campaign_criterion_operations(
# Set the language.
# For a list of all language codes, see:
# https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7
campaign_criterion.language.language_constant = (
googleads_service.language_constant_path("1000") # English
)
campaign_criterion.language.language_constant = googleads_service.language_constant_path(
"1000"
) # English
operations.append(mutate_operation)

return operations
Expand Down Expand Up @@ -346,8 +335,7 @@ def _create_multiple_text_assets(client, customer_id, texts):

# Send the operations in a single Mutate request.
response = googleads_service.mutate(
customer_id=customer_id,
mutate_operations=operations,
customer_id=customer_id, mutate_operations=operations,
)
asset_resource_names = []
for result in response.mutate_operation_responses:
Expand Down Expand Up @@ -395,8 +383,7 @@ def _create_asset_group_operation(
asset_group.final_mobile_urls.append("http://www.example.com")
asset_group.status = client.enums.AssetGroupStatusEnum.PAUSED
asset_group.resource_name = asset_group_service.asset_group_path(
customer_id,
_ASSET_GROUP_TEMPORARY_ID,
customer_id, _ASSET_GROUP_TEMPORARY_ID,
)
operations.append(mutate_operation)

Expand All @@ -420,8 +407,7 @@ def _create_asset_group_operation(
asset_group_asset = mutate_operation.asset_group_asset_operation.create
asset_group_asset.field_type = client.enums.AssetFieldTypeEnum.HEADLINE
asset_group_asset.asset_group = asset_group_service.asset_group_path(
customer_id,
_ASSET_GROUP_TEMPORARY_ID,
customer_id, _ASSET_GROUP_TEMPORARY_ID,
)
asset_group_asset.asset = resource_name
operations.append(mutate_operation)
Expand All @@ -434,8 +420,7 @@ def _create_asset_group_operation(
client.enums.AssetFieldTypeEnum.DESCRIPTION
)
asset_group_asset.asset_group = asset_group_service.asset_group_path(
customer_id,
_ASSET_GROUP_TEMPORARY_ID,
customer_id, _ASSET_GROUP_TEMPORARY_ID,
)
asset_group_asset.asset = resource_name
operations.append(mutate_operation)
Expand Down Expand Up @@ -523,8 +508,7 @@ def _create_and_link_text_asset(client, customer_id, text, field_type):
asset_group_asset = mutate_operation.asset_group_asset_operation.create
asset_group_asset.field_type = field_type
asset_group_asset.asset_group = asset_group_service.asset_group_path(
customer_id,
_ASSET_GROUP_TEMPORARY_ID,
customer_id, _ASSET_GROUP_TEMPORARY_ID,
)
asset_group_asset.asset = asset_service.asset_path(
customer_id, next_temp_id
Expand Down Expand Up @@ -574,8 +558,7 @@ def _create_and_link_image_asset(
asset_group_asset = mutate_operation.asset_group_asset_operation.create
asset_group_asset.field_type = field_type
asset_group_asset.asset_group = asset_group_service.asset_group_path(
customer_id,
_ASSET_GROUP_TEMPORARY_ID,
customer_id, _ASSET_GROUP_TEMPORARY_ID,
)
asset_group_asset.asset = asset_service.asset_path(
customer_id, next_temp_id
Expand Down Expand Up @@ -624,6 +607,39 @@ def _print_response_details(response):
)


# [START add_performance_max_campaign_9]
def _create_asset_group_signal_operation(client, customer_id, audience_id):
"""Creates a list of MutateOperations that may create asset group signals.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
audience_id: an optional 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
)

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
)

return mutate_operation
# [END add_performance_max_campaign_9]


# [END add_performance_max_campaign]

if __name__ == "__main__":
Expand All @@ -642,14 +658,14 @@ def _print_response_details(response):
required=True,
help="The Google Ads customer ID.",
)
parser.add_argument(
"-a", "--audience_id", type=str, help="The ID of an audience.",
)

args = parser.parse_args()

try:
main(
googleads_client,
args.customer_id,
)
main(googleads_client, args.customer_id, args.audience_id)
except GoogleAdsException as ex:
print(
f'Request with ID "{ex.request_id}" failed with status '
Expand Down
10 changes: 5 additions & 5 deletions examples/basic_operations/add_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ def main(client, customer_id):

# Add budget.
try:
campaign_budget_response = (
campaign_budget_service.mutate_campaign_budgets(
customer_id=customer_id, operations=[campaign_budget_operation]
)
campaign_budget_response = campaign_budget_service.mutate_campaign_budgets(
customer_id=customer_id, operations=[campaign_budget_operation]
)
except GoogleAdsException as ex:
_handle_googleads_exception(ex)
Expand All @@ -76,8 +74,10 @@ def main(client, customer_id):
# Set the campaign network options.
campaign.network_settings.target_google_search = True
campaign.network_settings.target_search_network = True
campaign.network_settings.target_content_network = False
campaign.network_settings.target_partner_search_network = False
# Enable Display Expansion on Search campaigns. For more details see:
# https://support.google.com/google-ads/answer/7193800
campaign.network_settings.target_content_network = True
# [END add_campaigns_1]

# Optional: Set the start date.
Expand Down
Loading

0 comments on commit 8d18441

Please sign in to comment.