/// <summary> /// Creates the portfolio bidding strategy. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="name">The bidding strategy name.</param> /// <param name="bidCeiling">The bid ceiling.</param> /// <param name="spendTarget">The spend target.</param> /// <returns>The bidding strategy object.</returns> private SharedBiddingStrategy CreateBiddingStrategy(AdWordsUser user, String name, long bidCeiling, long spendTarget) { using (BiddingStrategyService biddingStrategyService = (BiddingStrategyService)user.GetService( AdWordsService.v201702.BiddingStrategyService)) { // Create a portfolio bidding strategy. SharedBiddingStrategy portfolioBiddingStrategy = new SharedBiddingStrategy(); portfolioBiddingStrategy.name = name; TargetSpendBiddingScheme biddingScheme = new TargetSpendBiddingScheme(); // Optionally set additional bidding scheme parameters. biddingScheme.bidCeiling = new Money(); biddingScheme.bidCeiling.microAmount = bidCeiling; biddingScheme.spendTarget = new Money(); biddingScheme.spendTarget.microAmount = spendTarget; portfolioBiddingStrategy.biddingScheme = biddingScheme; // Create operation. BiddingStrategyOperation operation = new BiddingStrategyOperation(); operation.@operator = Operator.ADD; operation.operand = portfolioBiddingStrategy; return(biddingStrategyService.mutate( new BiddingStrategyOperation[] { operation }).value[0]); } }
/// <summary> /// Creates the shared bidding strategy. /// </summary> /// <param name="biddingStrategyService">The bidding strategy service.</param> /// <param name="name">The bidding strategy name.</param> /// <param name="bidCeiling">The bid ceiling.</param> /// <param name="spendTarget">The spend target.</param> /// <returns>The bidding strategy object.</returns> private SharedBiddingStrategy CreateBiddingStrategy( BiddingStrategyService biddingStrategyService, String name, long bidCeiling, long spendTarget) { // Create a shared bidding strategy. SharedBiddingStrategy sharedBiddingStrategy = new SharedBiddingStrategy(); sharedBiddingStrategy.name = name; TargetSpendBiddingScheme biddingScheme = new TargetSpendBiddingScheme(); // Optionally set additional bidding scheme parameters. biddingScheme.bidCeiling = new Money(); biddingScheme.bidCeiling.microAmount = bidCeiling; biddingScheme.spendTarget = new Money(); biddingScheme.spendTarget.microAmount = spendTarget; sharedBiddingStrategy.biddingScheme = biddingScheme; // Create operation. BiddingStrategyOperation operation = new BiddingStrategyOperation(); operation.@operator = Operator.ADD; operation.operand = sharedBiddingStrategy; return(biddingStrategyService.mutate(new BiddingStrategyOperation[] { operation }).value[0]); }
/// <summary> /// Creates the portfolio bidding strategy. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="name">The bidding strategy name.</param> /// <param name="bidCeiling">The bid ceiling.</param> /// <param name="spendTarget">The spend target.</param> /// <returns>The bidding strategy object.</returns> private SharedBiddingStrategy CreateBiddingStrategy(AdWordsUser user, string name, long bidCeiling, long spendTarget) { using (BiddingStrategyService biddingStrategyService = (BiddingStrategyService)user.GetService( AdWordsService.v201806.BiddingStrategyService)) { // Create a portfolio bidding strategy. SharedBiddingStrategy portfolioBiddingStrategy = new SharedBiddingStrategy { name = name }; TargetSpendBiddingScheme biddingScheme = new TargetSpendBiddingScheme { // Optionally set additional bidding scheme parameters. bidCeiling = new Money { microAmount = bidCeiling }, spendTarget = new Money { microAmount = spendTarget } }; portfolioBiddingStrategy.biddingScheme = biddingScheme; // Create operation. BiddingStrategyOperation operation = new BiddingStrategyOperation { @operator = Operator.ADD, operand = portfolioBiddingStrategy }; return(biddingStrategyService.mutate( new BiddingStrategyOperation[] { operation }).value[0]); } }
/// <summary> /// Runs the specified code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the services. BiddingStrategyService biddingStrategyService = (BiddingStrategyService)user.GetService( AdWordsService.v201607.BiddingStrategyService); BudgetService budgetService = (BudgetService)user.GetService( AdWordsService.v201607.BudgetService); CampaignService campaignService = (CampaignService)user.GetService( AdWordsService.v201607.CampaignService); String BIDDINGSTRATEGY_NAME = "Maximize Clicks " + ExampleUtilities.GetRandomString(); const long BID_CEILING = 2000000; const long SPEND_TARGET = 20000000; String BUDGET_NAME = "Shared Interplanetary Budget #" + ExampleUtilities.GetRandomString(); const long BUDGET_AMOUNT = 30000000; String CAMPAIGN_NAME = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(); try { SharedBiddingStrategy portfolioBiddingStrategy = CreateBiddingStrategy( biddingStrategyService, BIDDINGSTRATEGY_NAME, BID_CEILING, SPEND_TARGET); Console.WriteLine("Portfolio bidding strategy with name '{0}' and ID {1} of type " + "{2} was created.", portfolioBiddingStrategy.name, portfolioBiddingStrategy.id, portfolioBiddingStrategy.biddingScheme.BiddingSchemeType); Budget sharedBudget = CreateSharedBudget(budgetService, BUDGET_NAME, BUDGET_AMOUNT); Campaign newCampaign = CreateCampaignWithBiddingStrategy(campaignService, CAMPAIGN_NAME, portfolioBiddingStrategy.id, sharedBudget.budgetId); Console.WriteLine("Campaign with name '{0}', ID {1} and bidding scheme ID {2} was " + "created.", newCampaign.name, newCampaign.id, newCampaign.biddingStrategyConfiguration.biddingStrategyId); } catch (Exception e) { throw new System.ApplicationException("Failed to create campaign that uses portfolio " + "bidding strategy.", e); } }
/// <summary> /// Creates the shared bidding strategy. /// </summary> /// <param name="biddingStrategyService">The bidding strategy service.</param> /// <param name="name">The bidding strategy name.</param> /// <param name="bidCeiling">The bid ceiling.</param> /// <param name="spendTarget">The spend target.</param> /// <returns>The bidding strategy object.</returns> private SharedBiddingStrategy CreateBiddingStrategy( BiddingStrategyService biddingStrategyService, String name, long bidCeiling, long spendTarget) { // Create a shared bidding strategy. SharedBiddingStrategy sharedBiddingStrategy = new SharedBiddingStrategy(); sharedBiddingStrategy.name = name; TargetSpendBiddingScheme biddingScheme = new TargetSpendBiddingScheme(); // Optionally set additional bidding scheme parameters. biddingScheme.bidCeiling = new Money(); biddingScheme.bidCeiling.microAmount = bidCeiling; biddingScheme.spendTarget = new Money(); biddingScheme.spendTarget.microAmount = spendTarget; sharedBiddingStrategy.biddingScheme = biddingScheme; // Create operation. BiddingStrategyOperation operation = new BiddingStrategyOperation(); operation.@operator = Operator.ADD; operation.operand = sharedBiddingStrategy; return biddingStrategyService.mutate(new BiddingStrategyOperation[] {operation}).value[0]; }