/// <summary> /// Creates the budget for the campaign. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the newly created campaign budget.</returns> private static string CreateBudget(GoogleAdsClient client, long customerId) { // Get the BudgetService. CampaignBudgetServiceClient budgetService = client.GetService( Services.V4.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); }
/// <summary> /// Creates a shared campaign budget to be used to create the campaign. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="name">The budget name.</param> /// <param name="amount">The budget amount in micros.</param> /// <returns>The budget resource name.</returns> private string CreateSharedBudget(GoogleAdsClient client, long customerId, string name, long amount) { // Get the CampaignBudgetService. CampaignBudgetServiceClient campaignBudgetService = client.GetService(Services.V1.CampaignBudgetService); // Create a shared budget. CampaignBudget budget = new CampaignBudget() { Name = name, AmountMicros = amount, DeliveryMethod = BudgetDeliveryMethodEnum.Types.BudgetDeliveryMethod.Standard, ExplicitlyShared = true }; // Create the operation. CampaignBudgetOperation campaignBudgetOperation = new CampaignBudgetOperation() { Create = budget }; // Make the mutate request. MutateCampaignBudgetsResponse retVal = campaignBudgetService.MutateCampaignBudgets( customerId.ToString(), new CampaignBudgetOperation[] { campaignBudgetOperation }); return(retVal.Results[0].ResourceName); }
/// <summary> /// Creates a new campaign budget in the specified client account. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the newly created budget.</returns> private static string AddCampaignBudget(GoogleAdsClient client, long customerId) { // Get the CampaignBudgetService. CampaignBudgetServiceClient service = client.GetService( Services.V4.CampaignBudgetService); // Create a campaign budget. CampaignBudget budget = new CampaignBudget() { Name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(), DeliveryMethod = BudgetDeliveryMethod.Standard, AmountMicros = 50000000 }; // Create a campaign budget operation. CampaignBudgetOperation campaignBudgetOperation = new CampaignBudgetOperation() { Create = budget }; // Create the budget. MutateCampaignBudgetsResponse response = service.MutateCampaignBudgets( customerId.ToString(), new CampaignBudgetOperation[] { campaignBudgetOperation }); string budgetResourceName = response.Results[0].ResourceName; Console.WriteLine($"Added a budget with resource name: '{budgetResourceName}'."); return(budgetResourceName); }
/// <summary> /// Adds a campaign budget. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The campaign budget resource name.</returns> private static string AddCampaignBudget(GoogleAdsClient client, long customerId) { // Get the CampaignBudgetService. CampaignBudgetServiceClient campaignBudgetService = client.GetService(Services.V3.CampaignBudgetService); // Create the budget. CampaignBudget campaignBudget = new CampaignBudget() { Name = "", AmountMicros = 3_000_000, DeliveryMethod = BudgetDeliveryMethod.Standard }; // Create the operation. CampaignBudgetOperation operation = new CampaignBudgetOperation() { Create = campaignBudget }; // Add the campaign budget. MutateCampaignBudgetsResponse response = campaignBudgetService.MutateCampaignBudgets(customerId.ToString(), new CampaignBudgetOperation[] { operation }); // Display the result. string budgetResourceName = response.Results[0].ResourceName; Console.WriteLine($"Added budget with resource name '{budgetResourceName}'."); return(budgetResourceName); }
/// <summary> /// Creates a new campaign budget in the specified client account. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The client customer ID.</param> /// <returns>Resource name of the newly created budget.</returns> /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more /// service errors.</exception> private string AddCampaignBudget(GoogleAdsClient client, long customerId) { // Get the CampaignBudgetService. CampaignBudgetServiceClient campaignBudgetService = client.GetService(Services.V6.CampaignBudgetService); CampaignBudget budget = new CampaignBudget() { Name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(), DeliveryMethod = BudgetDeliveryMethod.Standard, AmountMicros = 5_000_000L, // Budgets for Smart Shopping campaigns cannot be shared. ExplicitlyShared = false }; CampaignBudgetOperation operation = new CampaignBudgetOperation() { Create = budget }; MutateCampaignBudgetsResponse response = campaignBudgetService.MutateCampaignBudgets(customerId.ToString(), new CampaignBudgetOperation[] { operation }); string budgetResourceName = response.Results[0].ResourceName; Console.WriteLine("Added a budget with resource name: '{0}'.", budgetResourceName); return(budgetResourceName); }
/// <summary> /// Creates the budget for the campaign. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the newly created campaign budget.</returns> private string CreateBudget(GoogleAdsClient client, long customerId) { // Get the BudgetService. CampaignBudgetServiceClient budgetService = client.GetService( Services.V4.CampaignBudgetService); // Creates a campaign budget. CampaignBudget budget = new CampaignBudget() { Name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(), DeliveryMethod = BudgetDeliveryMethod.Standard, AmountMicros = 50_000_000, // An App campaign cannot use a shared campaign budget. // explicitly_shared must be set to false. ExplicitlyShared = false }; // Create the operation. CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation() { Create = budget }; // Create the campaign budget. MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets( customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation }); string budgetResourceName = response.Results[0].ResourceName; Console.WriteLine($"Created campaign budget with resource name " + $"'{budgetResourceName}'."); return(budgetResourceName); }
/// <summary> /// Creates the budget for the campaign. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the newly created campaign budget.</returns> private static string CreateBudget(GoogleAdsClient client, long customerId) { // Get the BudgetService. CampaignBudgetServiceClient budgetService = client.GetService( Services.V3.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 }); string budgetResourceName = response.Results.First().ResourceName; // Print out some information about the added budget. Console.WriteLine($"Added campaign budget with resource name = '{budgetResourceName}'."); return(budgetResourceName); }
/// <summary>Snippet for MutateCampaignBudgets</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateCampaignBudgets() { // Create client CampaignBudgetServiceClient campaignBudgetServiceClient = CampaignBudgetServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <CampaignBudgetOperation> operations = new CampaignBudgetOperation[] { new CampaignBudgetOperation(), }; // Make the request MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.MutateCampaignBudgets(customerId, operations); }
/// <summary>Snippet for MutateCampaignBudgetsAsync</summary> public async Task MutateCampaignBudgetsAsync() { // Snippet: MutateCampaignBudgetsAsync(string, IEnumerable<CampaignBudgetOperation>, CallSettings) // Additional: MutateCampaignBudgetsAsync(string, IEnumerable<CampaignBudgetOperation>, CancellationToken) // Create client CampaignBudgetServiceClient campaignBudgetServiceClient = await CampaignBudgetServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <CampaignBudgetOperation> operations = new CampaignBudgetOperation[] { new CampaignBudgetOperation(), }; // Make the request MutateCampaignBudgetsResponse response = await campaignBudgetServiceClient.MutateCampaignBudgetsAsync(customerId, operations); // End snippet }
/// <summary> /// Builds all operations for creating a complete campaign and return an array of /// their corresponding mutate operations. /// </summary> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The mutate operations to be added to a batch job.</returns> private static List <MutateOperation> BuildAllOperations(long customerId) { List <MutateOperation> mutateOperations = new List <MutateOperation>(); // Creates a new campaign budget operation and adds it to the array of mutate operations. CampaignBudgetOperation campaignBudgetOperation = BuildCampaignBudgetOperation(customerId); mutateOperations.Add( new MutateOperation() { CampaignBudgetOperation = campaignBudgetOperation } ); // Creates new campaign operations and adds them to the array of mutate operations. List <CampaignOperation> campaignOperations = BuildCampaignOperations(customerId, campaignBudgetOperation.Create.ResourceName); foreach (CampaignOperation campaignOperation in campaignOperations) { mutateOperations.Add( new MutateOperation() { CampaignOperation = campaignOperation } ); } // Creates new campaign criterion operations and adds them to the array of mutate operations. List <CampaignCriterionOperation> campaignCriterionOperations = BuildCampaignCriterionOperations(campaignOperations); foreach (CampaignCriterionOperation campaignCriterionOperation in campaignCriterionOperations) { mutateOperations.Add( new MutateOperation() { CampaignCriterionOperation = campaignCriterionOperation } ); } // Creates new ad group operations and adds them to the array of mutate operations. List <AdGroupOperation> adGroupOperations = BuildAdGroupOperations(customerId, campaignOperations); foreach (AdGroupOperation adGroupOperation in adGroupOperations) { mutateOperations.Add( new MutateOperation() { AdGroupOperation = adGroupOperation } ); } // Creates new ad group criterion operations and adds them to the array of mutate operations. List <AdGroupCriterionOperation> adGroupCriterionOperations = BuildAdGroupCriterionOperations(adGroupOperations); foreach (AdGroupCriterionOperation adGroupCriterionOperation in adGroupCriterionOperations) { mutateOperations.Add( new MutateOperation() { AdGroupCriterionOperation = adGroupCriterionOperation } ); } // Creates new ad group ad operations and adds them to the array of mutate operations. List <AdGroupAdOperation> adGroupAdOperations = BuildAdGroupAdOperations(adGroupOperations); foreach (AdGroupAdOperation adGroupAdOperation in adGroupAdOperations) { mutateOperations.Add( new MutateOperation() { AdGroupAdOperation = adGroupAdOperation } ); } return(mutateOperations); }