campaign.ad_serving_optimization_status = client.enums.AdServingOptimizationStatusEnum.OPTIMIZE
# creates a campaign
def create_campaign(client, customer_id, campaign_budget):
"""Creates campaign resource.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
campaign_budget: a budget resource name.
Returns:
Campaign resource name.
"""
campaign_service = client.get_service("CampaignService")
campaign_operation = client.get_type("CampaignOperation")
campaign = campaign_operation.create
campaign.name = f"Complete campaign creation workflow with optimisation {uuid.uuid4()}"
campaign.advertising_channel_type = (
client.enums.AdvertisingChannelTypeEnum.SEARCH
)
# Recommendation: Set the campaign to PAUSED when creating it to prevent
# the ads from immediately serving. Set to ENABLED once you've added
# targeting and the ads are ready to serve.
campaign.status = client.enums.CampaignStatusEnum.ENABLED
# Set the bidding strategy and budget.
# The bidding strategy for Maximize Clicks is TargetSpend.
# The target_spend_micros is deprecated so don't put any value.
# See other bidding strategies you can select in the link below.
campaign.target_spend.target_spend_micros = 0
campaign.campaign_budget = campaign_budget
# set the ad rotation status
campaign.ad_serving_optimization_status = client.enums.AdServingOptimizationStatusEnum.OPTIMIZE
# Set the campaign network options.
campaign.network_settings.target_google_search = True
campaign.network_settings.target_search_network = True
campaign.network_settings.target_partner_search_network = False
# Enable Display Expansion on Search campaigns. For more details see:
campaign.network_settings.target_content_network = False
# # Optional: Set the start date.
# start_time = datetime.date.today() + datetime.timedelta(days=1)
# campaign.start_date = datetime.date.strftime(start_time, _DATE_FORMAT)
# # Optional: Set the end date.
# end_time = start_time + datetime.timedelta(weeks=4)
# campaign.end_date = datetime.date.strftime(end_time, _DATE_FORMAT)
# Add the campaign.
campaign_response = campaign_service.mutate_campaigns(
customer_id=customer_id, operations=[campaign_operation]
)
resource_name = campaign_response.results[0].resource_name
print(f"Created campaign {resource_name}.")
return resource_name