คุณสามารถกำหนดงบประมาณให้กับแคมเปญ ยกเลิกการเชื่อมโยงงบประมาณกับแคมเปญ หรือ เรียกข้อมูลแคมเปญที่กำหนดให้กับงบประมาณที่เฉพาะเจาะจง
กําหนดงบประมาณให้กับแคมเปญ
หลังจากสร้าง 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) // Declares whether this campaign serves political ads targeting the EU. .setContainsEuPoliticalAdvertising(DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING) // 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 }, // Declare whether or not this campaign contains political ads targeting the EU. ContainsEuPoliticalAdvertising = EuPoliticalAdvertisingStatus.DoesNotContainEuPoliticalAdvertising, // 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, // Declare whether or not this campaign serves political ads targeting the EU. 'contains_eu_political_advertising' => EuPoliticalAdvertisingStatus::DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING // Optional: Sets the start and end dates. 'start_date' => date('Ymd', strtotime('+1 day')), 'end_date' => date('Ymd', strtotime('+1 month')) ]);