Có hai loại ngân sách: ngân sách trung bình hằng ngày và tổng ngân sách chiến dịch. Bạn có thể tạo một trong hai loại bằng cách sử dụng CampaignBudgetService.
Tạo ngân sách trung bình hằng ngày
Đây là số tiền trung bình mà bạn sẵn sàng chi tiêu mỗi ngày cho một chiến dịch.
Bạn có thể đặt ngân sách trung bình hằng ngày bằng trường amount_micros của CampaignBudget. Ngân sách period mặc định là DAILY.
Vì explicitly_shared mặc định là true nếu bị bỏ qua trong thao tác create, nên bạn phải đặt rõ explicitly_shared thành false để tạo ngân sách không dùng chung cho một chiến dịch, như trong ví dụ sau:
Java
private static String addCampaignBudget(GoogleAdsClient googleAdsClient, long customerId) { CampaignBudget budget = CampaignBudget.newBuilder() .setName("Interplanetary Cruise Budget #" + getPrintableDateTime()) .setDeliveryMethod(BudgetDeliveryMethod.STANDARD) .setAmountMicros(500_000) .build(); CampaignBudgetOperation op = CampaignBudgetOperation.newBuilder().setCreate(budget).build(); try (CampaignBudgetServiceClient campaignBudgetServiceClient = googleAdsClient.getLatestVersion().createCampaignBudgetServiceClient()) { MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.mutateCampaignBudgets( Long.toString(customerId), ImmutableList.of(op)); String budgetResourceName = response.getResults(0).getResourceName(); System.out.printf("Added budget: %s%n", budgetResourceName); return budgetResourceName; } }
C#
private static string CreateBudget(GoogleAdsClient client, long customerId) { // Get the BudgetService. CampaignBudgetServiceClient budgetService = client.GetService( Services.V26.CampaignBudgetService); // Create the campaign budget. CampaignBudget budget = new CampaignBudget() { Name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(), DeliveryMethod = BudgetDeliveryMethod.Standard, AmountMicros = 500000 }; // Create the operation. CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation() { Create = budget }; // Create the campaign budget. MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets( customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation }); return response.Results[0].ResourceName; }
PHP
private static function addCampaignBudget(GoogleAdsClient $googleAdsClient, int $customerId) { // Creates a campaign budget. $budget = new CampaignBudget([ 'name' => 'Interplanetary Cruise Budget #' . Helper::getPrintableDatetime(), 'delivery_method' => BudgetDeliveryMethod::STANDARD, 'amount_micros' => 500000 ]); // Creates a campaign budget operation. $campaignBudgetOperation = new CampaignBudgetOperation(); $campaignBudgetOperation->setCreate($budget); // Issues a mutate request. $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient(); $response = $campaignBudgetServiceClient->mutateCampaignBudgets( MutateCampaignBudgetsRequest::build($customerId, [$campaignBudgetOperation]) ); /** @var CampaignBudget $addedBudget */ $addedBudget = $response->getResults()[0]; printf("Added budget named '%s'%s", $addedBudget->getResourceName(), PHP_EOL); return $addedBudget->getResourceName(); }
Python
# Create a budget, which can be shared by multiple campaigns. campaign_budget_operation: CampaignBudgetOperation = client.get_type( "CampaignBudgetOperation" ) campaign_budget: CampaignBudget = campaign_budget_operation.create campaign_budget.name = f"Interplanetary Budget {uuid.uuid4()}" campaign_budget.delivery_method = ( client.enums.BudgetDeliveryMethodEnum.STANDARD ) campaign_budget.amount_micros = 500000 # Add budget. campaign_budget_response: MutateCampaignBudgetsResponse try: budget_operations: List[CampaignBudgetOperation] = [ campaign_budget_operation ] campaign_budget_response = ( campaign_budget_service.mutate_campaign_budgets( customer_id=customer_id, operations=budget_operations, ) ) except GoogleAdsException as ex: handle_googleads_exception(ex)
Ruby
# Create a budget, which can be shared by multiple campaigns. campaign_budget = client.resource.campaign_budget do |cb| cb.name = "Interplanetary Budget #{(Time.new.to_f * 1000).to_i}" cb.delivery_method = :STANDARD cb.amount_micros = 500000 end operation = client.operation.create_resource.campaign_budget(campaign_budget) # Add budget. return_budget = client.service.campaign_budget.mutate_campaign_budgets( customer_id: customer_id, operations: [operation], )
Perl
# Create a campaign budget, which can be shared by multiple campaigns. my $campaign_budget = Google::Ads::GoogleAds::V26::Resources::CampaignBudget->new({ name => "Interplanetary budget #" . uniqid(), deliveryMethod => STANDARD, amountMicros => 500000 }); # Create a campaign budget operation. my $campaign_budget_operation = Google::Ads::GoogleAds::V26::Services::CampaignBudgetService::CampaignBudgetOperation ->new({create => $campaign_budget}); # Add the campaign budget. my $campaign_budgets_response = $api_client->CampaignBudgetService()->mutate({ customerId => $customer_id, operations => [$campaign_budget_operation]});
curl
Tạo tổng ngân sách chiến dịch
Đây là tổng số tiền mà bạn sẵn sàng chi tiêu trong toàn bộ thời gian chạy chiến dịch. Để tạo tổng ngân sách chiến dịch, hãy đặt ngân sách
period thành
CUSTOM_PERIOD
và đặt
total_amount_micros.
Bạn không thể chia sẻ tổng ngân sách chiến dịch giữa các chiến dịch, vì vậy, bạn phải đặt explicitly_shared thành false khi tạo ngân sách có period là CUSTOM_PERIOD.
Khi lập trình, các trường sẽ giống như trường của ngân sách trung bình hằng ngày, ngoại trừ period và total_amount_micros.
Đề xuất về ngân sách chiến dịch
Google Ads API cung cấp một số loại đề xuất để giúp bạn tối ưu hoá ngân sách chiến dịch:
CAMPAIGN_BUDGETđề xuất số tiền ngân sách mới cho các chiến dịch bị ràng buộc ngân sách.MOVE_UNUSED_BUDGETnêu bật các cơ hội để phân bổ lại ngân sách dư thừa từ một chiến dịch sang một chiến dịch khác bị ràng buộc ngân sách.MARGINAL_ROI_CAMPAIGN_BUDGETđề xuất một số tiền ngân sách mới cho những chiến dịch được dự đoán là sẽ tăng ROI khi điều chỉnh ngân sách.FORECASTING_CAMPAIGN_BUDGETđề xuất một số tiền ngân sách mới cho những chiến dịch dự kiến sẽ bị ràng buộc ngân sách trong tương lai.
Để biết thêm các loại đề xuất và hướng dẫn về cách làm việc với các đề xuất trong Google Ads API, hãy xem hướng dẫn về Điểm tối ưu hoá và đề xuất.