/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the BudgetSuggestionService. BudgetSuggestionService budgetSuggestionService = (BudgetSuggestionService) user.GetService(AdWordsService.v201502.BudgetSuggestionService); BudgetSuggestionSelector selector = new BudgetSuggestionSelector(); List<Criterion> criteria = new List<Criterion>(); // Criterion - Travel Agency product/service. See GetProductServices.cs for an example // of how to get valid product/service settings. ProductService productService = new ProductService(); productService.text = "Travel Agency"; productService.locale = "en_US"; criteria.Add(productService); // Criterion - English language. // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes Language language = new Language(); language.id = 1000L; criteria.Add(language); // Criterion - Mountain View, California location. // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/geotargeting // https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions Location location = new Location(); location.id = 1014044L; criteria.Add(location); selector.criteria = criteria.ToArray(); try { BudgetSuggestion budgetSuggestion = budgetSuggestionService.get(selector); Console.WriteLine("Budget suggestion for criteria is:\n" + " SuggestedBudget={0}\n" + " Min/MaxBudget={1}/{2}\n" + " Min/MaxCpc={3}/{4}\n" + " CPM={5}\n" + " CPC={6}\n" + " Impressions={7}\n", budgetSuggestion.suggestedBudget.microAmount, budgetSuggestion.minBudget.microAmount, budgetSuggestion.maxBudget.microAmount, budgetSuggestion.minCpc.microAmount, budgetSuggestion.maxCpc.microAmount, budgetSuggestion.cpm.microAmount, budgetSuggestion.cpc.microAmount, budgetSuggestion.impressions); if (budgetSuggestion.budgetQuantiles != null && budgetSuggestion.budgetQuantiles.Length > 0) { int quantileCount = 0; Console.WriteLine(" Budget quantiles:"); foreach (Money budgetQuantile in budgetSuggestion.budgetQuantiles) { Console.WriteLine(" {0}) {1}", ++quantileCount, budgetQuantile.microAmount); } } else { Console.WriteLine(" No budget quantiles found on budget suggestion"); } } catch (Exception e) { throw new System.ApplicationException("Failed to get budget suggestion.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="businessId">The AdWords Express business id.</param> public void Run(AdWordsUser user, long businessId) { // Get the ExpressBusinessService. ExpressBusinessService businessService = (ExpressBusinessService) user.GetService(AdWordsService.v201502.ExpressBusinessService); // Get the PromotionService PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201502.PromotionService); // Get the business for the businessId. We will need its geo point to // create a Proximity criterion for the new Promotion. Selector businessSelector = new Selector(); Predicate predicate = new Predicate(); predicate.field = "Id"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { businessId.ToString() }; businessSelector.predicates = new Predicate[] { predicate }; businessSelector.fields = new string[] { "Id", "GeoPoint" }; ExpressBusinessPage businessPage = businessService.get(businessSelector); if (businessPage == null || businessPage.entries == null || businessPage.entries.Length == 0) { Console.WriteLine("No business was found."); return; } // Set the business ID to the service. promotionService.RequestHeader.expressBusinessId = businessId; // First promotion Promotion marsTourPromotion = new Promotion(); Money budget = new Money(); budget.microAmount = 1000000L; marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString(); marsTourPromotion.status = PromotionStatus.PAUSED; marsTourPromotion.destinationUrl = "http://www.example.com"; marsTourPromotion.budget = budget; marsTourPromotion.callTrackingEnabled = true; // Criteria // Criterion - Travel Agency product service ProductService productService = new ProductService(); productService.text = "Travel Agency"; // Criterion - English language // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes Language language = new Language(); language.id = 1000L; // Criterion - Within 15 miles Proximity proximity = new Proximity(); proximity.geoPoint = businessPage.entries[0].geoPoint; proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES; proximity.radiusInUnits = 15; marsTourPromotion.criteria = new Criterion[] { productService, language, proximity }; // Creative Creative creative = new Creative(); creative.headline = "Standard Mars Trip"; creative.line1 = "Fly coach to Mars"; creative.line2 = "Free in-flight pretzels"; marsTourPromotion.creatives = new Creative[] { creative }; PromotionOperation operation = new PromotionOperation(); operation.@operator = Operator.ADD; operation.operand = marsTourPromotion; try { Promotion[] addedPromotions = promotionService.mutate( new PromotionOperation[] { operation }); Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.", addedPromotions[0].id, addedPromotions[0].name, businessId); } catch (Exception e) { throw new System.ApplicationException("Failed to add promotions.", e); } }