/// <summary> /// Creates a test campaign for running further tests. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="biddingStrategy">The bidding strategy to be used.</param> /// <returns>The campaign id.</returns> public long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType, BiddingStrategyType strategyType) { CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201406.CampaignService); BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); biddingConfig.biddingStrategyType = strategyType; CampaignOperation campaignOperation = new CampaignOperation(); campaignOperation.@operator = Operator.ADD; campaignOperation.operand = new Campaign(); campaignOperation.operand.name = string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-M-d H:m:s.ffffff")); campaignOperation.operand.advertisingChannelType = channelType; campaignOperation.operand.status = CampaignStatus.PAUSED; campaignOperation.operand.biddingStrategyConfiguration = biddingConfig; campaignOperation.operand.budget = new Budget(); campaignOperation.operand.budget.budgetId = CreateBudget(user); campaignOperation.operand.budget.period = BudgetBudgetPeriod.DAILY; campaignOperation.operand.budget.amount = new Money(); campaignOperation.operand.budget.amount.microAmount = 100000000; campaignOperation.operand.budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD; List<Setting> settings = new List<Setting>(); KeywordMatchSetting matchSetting = new KeywordMatchSetting(); matchSetting.optIn = true; settings.Add(matchSetting); if (channelType == AdvertisingChannelType.SHOPPING) { // All Shopping campaigns need a ShoppingSetting. ShoppingSetting shoppingSetting = new ShoppingSetting(); shoppingSetting.salesCountry = "US"; shoppingSetting.campaignPriority = 0; shoppingSetting.merchantId = (user.Config as AdWordsAppConfig).MerchantCenterId; settings.Add(shoppingSetting); } campaignOperation.operand.settings = settings.ToArray(); CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {campaignOperation}); return retVal.value[0].id; }
/// <summary> /// Creates the shopping campaign. /// </summary> /// <param name="budgetId">The budget id.</param> /// <param name="merchantId">The Merchant Center id.</param> /// <param name="campaignService">The CampaignService instance.</param> /// <returns>The Shopping campaign.</returns> private static Campaign CreateCampaign(long budgetId, long merchantId, CampaignService campaignService) { // Create campaign. Campaign campaign = new Campaign(); campaign.name = "Shopping campaign #" + ExampleUtilities.GetRandomString(); // The advertisingChannelType is what makes this a Shopping campaign. campaign.advertisingChannelType = AdvertisingChannelType.SHOPPING; // Set shared budget (required). campaign.budget = new Budget(); campaign.budget.budgetId = budgetId; // Set bidding strategy (required). BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC; campaign.biddingStrategyConfiguration = biddingStrategyConfiguration; // Set keyword matching setting (required). KeywordMatchSetting keywordMatchSetting = new KeywordMatchSetting(); keywordMatchSetting.optIn = false; // All Shopping campaigns need a ShoppingSetting. ShoppingSetting shoppingSetting = new ShoppingSetting(); shoppingSetting.salesCountry = "US"; shoppingSetting.campaignPriority = 0; shoppingSetting.merchantId = merchantId; campaign.settings = new Setting[] { keywordMatchSetting, shoppingSetting }; // Create operation. CampaignOperation campaignOperation = new CampaignOperation(); campaignOperation.operand = campaign; campaignOperation.@operator = Operator.ADD; // Make the mutate request. CampaignReturnValue retval = campaignService.mutate( new CampaignOperation[] { campaignOperation }); return retval.value[0]; }