/// <summary>
        /// Runs the code example, showing a typical series of calls to the
        /// <see cref="Services.V3.ReachPlanService"/>.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            string locationId   = "2840"; // US
            string currencyCode = "USD";
            long   budgetMicros = 500_000_000_000L;
            ReachPlanServiceClient reachPlanService =
                client.GetService(Services.V3.ReachPlanService);

            try
            {
                ShowPlannableLocations(reachPlanService);
                ShowPlannableProducts(reachPlanService, locationId);
                ForecastManualMix(
                    reachPlanService, customerId.ToString(), locationId, currencyCode, budgetMicros);
                ForecastSuggestedMix(
                    reachPlanService, customerId.ToString(), locationId, currencyCode, budgetMicros);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Pulls a forecast for a budget split 15% and 85% between two products.
        /// </summary>
        /// <param name="reachPlanService">Instance of Reach Plan Service client.</param>
        /// <param name="customerId">The customer ID for the reach forecast.</param>
        /// <param name="locationId">Location ID to plan for. To find a valid locaction ID, either
        /// see https://developers.google.com/adwords/api/docs/appendix/geotargeting or call
        /// <see cref="ReachPlanServiceClient.ListPlannableLocations"/>.</param>
        /// <param name="currencyCode">Three-character ISO 4217 currency code.</param>
        /// <param name="budgetMicros">Budget in currency to plan for.</param>
        public void ForecastManualMix(
            ReachPlanServiceClient reachPlanService,
            string customerId,
            string locationId,
            string currencyCode,
            long budgetMicros)
        {
            List <PlannedProduct> productMix = new List <PlannedProduct>();

            // Set up a ratio to split the budget between two products.
            double trueviewAllocation = 0.15;
            double bumperAllocation   = 1 - trueviewAllocation;

            // See listPlannableProducts on ReachPlanService to retrieve a list
            // of valid PlannableProductCode's for a given location:
            // https://developers.google.com/google-ads/api/reference/rpc/Google.Ads.GoogleAds.V3.services#reachplanservice
            productMix.Add(new PlannedProduct()
            {
                PlannableProductCode = "TRUEVIEW_IN_STREAM",
                BudgetMicros         = Convert.ToInt64((double)budgetMicros * trueviewAllocation)
            });
            productMix.Add(new PlannedProduct()
            {
                PlannableProductCode = "BUMPER",
                BudgetMicros         = Convert.ToInt64((double)budgetMicros * bumperAllocation)
            });

            GenerateReachForecastRequest request =
                BuildReachRequest(customerId, productMix, locationId, currencyCode);

            PullReachCurve(reachPlanService, request);
        }
        /// <summary>
        /// Lists plannable products for a given location.
        /// </summary>
        /// <param name="reachPlanService">Instance of Reach Plan Service client.</param>
        /// <param name="locationId">Location ID to plan for. To find a valid locaction ID, either
        /// see https://developers.google.com/adwords/api/docs/appendix/geotargeting or call
        /// <see cref="ReachPlanServiceClient.ListPlannableLocations"/>.</param>
        public void ShowPlannableProducts(
            ReachPlanServiceClient reachPlanService, string locationId)
        {
            ListPlannableProductsRequest request = new ListPlannableProductsRequest()
            {
                PlannableLocationId = locationId
            };
            ListPlannableProductsResponse response = reachPlanService.ListPlannableProducts(
                request);

            Console.WriteLine($"Plannable Products for location {locationId}:");
            foreach (ProductMetadata product in response.ProductMetadata)
            {
                Console.WriteLine($"{product.PlannableProductCode}:");
                Console.WriteLine("Age Ranges:");
                foreach (var ageRange in product.PlannableTargeting.AgeRanges)
                {
                    Console.WriteLine($"\t- {ageRange}");
                }
                Console.WriteLine("Genders:");
                foreach (var gender in product.PlannableTargeting.Genders)
                {
                    Console.WriteLine($"\t- {gender.Type}");
                }
                Console.WriteLine("Devices:");
                foreach (var device in product.PlannableTargeting.Devices)
                {
                    Console.WriteLine($"\t- {device.Type}");
                }
            }
        }
        /// <summary>Snippet for GenerateReachForecastAsync</summary>
        public async Task GenerateReachForecastRequestObjectAsync()
        {
            // Snippet: GenerateReachForecastAsync(GenerateReachForecastRequest, CallSettings)
            // Additional: GenerateReachForecastAsync(GenerateReachForecastRequest, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            GenerateReachForecastRequest request = new GenerateReachForecastRequest
            {
                CustomerId       = "",
                CampaignDuration = new CampaignDuration(),
                Targeting        = new Targeting(),
                PlannedProducts  =
                {
                    new PlannedProduct(),
                },
                CookieFrequencyCapSetting = new FrequencyCap(),
                CurrencyCode          = "",
                CookieFrequencyCap    = 0,
                MinEffectiveFrequency = 0,
            };
            // Make the request
            GenerateReachForecastResponse response = await reachPlanServiceClient.GenerateReachForecastAsync(request);

            // End snippet
        }
        /// <summary>
        /// Pulls and prints the reach curve for the given request.
        /// </summary>
        /// <param name="reachPlanService">Instance of Reach Plan Service client.</param>
        /// <param name="request">An already-populated reach curve request.</param>
        public void PullReachCurve(
            ReachPlanServiceClient reachPlanService, GenerateReachForecastRequest request)
        {
            GenerateReachForecastResponse response = reachPlanService.GenerateReachForecast(
                request);

            Console.WriteLine("Reach curve output:");
            Console.WriteLine(
                "Currency,\tCost Micros,\tOn-Target Reach,\tOn-Target Imprs,\tTotal Reach," +
                "\tTotal Imprs,\tProducts");
            foreach (ReachForecast point in response.ReachCurve.ReachForecasts)
            {
                Console.Write($"{request.CurrencyCode},\t");
                Console.Write($"{point.CostMicros},\t");
                Console.Write($"{point.Forecast.OnTargetReach},\t");
                Console.Write($"{point.Forecast.OnTargetImpressions},\t");
                Console.Write($"{point.Forecast.TotalReach},\t");
                Console.Write($"{point.Forecast.TotalImpressions},\t");
                Console.Write($"\"[");
                foreach (ProductAllocation product in point.ForecastedProductAllocations)
                {
                    Console.Write($"(Product: {product.PlannableProductCode}, ");
                    Console.Write($"Budget Micros: {product.BudgetMicros}), ");
                }
                Console.WriteLine($"]\"");
            }
        }
 /// <summary>Snippet for ListPlannableProducts</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void ListPlannableProducts()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     string plannableLocationId = "";
     // Make the request
     ListPlannableProductsResponse response = reachPlanServiceClient.ListPlannableProducts(plannableLocationId);
 }
        /// <summary>Snippet for ListPlannableProductsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task ListPlannableProductsAsync()
        {
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            string plannableLocationId = "";
            // Make the request
            ListPlannableProductsResponse response = await reachPlanServiceClient.ListPlannableProductsAsync(plannableLocationId);
        }
示例#8
0
 /// <summary>Snippet for ListPlannableLocations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void ListPlannableLocationsRequestObject()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     ListPlannableLocationsRequest request = new ListPlannableLocationsRequest {
     };
     // Make the request
     ListPlannableLocationsResponse response = reachPlanServiceClient.ListPlannableLocations(request);
 }
示例#9
0
        /// <summary>Snippet for ListPlannableLocationsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task ListPlannableLocationsRequestObjectAsync()
        {
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListPlannableLocationsRequest request = new ListPlannableLocationsRequest {
            };
            // Make the request
            ListPlannableLocationsResponse response = await reachPlanServiceClient.ListPlannableLocationsAsync(request);
        }
 /// <summary>Snippet for GenerateProductMixIdeas</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GenerateProductMixIdeas()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     string customerId          = "";
     string plannableLocationId = "";
     string currencyCode        = "";
     long   budgetMicros        = 0L;
     // Make the request
     GenerateProductMixIdeasResponse response = reachPlanServiceClient.GenerateProductMixIdeas(customerId, plannableLocationId, currencyCode, budgetMicros);
 }
        /// <summary>Snippet for ListPlannableProductsAsync</summary>
        public async Task ListPlannableProductsAsync()
        {
            // Snippet: ListPlannableProductsAsync(string, CallSettings)
            // Additional: ListPlannableProductsAsync(string, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            string plannableLocationId = "";
            // Make the request
            ListPlannableProductsResponse response = await reachPlanServiceClient.ListPlannableProductsAsync(plannableLocationId);

            // End snippet
        }
示例#12
0
        /// <summary>
        /// Maps friendly names of plannable locations to location IDs usable with
        /// <see cref="ReachPlanServiceClient"/>.
        /// </summary>
        /// <param name="reachPlanService">Instance of Reach Plan Service client.</param>
        public void ShowPlannableLocations(ReachPlanServiceClient reachPlanService)
        {
            ListPlannableLocationsRequest  request  = new ListPlannableLocationsRequest();
            ListPlannableLocationsResponse response = reachPlanService.ListPlannableLocations(
                request);

            Console.WriteLine("Plannable Locations:");
            Console.WriteLine("Name,\tId,\t,ParentCountryId");
            foreach (PlannableLocation location in response.PlannableLocations)
            {
                Console.WriteLine(
                    $"\"{location.Name}\",\t{location.Id},{location.ParentCountryId}");
            }
        }
 /// <summary>Snippet for GenerateReachForecast</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GenerateReachForecast()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     string                       customerId       = "";
     CampaignDuration             campaignDuration = new CampaignDuration();
     IEnumerable <PlannedProduct> plannedProducts  = new PlannedProduct[]
     {
         new PlannedProduct(),
     };
     // Make the request
     GenerateReachForecastResponse response = reachPlanServiceClient.GenerateReachForecast(customerId, campaignDuration, plannedProducts);
 }
 /// <summary>Snippet for ListPlannableProducts</summary>
 public void ListPlannableProductsRequestObject()
 {
     // Snippet: ListPlannableProducts(ListPlannableProductsRequest, CallSettings)
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     ListPlannableProductsRequest request = new ListPlannableProductsRequest
     {
         PlannableLocationId = "",
     };
     // Make the request
     ListPlannableProductsResponse response = reachPlanServiceClient.ListPlannableProducts(request);
     // End snippet
 }
        /// <summary>Snippet for ListPlannableLocationsAsync</summary>
        public async Task ListPlannableLocationsRequestObjectAsync()
        {
            // Snippet: ListPlannableLocationsAsync(ListPlannableLocationsRequest, CallSettings)
            // Additional: ListPlannableLocationsAsync(ListPlannableLocationsRequest, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListPlannableLocationsRequest request = new ListPlannableLocationsRequest {
            };
            // Make the request
            ListPlannableLocationsResponse response = await reachPlanServiceClient.ListPlannableLocationsAsync(request);

            // End snippet
        }
示例#16
0
 /// <summary>Snippet for GenerateProductMixIdeas</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GenerateProductMixIdeasRequestObject()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     GenerateProductMixIdeasRequest request = new GenerateProductMixIdeasRequest
     {
         CustomerId          = "",
         Preferences         = new Preferences(),
         PlannableLocationId = "",
         CurrencyCode        = "",
         BudgetMicros        = 0L,
     };
     // Make the request
     GenerateProductMixIdeasResponse response = reachPlanServiceClient.GenerateProductMixIdeas(request);
 }
        /// <summary>Snippet for GenerateProductMixIdeasAsync</summary>
        public async Task GenerateProductMixIdeasAsync()
        {
            // Snippet: GenerateProductMixIdeasAsync(string, string, string, long, CallSettings)
            // Additional: GenerateProductMixIdeasAsync(string, string, string, long, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId          = "";
            string plannableLocationId = "";
            string currencyCode        = "";
            long   budgetMicros        = 0L;
            // Make the request
            GenerateProductMixIdeasResponse response = await reachPlanServiceClient.GenerateProductMixIdeasAsync(customerId, plannableLocationId, currencyCode, budgetMicros);

            // End snippet
        }
示例#18
0
        /// <summary>
        /// Pulls a forecast for a product mix suggested based on preferences for whether the ad
        /// would have a guaranteed price, play with sound, would be skippable, would include top
        /// content, and a desired ad length.
        /// </summary>
        /// <param name="reachPlanService">Instance of Reach Plan Service client.</param>
        /// <param name="customerId">The customer ID for the reach forecast.</param>
        /// <param name="locationId">Location ID to plan for. To find a valid locaction ID, either
        /// see https://developers.google.com/adwords/api/docs/appendix/geotargeting or call
        /// <see cref="ReachPlanServiceClient.ListPlannableLocations"/>.</param>
        /// <param name="currencyCode">Three-character ISO 4217 currency code.</param>
        /// <param name="budgetMicros">Budget in currency micro-units to plan for.</param>
        public void ForecastSuggestedMix(
            ReachPlanServiceClient reachPlanService,
            string customerId,
            string locationId,
            string currencyCode,
            long budgetMicros)
        {
            // Note: If preferences are too restrictive, then the response will be empty.
            Preferences preferences = new Preferences()
            {
                HasGuaranteedPrice = true,
                StartsWithSound    = true,
                IsSkippable        = false,
                TopContentOnly     = true,
                AdLength           = ReachPlanAdLength.FifteenOrTwentySeconds
            };

            GenerateProductMixIdeasRequest mixRequest = new GenerateProductMixIdeasRequest()
            {
                BudgetMicros        = Convert.ToInt64((double)budgetMicros),
                CurrencyCode        = currencyCode,
                CustomerId          = customerId,
                PlannableLocationId = locationId,
                Preferences         = preferences
            };

            GenerateProductMixIdeasResponse mixResponse =
                reachPlanService.GenerateProductMixIdeas(mixRequest);

            List <PlannedProduct> productMix = new List <PlannedProduct>();

            foreach (ProductAllocation product in mixResponse.ProductAllocation)
            {
                productMix.Add(
                    new PlannedProduct()
                {
                    PlannableProductCode = product.PlannableProductCode,
                    BudgetMicros         = product.BudgetMicros
                });
            }

            GenerateReachForecastRequest curveRequest =
                BuildReachRequest(customerId, productMix, locationId, currencyCode);

            PullReachCurve(reachPlanService, curveRequest);
        }
        /// <summary>Snippet for GenerateReachForecastAsync</summary>
        public async Task GenerateReachForecastAsync()
        {
            // Snippet: GenerateReachForecastAsync(string, CampaignDuration, IEnumerable<PlannedProduct>, CallSettings)
            // Additional: GenerateReachForecastAsync(string, CampaignDuration, IEnumerable<PlannedProduct>, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            string                       customerId       = "";
            CampaignDuration             campaignDuration = new CampaignDuration();
            IEnumerable <PlannedProduct> plannedProducts  = new PlannedProduct[]
            {
                new PlannedProduct(),
            };
            // Make the request
            GenerateReachForecastResponse response = await reachPlanServiceClient.GenerateReachForecastAsync(customerId, campaignDuration, plannedProducts);

            // End snippet
        }
        /// <summary>Snippet for GenerateProductMixIdeasAsync</summary>
        public async Task GenerateProductMixIdeasRequestObjectAsync()
        {
            // Snippet: GenerateProductMixIdeasAsync(GenerateProductMixIdeasRequest, CallSettings)
            // Additional: GenerateProductMixIdeasAsync(GenerateProductMixIdeasRequest, CancellationToken)
            // Create client
            ReachPlanServiceClient reachPlanServiceClient = await ReachPlanServiceClient.CreateAsync();

            // Initialize request argument(s)
            GenerateProductMixIdeasRequest request = new GenerateProductMixIdeasRequest
            {
                CustomerId          = "",
                Preferences         = new Preferences(),
                PlannableLocationId = "",
                CurrencyCode        = "",
                BudgetMicros        = 0L,
            };
            // Make the request
            GenerateProductMixIdeasResponse response = await reachPlanServiceClient.GenerateProductMixIdeasAsync(request);

            // End snippet
        }
示例#21
0
 /// <summary>Snippet for GenerateReachForecast</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GenerateReachForecastRequestObject()
 {
     // Create client
     ReachPlanServiceClient reachPlanServiceClient = ReachPlanServiceClient.Create();
     // Initialize request argument(s)
     GenerateReachForecastRequest request = new GenerateReachForecastRequest
     {
         CustomerId       = "",
         CampaignDuration = new CampaignDuration(),
         Targeting        = new Targeting(),
         PlannedProducts  =
         {
             new PlannedProduct(),
         },
         CookieFrequencyCapSetting = new FrequencyCap(),
         CurrencyCode          = "",
         CookieFrequencyCap    = 0,
         MinEffectiveFrequency = 0,
     };
     // Make the request
     GenerateReachForecastResponse response = reachPlanServiceClient.GenerateReachForecast(request);
 }