为广告系列分配预算
完成
创建了CampaignBudget
替换为
CampaignBudgetService
或
发现一个现有实例,
您需要使用
resource_name
字段值来调用
CampaignService
。请注意
孤立预算(未与任何广告系列相关联的预算)
分配操作失败,但预算创建操作成功。周三
建议您重复使用或移除
预算。
新广告系列
对于新广告系列,请在
CampaignOperation.create
、
设这个
campaign_budget
字段的
Campaign
将对象替换为预算资源名称,如以下代码示例所示。
Java
// Creates the campaign. Campaign campaign = Campaign.newBuilder() .setName("Interplanetary Cruise #" + getPrintableDateTime()) .setAdvertisingChannelType(AdvertisingChannelType.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 .setStatus(CampaignStatus.PAUSED) // Sets the bidding strategy and budget. .setManualCpc(ManualCpc.newBuilder().build()) .setCampaignBudget(budgetResourceName) // Adds the networkSettings configured above. .setNetworkSettings(networkSettings) // Optional: Sets the start & end dates. .setStartDate(new DateTime().plusDays(1).toString("yyyyMMdd")) .setEndDate(new DateTime().plusDays(30).toString("yyyyMMdd")) .build();
C#
// Create the campaign. Campaign campaign = new Campaign() { Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(), AdvertisingChannelType = AdvertisingChannelType.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 Status = CampaignStatus.Paused, // Set the bidding strategy and budget. ManualCpc = new ManualCpc(), CampaignBudget = budget, // Set the campaign network options. NetworkSettings = new NetworkSettings { TargetGoogleSearch = true, TargetSearchNetwork = true, // Enable Display Expansion on Search campaigns. See // https://support.google.com/google-ads/answer/7193800 to learn more. TargetContentNetwork = true, TargetPartnerSearchNetwork = false }, // Optional: Set the start date. StartDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"), // Optional: Set the end date. EndDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd"), };
PHP
$campaign = new Campaign([ 'name' => 'Interplanetary Cruise #' . Helper::getPrintableDatetime(), 'advertising_channel_type' => AdvertisingChannelType::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. 'status' => CampaignStatus::PAUSED, // Sets the bidding strategy and budget. 'manual_cpc' => new ManualCpc(), 'campaign_budget' => $budgetResourceName, // Adds the network settings configured above. 'network_settings' => $networkSettings, // Optional: Sets the start and end dates. 'start_date' => date('Ymd', strtotime('+1 day')), 'end_date' => date('Ymd', strtotime('+1 month')) ]);
Python
# Create campaign. campaign_operation = client.get_type("CampaignOperation") campaign = campaign_operation.create campaign.name = f"Interplanetary Cruise {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.PAUSED # Set the bidding strategy and budget. campaign.manual_cpc.enhanced_cpc_enabled = True campaign.campaign_budget = campaign_budget_response.results[0].resource_name # 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: # https://support.google.com/google-ads/answer/7193800 campaign.network_settings.target_content_network = True
Ruby
# Create campaign. campaign = client.resource.campaign do |c| c.name = "Interplanetary Cruise #{(Time.new.to_f * 1000).to_i}" c.advertising_channel_type = :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. c.status = :PAUSED # Set the bidding strategy and budget. c.manual_cpc = client.resource.manual_cpc c.campaign_budget = return_budget.results.first.resource_name # Set the campaign network options. c.network_settings = client.resource.network_settings do |ns| ns.target_google_search = true ns.target_search_network = true # Enable Display Expansion on Search campaigns. See # https://support.google.com/google-ads/answer/7193800 to learn more. ns.target_content_network = true ns.target_partner_search_network = false end # Optional: Set the start date. c.start_date = DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d') # Optional: Set the end date. c.end_date = DateTime.parse((Date.today.next_year).to_s).strftime('%Y%m%d') end
Perl
# Create a campaign. my $campaign = Google::Ads::GoogleAds::V17::Resources::Campaign->new({ name => "Interplanetary Cruise #" . uniqid(), advertisingChannelType => SEARCH, # Recommendation: Set the campaign to PAUSED when creating it to stop # the ads from immediately serving. Set to ENABLED once you've added # targeting and the ads are ready to serve. status => PAUSED, # Set the bidding strategy and budget. manualCpc => Google::Ads::GoogleAds::V17::Common::ManualCpc->new( {enhancedCpcEnabled => "true"} ), campaignBudget => $campaign_budgets_response->{results}[0]{resourceName}, # Set the campaign network options. networkSettings => Google::Ads::GoogleAds::V17::Resources::NetworkSettings->new({ targetGoogleSearch => "true", targetSearchNetwork => "true", # Enable Display Expansion on Search campaigns. See # https://support.google.com/google-ads/answer/7193800 to learn more. targetContentNetwork => "true", targetPartnerSearchNetwork => "false" } ), # Optional: Set the start date. The campaign starts tomorrow. startDate => strftime("%Y%m%d", localtime(time + 60 * 60 * 24)), # Optional: Set the end date. The campaign runs for 30 days. endDate => strftime("%Y%m%d", localtime(time + 60 * 60 * 24 * 30)), });
现有广告系列
要替换现有广告系列的预算,请在
CampaignOperation.update
、
设置 campaign_budget
字段
Campaign
对象的另一个属性,
现有预算(以及任何其他广告系列)的资源名称
您可能想设置的字段)。请注意,这样将替换现有的
为广告系列分配了 campaign_budget
指定的预算
字段,因为一个广告系列每次只能与一个预算相关联。
取消预算与广告系列之间的关联
广告系列必须始终与预算相关联。您可以移除预算 从广告系列中更改与广告系列相关联的预算,从而 将其替换为另一项预算。找出广告系列 则请继续学习下一部分。
获取分配到预算的广告系列
获取使用相同预算的广告系列列表有助于实现以下目的: 平衡预算利用率。以下 GAQL 查询将返回 指定预算 ID 对应的所有广告系列:
SELECT campaign.id FROM campaign WHERE campaign_budget.id = campaign_budget_id