/// <summary>
        /// Creates the portfolio bidding strategy.
        /// </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 bidding strategy name.</param>
        /// <param name="bidCeiling">The bid ceiling amount in micros.</param>
        /// <param name="spendTarget">The spend target in micros.</param>
        /// <returns>The bidding strategy resource name.</returns>
        private string CreatePortfolioBiddingStrategy(GoogleAdsClient client,
                                                      long customerId, string name, long bidCeiling, long spendTarget)
        {
            // Get the BiddingStrategyService.
            BiddingStrategyServiceClient biddingStrategyService = client.GetService(
                Services.V1.BiddingStrategyService);

            // Create a portfolio bidding strategy.
            BiddingStrategy biddingStrategy = new BiddingStrategy()
            {
                Name = name,

                TargetSpend = new TargetSpend()
                {
                    // Optionally set additional bidding scheme parameters.
                    CpcBidCeilingMicros = bidCeiling,
                    TargetSpendMicros   = spendTarget
                }
            };

            // Create operation.
            BiddingStrategyOperation biddingOperation = new BiddingStrategyOperation()
            {
                Create = biddingStrategy
            };

            // Create the portfolio bidding strategy.
            MutateBiddingStrategiesResponse biddingResponse =
                biddingStrategyService.MutateBiddingStrategies(
                    customerId.ToString(), new BiddingStrategyOperation[] { biddingOperation });

            return(biddingResponse.Results[0].ResourceName);
        }
Example #2
0
        // [END create_cross_account_strategy]

        // [START list_manager_strategies]
        /// <summary>
        /// Lists all cross-account bidding strategies in a specified manager account.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="managerCustomerId">The manager customer ID.</param>
        private void ListManagerOwnedBiddingStrategies(GoogleAdsClient client,
                                                       long managerCustomerId)
        {
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            // Create a GAQL query that will retrieve all cross-account bidding strategies.
            string query = @"
                SELECT
                  bidding_strategy.id,
                  bidding_strategy.name,
                  bidding_strategy.type,
                  bidding_strategy.currency_code
                FROM bidding_strategy";

            // Issue a streaming search request, then iterate through and print the results.
            googleAdsServiceClient.SearchStream(managerCustomerId.ToString(), query,
                                                delegate(SearchGoogleAdsStreamResponse resp)
            {
                Console.WriteLine("Cross-account bid strategies in manager account " +
                                  $"{managerCustomerId}:");

                foreach (GoogleAdsRow googleAdsRow in resp.Results)
                {
                    BiddingStrategy biddingStrategy = googleAdsRow.BiddingStrategy;

                    Console.WriteLine($"\tID: {biddingStrategy.Id}\n" +
                                      $"\tName: {biddingStrategy.Name}\n" +
                                      "\tStrategy type: " +
                                      $"{Enum.GetName(typeof(BiddingStrategyType), biddingStrategy.Type)}\n" +
                                      $"\tCurrency: {biddingStrategy.CurrencyCode}\n\n");
                }
            }
                                                );
        }
 /// <summary>Snippet for GetBiddingStrategy</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBiddingStrategyResourceNames()
 {
     // Create client
     BiddingStrategyServiceClient biddingStrategyServiceClient = BiddingStrategyServiceClient.Create();
     // Initialize request argument(s)
     BiddingStrategyName resourceName = BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER]", "[BIDDING_STRATEGY]");
     // Make the request
     BiddingStrategy response = biddingStrategyServiceClient.GetBiddingStrategy(resourceName);
 }
Example #4
0
 /// <summary>Snippet for GetBiddingStrategy</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBiddingStrategy()
 {
     // Create client
     BiddingStrategyServiceClient biddingStrategyServiceClient = BiddingStrategyServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/biddingStrategies/[BIDDING_STRATEGY_ID]";
     // Make the request
     BiddingStrategy response = biddingStrategyServiceClient.GetBiddingStrategy(resourceName);
 }
Example #5
0
        /// <summary>Snippet for GetBiddingStrategyAsync</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 GetBiddingStrategyAsync()
        {
            // Create client
            BiddingStrategyServiceClient biddingStrategyServiceClient = await BiddingStrategyServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/biddingStrategies/[BIDDING_STRATEGY]";
            // Make the request
            BiddingStrategy response = await biddingStrategyServiceClient.GetBiddingStrategyAsync(resourceName);
        }
        /// <summary>Snippet for GetBiddingStrategyAsync</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 GetBiddingStrategyResourceNamesAsync()
        {
            // Create client
            BiddingStrategyServiceClient biddingStrategyServiceClient = await BiddingStrategyServiceClient.CreateAsync();

            // Initialize request argument(s)
            BiddingStrategyName resourceName = BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER_ID]", "[BIDDING_STRATEGY_ID]");
            // Make the request
            BiddingStrategy response = await biddingStrategyServiceClient.GetBiddingStrategyAsync(resourceName);
        }
Example #7
0
 /// <summary>Snippet for GetBiddingStrategy</summary>
 public void GetBiddingStrategy()
 {
     // Snippet: GetBiddingStrategy(string, CallSettings)
     // Create client
     BiddingStrategyServiceClient biddingStrategyServiceClient = BiddingStrategyServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/biddingStrategies/[BIDDING_STRATEGY]";
     // Make the request
     BiddingStrategy response = biddingStrategyServiceClient.GetBiddingStrategy(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetBiddingStrategy</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBiddingStrategyRequestObject()
 {
     // Create client
     BiddingStrategyServiceClient biddingStrategyServiceClient = BiddingStrategyServiceClient.Create();
     // Initialize request argument(s)
     GetBiddingStrategyRequest request = new GetBiddingStrategyRequest
     {
         ResourceNameAsBiddingStrategyName = BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER_ID]", "[BIDDING_STRATEGY_ID]"),
     };
     // Make the request
     BiddingStrategy response = biddingStrategyServiceClient.GetBiddingStrategy(request);
 }
Example #9
0
        /// <summary>Snippet for GetBiddingStrategyAsync</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 GetBiddingStrategyRequestObjectAsync()
        {
            // Create client
            BiddingStrategyServiceClient biddingStrategyServiceClient = await BiddingStrategyServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetBiddingStrategyRequest request = new GetBiddingStrategyRequest
            {
                ResourceNameAsBiddingStrategyName = BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER]", "[BIDDING_STRATEGY]"),
            };
            // Make the request
            BiddingStrategy response = await biddingStrategyServiceClient.GetBiddingStrategyAsync(request);
        }
Example #10
0
        /// <summary>Snippet for GetBiddingStrategyAsync</summary>
        public async Task GetBiddingStrategyAsync()
        {
            // Snippet: GetBiddingStrategyAsync(string, CallSettings)
            // Additional: GetBiddingStrategyAsync(string, CancellationToken)
            // Create client
            BiddingStrategyServiceClient biddingStrategyServiceClient = await BiddingStrategyServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/biddingStrategies/[BIDDING_STRATEGY]";
            // Make the request
            BiddingStrategy response = await biddingStrategyServiceClient.GetBiddingStrategyAsync(resourceName);

            // End snippet
        }
Example #11
0
        /// <summary>Snippet for GetBiddingStrategyAsync</summary>
        public async Task GetBiddingStrategyResourceNamesAsync()
        {
            // Snippet: GetBiddingStrategyAsync(BiddingStrategyName, CallSettings)
            // Additional: GetBiddingStrategyAsync(BiddingStrategyName, CancellationToken)
            // Create client
            BiddingStrategyServiceClient biddingStrategyServiceClient = await BiddingStrategyServiceClient.CreateAsync();

            // Initialize request argument(s)
            BiddingStrategyName resourceName = BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER]", "[BIDDING_STRATEGY]");
            // Make the request
            BiddingStrategy response = await biddingStrategyServiceClient.GetBiddingStrategyAsync(resourceName);

            // End snippet
        }
Example #12
0
        public void GetBiddingStrategy2()
        {
            Mock <BiddingStrategyService.BiddingStrategyServiceClient> mockGrpcClient = new Mock <BiddingStrategyService.BiddingStrategyServiceClient>(MockBehavior.Strict);
            GetBiddingStrategyRequest request = new GetBiddingStrategyRequest
            {
                ResourceName = new BiddingStrategyName("[CUSTOMER]", "[BIDDING_STRATEGY]").ToString(),
            };
            BiddingStrategy expectedResponse = new BiddingStrategy
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetBiddingStrategy(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            BiddingStrategyServiceClient client = new BiddingStrategyServiceClientImpl(mockGrpcClient.Object, null);
            BiddingStrategy response            = client.GetBiddingStrategy(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #13
0
        public async Task GetBiddingStrategyAsync2()
        {
            Mock <BiddingStrategyService.BiddingStrategyServiceClient> mockGrpcClient = new Mock <BiddingStrategyService.BiddingStrategyServiceClient>(MockBehavior.Strict);
            GetBiddingStrategyRequest request = new GetBiddingStrategyRequest
            {
                ResourceName = new BiddingStrategyName("[CUSTOMER]", "[BIDDING_STRATEGY]").ToString(),
            };
            BiddingStrategy expectedResponse = new BiddingStrategy
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetBiddingStrategyAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <BiddingStrategy>(Task.FromResult(expectedResponse), null, null, null, null));
            BiddingStrategyServiceClient client = new BiddingStrategyServiceClientImpl(mockGrpcClient.Object, null);
            BiddingStrategy response            = await client.GetBiddingStrategyAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #14
0
        // [START create_cross_account_strategy]
        /// <summary>
        /// Creates a new TargetSpend (Maximize Clicks) cross-account bidding strategy in the
        /// specified manager account.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="managerCustomerId">The manager customer ID.</param>
        /// <returns>The resource name of the newly created bidding strategy.</returns>
        private string CreateBiddingStrategy(GoogleAdsClient client, long managerCustomerId)
        {
            BiddingStrategyServiceClient biddingStrategyServiceClient =
                client.GetService(Services.V10.BiddingStrategyService);

            // Create a portfolio bidding strategy.
            // [START set_currency_code]
            BiddingStrategy portfolioBiddingStrategy = new BiddingStrategy
            {
                Name        = $"Maximize clicks #{ExampleUtilities.GetRandomString()}",
                TargetSpend = new TargetSpend(),
                // Set the currency of the new bidding strategy. If not provided, the bidding
                // strategy uses the manager account's default currency.
                CurrencyCode = "USD"
            };
            // [END set_currency_code]

            // Send a create operation that will create the portfolio bidding strategy.
            MutateBiddingStrategiesResponse mutateBiddingStrategiesResponse =
                biddingStrategyServiceClient.MutateBiddingStrategies(managerCustomerId.ToString(),
                                                                     new[]
            {
                new BiddingStrategyOperation
                {
                    Create = portfolioBiddingStrategy
                }
            });

            // Print and return the resource name of the newly created cross-account bidding
            // strategy.
            string biddingStrategyResourceName =
                mutateBiddingStrategiesResponse.Results.First().ResourceName;

            Console.WriteLine("Created cross-account bidding strategy " +
                              $"'{biddingStrategyResourceName}'.");

            return(biddingStrategyResourceName);
        }