Exemplo n.º 1
0
        // [END setup_remarketing_1]

        /// <summary>
        /// Updates the bid modifier on an ad group criterion.
        /// </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>
        /// <param name="adGroupCriterionResourceName">The resource name of the ad group criterion to update.</param>
        /// <param name="bidModifierValue">The bid modifier value.</param>
        private void ModifyAdGroupBids(
            GoogleAdsClient client,
            long customerId,
            string adGroupCriterionResourceName,
            double bidModifierValue)
        {
            // Get the AdGroupCriterionService client.
            AdGroupCriterionServiceClient adGroupCriterionServiceClient =
                client.GetService(Services.V10.AdGroupCriterionService);

            // Create the ad group criterion with a bid modifier. You may alternatively set the bid
            // for the ad group criterion directly.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion
            {
                ResourceName = adGroupCriterionResourceName,
                BidModifier  = bidModifierValue
            };

            // Create the update operation.
            AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation
            {
                Update     = adGroupCriterion,
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroupCriterion)
            };

            // Update the ad group criterion and print the results.
            MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse =
                adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId.ToString(),
                                                                    new[] { adGroupCriterionOperation });

            Console.WriteLine("Successfully updated the bid for ad group criterion with resource " +
                              $"name '{mutateAdGroupCriteriaResponse.Results.First().ResourceName}'.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes all ad group criteria targeting a user list under a given campaign. This is a
        /// necessary step before targeting a user list at the campaign level.
        /// </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>
        /// <param name="campaignId">The campaign from which to remove the ad group criteria.</param>
        // [START setup_remarketing_3]
        private void RemoveExistingListCriteriaFromAdGroup(GoogleAdsClient client, long customerId,
                                                           long campaignId)
        {
            // Get the AdGroupCriterionService client.
            AdGroupCriterionServiceClient adGroupCriterionServiceClient =
                client.GetService(Services.V10.AdGroupCriterionService);

            // Retrieve all of the ad group criteria under a campaign.
            List <string> adGroupCriteria =
                GetUserListAdGroupCriteria(client, customerId, campaignId);

            // Create a list of remove operations.
            List <AdGroupCriterionOperation> operations = adGroupCriteria.Select(adGroupCriterion =>
                                                                                 new AdGroupCriterionOperation {
                Remove = adGroupCriterion
            }).ToList();

            // Remove the ad group criteria and print the resource names of the removed criteria.
            MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse =
                adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId.ToString(),
                                                                    operations);

            Console.WriteLine($"Removed {mutateAdGroupCriteriaResponse.Results.Count} ad group " +
                              "criteria.");
            foreach (MutateAdGroupCriterionResult result in mutateAdGroupCriteriaResponse.Results)
            {
                Console.WriteLine("Successfully removed ad group criterion with resource name " +
                                  $"'{result.ResourceName}'.");
            }
        }
        /// <summary>
        /// Targets the specified user list to the specified ad group.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupResourceName">The campaign resource name.</param>
        /// <param name="userListId">The user list ID.</param>
        private void AttachUserList(GoogleAdsClient client, long customerId,
                                    string adGroupResourceName, long userListId)
        {
            // Creates the ad group criterion service client.
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService
                                                                              (Services.V4.AdGroupCriterionService);

            string userListResourceName = ResourceNames.UserList(customerId, userListId);

            // Creates the ad group criterion that targets the user list.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup  = adGroupResourceName,
                UserList = new UserListInfo()
                {
                    UserList = userListResourceName
                }
            };

            // Creates the ad group criterion operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            // Adds the ad group criterion.
            MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient
                                                     .MutateAdGroupCriteria(customerId.ToString(), new[] { operation });

            Console.WriteLine("Created ad group criterion with resource name " +
                              $"'{response.Results.First().ResourceName}'.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer account ID.</param>
        /// <param name="adGroupId">Id of the ad group that contains the keyword.</param>
        /// <param name="keywordId">Id of the keyword to be removed.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, long keywordId)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService = client.GetService(
                Services.V0.AdGroupCriterionService);

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation();

            operation.Remove = ResourceNames.AdGroupCriterion(customerId, adGroupId, keywordId);

            try
            {
                // Remove the keyword.
                MutateAdGroupCriteriaResponse retVal =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  new AdGroupCriterionOperation[] { operation });

                // Display the results.
                MutateAdGroupCriterionResult removedKeyword = retVal.Results[0];
                Console.WriteLine($"Keyword with resource name = " +
                                  $"'{removedKeyword.ResourceName}' was removed.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
        public void MutateAdGroupCriteria()
        {
            moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupCriterionOperation(),
                },
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse
            {
                Results =
                {
                    new MutateAdGroupCriterionResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteria(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AdGroupCriterionServiceClient client   = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupCriteriaResponse response = client.MutateAdGroupCriteria(request.CustomerId, request.Operations);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async stt::Task MutateAdGroupCriteriaAsync()
        {
            moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupCriterionOperation(),
                },
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse
            {
                Results =
                {
                    new MutateAdGroupCriterionResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteriaAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateAdGroupCriteriaResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupCriterionServiceClient client = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupCriteriaResponse responseCallSettings = await client.MutateAdGroupCriteriaAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            MutateAdGroupCriteriaResponse responseCancellationToken = await client.MutateAdGroupCriteriaAsync(request.CustomerId, request.Operations, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 7
0
        public void MutateAdGroupCriteriaRequestObject()
        {
            moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupCriterionOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = true,
                ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly,
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse
            {
                Results =
                {
                    new MutateAdGroupCriterionResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteria(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AdGroupCriterionServiceClient client   = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupCriteriaResponse response = client.MutateAdGroupCriteria(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Runs the code example.
        /// </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="adGroupId">The ad group to which new keyword ia added.</param>
        /// <param name="keywordText">The new keyword text.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, string keywordText)
        {
            if (string.IsNullOrEmpty(keywordText))
            {
                keywordText = KEYWORD_TEXT;
            }
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V6.AdGroupCriterionService);

            // Create a keyword.
            AdGroupCriterion criterion = new AdGroupCriterion()
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Status  = AdGroupCriterionStatus.Enabled,
                Keyword = new KeywordInfo()
                {
                    Text      = keywordText,
                    MatchType = KeywordMatchType.Exact
                }
            };

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = criterion,
            };

            try
            {
                // Add the keywords.
                MutateAdGroupCriteriaResponse retVal =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  new AdGroupCriterionOperation[] { operation });

                // Display the results.
                if (retVal.Results.Count > 0)
                {
                    foreach (MutateAdGroupCriterionResult newCriterion in retVal.Results)
                    {
                        Console.WriteLine($"Created keyword with resource ID = " +
                                          "'{newCriterion.ResourceName}'.");
                    }
                }
                else
                {
                    Console.WriteLine("No keywords were added.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="adGroupId">ID of the ad group to which keywords are added.</param>
        /// <param name="keywordText">The keyword text to add to the ad group.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId,
                        string keywordText)
        {
            // Get the AdGroupCriterionServiceClient.
            AdGroupCriterionServiceClient service = client.GetService(
                Services.V4.AdGroupCriterionService);

            // Configures the keyword text and match type settings.
            KeywordInfo keywordInfo = new KeywordInfo()
            {
                Text      = keywordText,
                MatchType = KeywordMatchType.Exact
            };

            // Constructs an ad group criterion using the keyword text info above.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Status  = AdGroupCriterionStatus.Paused,
                Keyword = keywordInfo
            };

            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            try
            {
                try
                {
                    // Try sending a mutate request to add the keyword.
                    MutateAdGroupCriteriaResponse response = service.MutateAdGroupCriteria(
                        customerId.ToString(), new[] { operation });
                    Console.WriteLine($"Added a keyword with resource name " +
                                      $"'{response.Results[0].ResourceName}'.");
                }
                catch (GoogleAdsException ex)
                {
                    PolicyViolationKey[] exemptPolicyViolationKeys =
                        FetchExemptPolicyViolationKeys(ex);

                    // Try sending exemption requests for creating a keyword. However, if your
                    // keyword contains many policy violations, but not all of them are exemptible,
                    // the request will not be sent.
                    RequestExemption(customerId, service, operation, exemptPolicyViolationKeys);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>Add webpage targeting criteria for the DSA ad group.</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="adGroupResourceName">The resource name of the ad group for which targeting
        /// is aded.</param>
        private static void AddWebPageCriteria(GoogleAdsClient client, long customerId,
                                               string adGroupResourceName)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V4.AdGroupCriterionService);

            // Create the criterion.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup      = adGroupResourceName,
                CpcBidMicros = 1_000_000,
                Status       = AdGroupCriterionStatus.Paused,

                // Set the webpage targeting criteria.
                Webpage = new WebpageInfo()
                {
                    CriterionName = "Special Offers",
                    Conditions    =
                    {
                        // Adds the url targeting criteria.
                        new WebpageConditionInfo()
                        {
                            Operand  = WebpageConditionOperand.Url,
                            Argument = "/specialoffers"
                        },
                        // Adds the page title criteria.
                        // The list of webpage targeting conditions are
                        // and-ed together when evaluated for targeting.
                        new WebpageConditionInfo()
                        {
                            Operand  = WebpageConditionOperand.PageTitle,
                            Argument = "Special Offer"
                        }
                    }
                }
            };

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            // Add the webpage criteria.
            MutateAdGroupCriteriaResponse response =
                adGroupCriterionService.MutateAdGroupCriteria(
                    customerId.ToString(), new[] { operation });

            // Displays the results.
            Console.WriteLine($"Added ad group criterion with resource name " +
                              $"'{response.Results[0].ResourceName}'");
        }
    }
Exemplo n.º 11
0
 /// <summary>Snippet for MutateAdGroupCriteria</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupCriteria()
 {
     // Create client
     AdGroupCriterionServiceClient adGroupCriterionServiceClient = AdGroupCriterionServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <AdGroupCriterionOperation> operations = new AdGroupCriterionOperation[]
     {
         new AdGroupCriterionOperation(),
     };
     // Make the request
     MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId, operations);
 }
        // [END add_shopping_product_listing_group_tree]

        /// <summary>
        /// Removes all the ad group criteria that define the existing listing group tree for an
        /// ad group. Returns without an error if all listing group criterion are successfully
        /// removed.
        /// </summary>
        /// <param name="client">The Google Ads API client..</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupId">The ID of the ad group that the new listing group tree will
        /// be removed from.</param>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        private void RemoveListingGroupTree(GoogleAdsClient client, long customerId,
                                            long adGroupId)
        {
            // Get the GoogleAdsService.
            GoogleAdsServiceClient googleAdsService = client.GetService(
                Services.V10.GoogleAdsService);

            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V10.AdGroupCriterionService);

            String searchQuery = "SELECT ad_group_criterion.resource_name FROM " +
                                 "ad_group_criterion WHERE ad_group_criterion.type = LISTING_GROUP AND " +
                                 "ad_group_criterion.listing_group.parent_ad_group_criterion IS NULL " +
                                 $"AND ad_group.id = {adGroupId}";

            // Creates a request that will retrieve all listing groups where the parent ad group
            // criterion is NULL (and hence the root node in the tree) for a given ad group ID.
            SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
            {
                CustomerId = customerId.ToString(),
                PageSize   = PAGE_SIZE,
                Query      = searchQuery
            };

            // Issues the search request.
            GoogleAdsRow googleAdsRow = googleAdsService.Search(request).FirstOrDefault();

            if (googleAdsRow == null)
            {
                return;
            }

            AdGroupCriterion adGroupCriterion = googleAdsRow.AdGroupCriterion;

            Console.WriteLine("Found ad group criterion with the resource name: '{0}'.",
                              adGroupCriterion.ResourceName);

            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Remove = adGroupCriterion.ResourceName
            };

            MutateAdGroupCriteriaResponse response =
                adGroupCriterionService.MutateAdGroupCriteria(
                    customerId.ToString(), new AdGroupCriterionOperation[] { operation });

            Console.WriteLine($"Removed {response.Results.Count}.");
        }
        // [END add_campaign_asset_set]

        // [START add_dsa_target]
        /// <summary>
        /// Adds the DSA target.
        /// </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="adGroupId">The ad group to which DSA label targeting is added.</param>
        /// <param name="dsaPageUrlLabel">The DSA page URL label.</param>
        private static void AddDsaTarget(
            GoogleAdsClient client, long customerId, long adGroupId, string dsaPageUrlLabel)
        {
            AdGroupCriterionServiceClient adGroupCriterionService = client.GetService(
                Services.V10.AdGroupCriterionService);

            string adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId);

            // Creates the webpage condition info that targets an advertiser's webpages
            // based on the custom label specified by the dsaPageUrlLabel (e.g. "discounts").
            WebpageConditionInfo webpageConditionInfo = new WebpageConditionInfo()
            {
                Operand  = WebpageConditionOperand.CustomLabel,
                Argument = dsaPageUrlLabel
            };

            // Creates the webpage info, or criterion for targeting webpages of an
            // advertiser's website.
            WebpageInfo webpageInfo = new WebpageInfo()
            {
                CriterionName = "Test Criterion",
                Conditions    = { webpageConditionInfo }
            };

            // Creates the ad group criterion.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup      = adGroupResourceName,
                Webpage      = webpageInfo,
                CpcBidMicros = 1_500_000
            };

            // Creates the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            // Adds the ad group criterion.
            MutateAdGroupCriteriaResponse response =
                adGroupCriterionService.MutateAdGroupCriteria(
                    customerId.ToString(), new[] { operation });

            string resourceName = response.Results[0].ResourceName;

            // Displays the results.
            Console.WriteLine($"Created ad group criterion with resource " +
                              $"name '{resourceName}'.");
        }
Exemplo n.º 14
0
        // [END add_dynamic_page_feed]

        // [START add_dynamic_page_feed_2]
        private void AddDsaTarget(GoogleAdsClient client, long customerId, long adGroupId,
                                  string dsaPageUrlLabel)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService = client.GetService(
                Services.V10.AdGroupCriterionService);

            // Create the webpage condition info.
            WebpageConditionInfo webpageConditionInfo = new WebpageConditionInfo()
            {
                Operand  = WebpageConditionOperand.CustomLabel,
                Argument = dsaPageUrlLabel,
            };

            // Creates the webpage info.
            WebpageInfo webpageInfo = new WebpageInfo()
            {
                CriterionName = "Test Criterion",
                Conditions    = { webpageConditionInfo }
            };

            // Creates the ad group criterion.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup      = ResourceNames.AdGroup(customerId, adGroupId),
                Webpage      = webpageInfo,
                CpcBidMicros = 1_500_000
            };

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            // Add the ad group criterion.
            MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse =
                adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                              new[] { operation });

            // Display the results.
            foreach (MutateAdGroupCriterionResult result in mutateAdGroupCriteriaResponse.Results)
            {
                Console.WriteLine($"Created ad group criterion with resource name " +
                                  $"'{result.ResourceName}'.");
            }
        }
 /// <summary>Snippet for MutateAdGroupCriteria</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupCriteriaRequestObject()
 {
     // Create client
     AdGroupCriterionServiceClient adGroupCriterionServiceClient = AdGroupCriterionServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupCriterionOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.MutateAdGroupCriteria(request);
 }
        /// <summary>Snippet for MutateAdGroupCriteriaAsync</summary>
        public async Task MutateAdGroupCriteriaAsync()
        {
            // Snippet: MutateAdGroupCriteriaAsync(string, IEnumerable<AdGroupCriterionOperation>, CallSettings)
            // Additional: MutateAdGroupCriteriaAsync(string, IEnumerable<AdGroupCriterionOperation>, CancellationToken)
            // Create client
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = await AdGroupCriterionServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <AdGroupCriterionOperation> operations = new AdGroupCriterionOperation[]
            {
                new AdGroupCriterionOperation(),
            };
            // Make the request
            MutateAdGroupCriteriaResponse response = await adGroupCriterionServiceClient.MutateAdGroupCriteriaAsync(customerId, operations);

            // End snippet
        }
        /// <summary>
        /// Sends exemption requests for creating a keyword.
        /// </summary>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="service">The ad group criterion service.</param>
        /// <param name="operation">The ad group criterion operation to request exemption for.
        /// </param>
        /// <param name="exemptPolicyViolationKeys">The exemptable policy violation keys.</param>
        private static void RequestExemption(
            long customerId, AdGroupCriterionServiceClient service,
            AdGroupCriterionOperation operation, PolicyViolationKey[] exemptPolicyViolationKeys)
        {
            Console.WriteLine("Try adding a keyword again by requesting exemption for its policy "
                              + "violations.");
            PolicyValidationParameter validationParameter = new PolicyValidationParameter();

            validationParameter.ExemptPolicyViolationKeys.AddRange(exemptPolicyViolationKeys);
            operation.ExemptPolicyViolationKeys.AddRange(exemptPolicyViolationKeys);

            MutateAdGroupCriteriaResponse response = service.MutateAdGroupCriteria(
                customerId.ToString(), new[] { operation });

            Console.WriteLine($"Successfully added a keyword with resource name " +
                              $"'{response.Results[0].ResourceName}' by requesting for policy violation " +
                              $"exemption.");
        }
Exemplo n.º 18
0
        public void MutateAdGroupCriteria2()
        {
            Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(MockBehavior.Strict);
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteria(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            AdGroupCriterionServiceClient client   = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupCriteriaResponse response = client.MutateAdGroupCriteria(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 19
0
        public async Task MutateAdGroupCriteriaAsync2()
        {
            Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(MockBehavior.Strict);
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteriaAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateAdGroupCriteriaResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupCriterionServiceClient client   = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupCriteriaResponse response = await client.MutateAdGroupCriteriaAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="adGroupId">The ad group ID of the ad group to which the hotel listing will
        ///     be added.</param>
        /// <param name="percentCpcBidMicroAmount">The CPC bid micro amount to be set on created
        ///     ad group criteria.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId,
                        long percentCpcBidMicroAmount)
        {
            // Get the AdGroupCriterionService client.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V6.AdGroupCriterionService);

            List <AdGroupCriterionOperation> operations = new List <AdGroupCriterionOperation>();

            try
            {
                // Creates the root of the tree as a SUBDIVISION node.
                string rootResourceName = AddRootNode(customerId, adGroupId, operations,
                                                      percentCpcBidMicroAmount);

                // Creates child nodes of level 1, partitioned by the hotel class info.
                string otherHotelResourceName = AddLevel1Nodes(customerId, adGroupId,
                                                               rootResourceName, operations, percentCpcBidMicroAmount);

                // Creates child nodes of level 2, partitioned by the hotel country region info.
                AddLevel2Nodes(customerId, adGroupId, otherHotelResourceName, operations,
                               percentCpcBidMicroAmount);

                // Adds the listing group and prints the resulting node resource names.
                MutateAdGroupCriteriaResponse response =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  operations);

                Console.WriteLine($"Added {response.Results.Count} listing group info entities " +
                                  "with resource names:");
                foreach (MutateAdGroupCriterionResult adGroupCriterionResult in response.Results)
                {
                    Console.WriteLine($"\t{adGroupCriterionResult.ResourceName}");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer Id.</param>
        /// <param name="adGroupId">The Google Ads ad group Id.</param>
        /// <param name="keywordId">The Google Ads keyword Id.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, long keywordId)
        {
            // Get the CampaignCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V4.AdGroupCriterionService);

            // Create the keyword for update.
            AdGroupCriterion keyword = new AdGroupCriterion()
            {
                ResourceName = ResourceNames.AdGroupCriterion(customerId, adGroupId, keywordId),
                CriterionId  = keywordId,
                Status       = AdGroupCriterionStatus.Enabled,
                FinalUrls    = { "https://www.example.com" }
            };

            AdGroupCriterionOperation keywordOperation = new AdGroupCriterionOperation()
            {
                Update     = keyword,
                UpdateMask = FieldMasks.AllSetFieldsOf(keyword)
            };

            try
            {
                // Update the keyword.
                MutateAdGroupCriteriaResponse response =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  new AdGroupCriterionOperation[] { keywordOperation });

                // Display the results.
                foreach (MutateAdGroupCriterionResult criterionResult in response.Results)
                {
                    Console.WriteLine($"Keyword with resource name = " +
                                      $"'{criterionResult.ResourceName}' was updated.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>Snippet for MutateAdGroupCriteriaAsync</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 MutateAdGroupCriteriaRequestObjectAsync()
        {
            // Create client
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = await AdGroupCriterionServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "",
                Operations =
                {
                    new AdGroupCriterionOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = false,
                ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
            };
            // Make the request
            MutateAdGroupCriteriaResponse response = await adGroupCriterionServiceClient.MutateAdGroupCriteriaAsync(request);
        }
 /// <summary>Snippet for MutateAdGroupCriteria</summary>
 public void MutateAdGroupCriteriaRequestObject()
 {
     // Snippet: MutateAdGroupCriteria(MutateAdGroupCriteriaRequest, CallSettings)
     // Create client
     AdGroupCriterionServiceClient adGroupCriterionServiceClient = AdGroupCriterionServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupCriterionOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.MutateAdGroupCriteria(request);
     // End snippet
 }
Exemplo n.º 24
0
        /// <summary>Snippet for MutateAdGroupCriteriaAsync</summary>
        public async Task MutateAdGroupCriteriaRequestObjectAsync()
        {
            // Snippet: MutateAdGroupCriteriaAsync(MutateAdGroupCriteriaRequest, CallSettings)
            // Additional: MutateAdGroupCriteriaAsync(MutateAdGroupCriteriaRequest, CancellationToken)
            // Create client
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = await AdGroupCriterionServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateAdGroupCriteriaRequest request = new MutateAdGroupCriteriaRequest
            {
                CustomerId = "",
                Operations =
                {
                    new AdGroupCriterionOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateAdGroupCriteriaResponse response = await adGroupCriterionServiceClient.MutateAdGroupCriteriaAsync(request);

            // End snippet
        }
Exemplo n.º 25
0
        // [END setup_remarketing]

        /// <summary>
        /// Creates an ad group criterion that targets a user list with an ad group.
        /// </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>
        /// <param name="adGroupId">The ad group on which the user list will be targeted.</param>
        /// <param name="userListResourceName">The resource name of the user list to be
        /// targeted.</param>
        /// <returns>The resource name of the newly created ad group criterion.</returns>
        // [START setup_remarketing_1]
        private string TargetAdsInAdGroupToUserList(
            GoogleAdsClient client, long customerId, long adGroupId, string userListResourceName)
        {
            // Get the AdGroupCriterionService client.
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService
                                                                              (Services.V10.AdGroupCriterionService);

            // Create the ad group criterion targeting members of the user list.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion
            {
                AdGroup  = ResourceNames.AdGroup(customerId, adGroupId),
                UserList = new UserListInfo
                {
                    UserList = userListResourceName
                }
            };

            // Create the operation.
            AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation
            {
                Create = adGroupCriterion
            };

            // Add the ad group criterion, then print and return the new criterion's resource name.
            MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse =
                adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId.ToString(),
                                                                    new[] { adGroupCriterionOperation });

            string adGroupCriterionResourceName =
                mutateAdGroupCriteriaResponse.Results.First().ResourceName;

            Console.WriteLine("Successfully created ad group criterion with resource name " +
                              $"'{adGroupCriterionResourceName}' targeting user list with resource name " +
                              $"'{userListResourceName}' with ad group with ID {adGroupId}.");
            return(adGroupCriterionResourceName);
        }
        public async Task MutateAdGroupCriteriaAsync()
        {
            Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(MockBehavior.Strict);
            MutateAdGroupCriteriaRequest expectedRequest = new MutateAdGroupCriteriaRequest
            {
                CustomerId     = "customerId-1772061412",
                Operations     = { },
                PartialFailure = true,
                ValidateOnly   = false,
            };
            MutateAdGroupCriteriaResponse expectedResponse = new MutateAdGroupCriteriaResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupCriteriaAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateAdGroupCriteriaResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupCriterionServiceClient client = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            string customerId = "customerId-1772061412";
            IEnumerable <AdGroupCriterionOperation> operations = new List <AdGroupCriterionOperation>();
            bool partialFailure = true;
            bool validateOnly   = false;
            MutateAdGroupCriteriaResponse response = await client.MutateAdGroupCriteriaAsync(customerId, operations, partialFailure, validateOnly);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Runs the code example.
        /// </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="adGroupId">The ID of the ad group.</param>
        /// <param name="replaceExistingTree">The boolean to indicate whether to replace the
        /// existing listing group tree on the ad group, if it already exists. The example will
        /// throw a <code>LISTING_GROUP_ALREADY_EXISTS</code> error if listing group tree already
        /// exists and this option is not set to true.</param>
        // [START add_shopping_product_listing_group_tree]
        public void Run(GoogleAdsClient client, long customerId, long adGroupId,
                        bool replaceExistingTree)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V10.AdGroupCriterionService);

            try
            {
                // 1) Optional: Remove the existing listing group tree, if it already exists on the
                // ad group.
                if (replaceExistingTree)
                {
                    RemoveListingGroupTree(client, customerId, adGroupId);
                }
                // Create a list of ad group criterion to add
                List <AdGroupCriterionOperation> operations = new List <AdGroupCriterionOperation>();

                // 2) Construct the listing group tree "root" node.

                // Subdivision node: (Root node)
                AdGroupCriterion adGroupCriterionRoot = CreateListingGroupSubdivisionRoot(
                    customerId, adGroupId, -1L);

                // Get the resource name that will be used for the root node.
                // This resource has not been created yet and will include the temporary ID as
                // part of the criterion ID.
                String adGroupCriterionResourceNameRoot = adGroupCriterionRoot.ResourceName;
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionRoot
                });

                // 3) Construct the listing group unit nodes for NEW, USED and other

                // Biddable Unit node: (Condition NEW node)
                // * Product Condition: NEW
                // * CPC bid: $0.20
                AdGroupCriterion adGroupCriterionConditionNew =
                    CreateListingGroupUnitBiddable(
                        customerId,
                        adGroupId,
                        adGroupCriterionResourceNameRoot,
                        new ListingDimensionInfo()
                {
                    ProductCondition = new ProductConditionInfo()
                    {
                        Condition = ProductCondition.New
                    }
                },
                        200_000L);
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionConditionNew
                });

                // Biddable Unit node: (Condition USED node)
                // * Product Condition: USED
                // * CPC bid: $0.10
                AdGroupCriterion adGroupCriterionConditionUsed =
                    CreateListingGroupUnitBiddable(
                        customerId,
                        adGroupId,
                        adGroupCriterionResourceNameRoot,
                        new ListingDimensionInfo()
                {
                    ProductCondition = new ProductConditionInfo()
                    {
                        Condition = ProductCondition.Used
                    }
                },
                        100_000L
                        );
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionConditionUsed
                });

                // Sub-division node: (Condition "other" node)
                // * Product Condition: (not specified)
                AdGroupCriterion adGroupCriterionConditionOther =
                    CreateListingGroupSubdivision(
                        customerId,
                        adGroupId,
                        -2L,
                        adGroupCriterionResourceNameRoot,
                        new ListingDimensionInfo()
                {
                    // All sibling nodes must have the same dimension type, even if they
                    // don't contain a bid.
                    ProductCondition = new ProductConditionInfo()
                }
                        );
                // Get the resource name that will be used for the condition other node.
                // This resource has not been created yet and will include the temporary ID as
                // part of the criterion ID.
                String adGroupCriterionResourceNameConditionOther =
                    adGroupCriterionConditionOther.ResourceName;
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionConditionOther
                });

                // 4) Construct the listing group unit nodes for CoolBrand, CheapBrand and other

                // Biddable Unit node: (Brand CoolBrand node)
                // * Brand: CoolBrand
                // * CPC bid: $0.90
                AdGroupCriterion adGroupCriterionBrandCoolBrand =
                    CreateListingGroupUnitBiddable(
                        customerId,
                        adGroupId,
                        adGroupCriterionResourceNameConditionOther,
                        new ListingDimensionInfo()
                {
                    ProductBrand = new ProductBrandInfo()
                    {
                        Value = "CoolBrand"
                    }
                },
                        900_000L);
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionBrandCoolBrand
                });

                // Biddable Unit node: (Brand CheapBrand node)
                // * Brand: CheapBrand
                // * CPC bid: $0.01
                AdGroupCriterion adGroupCriterionBrandCheapBrand =
                    CreateListingGroupUnitBiddable(
                        customerId,
                        adGroupId,
                        adGroupCriterionResourceNameConditionOther,
                        new ListingDimensionInfo()
                {
                    ProductBrand = new ProductBrandInfo()
                    {
                        Value = "CheapBrand"
                    }
                },
                        10_000L);

                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionBrandCheapBrand
                });

                // Biddable Unit node: (Brand other node)
                // * Brand: CheapBrand
                // * CPC bid: $0.01
                AdGroupCriterion adGroupCriterionBrandOther =
                    CreateListingGroupUnitBiddable(
                        customerId,
                        adGroupId,
                        adGroupCriterionResourceNameConditionOther,
                        new ListingDimensionInfo()
                {
                    ProductBrand = new ProductBrandInfo()
                },
                        50_000L);
                operations.Add(new AdGroupCriterionOperation()
                {
                    Create = adGroupCriterionBrandOther
                });

                // Issues a mutate request to add the ad group criterion to the ad group.
                MutateAdGroupCriteriaResponse response =
                    adGroupCriterionService.MutateAdGroupCriteria(
                        customerId.ToString(), operations);

                // Display the results.
                foreach (MutateAdGroupCriterionResult mutateAdGroupCriterionResult
                         in response.Results)
                {
                    Console.WriteLine("Added ad group criterion for listing group with resource " +
                                      $"name: '{mutateAdGroupCriterionResult.ResourceName}.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </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="adGroupId">ID of the ad group to which targeting criteria are added.
        /// </param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V10.AdGroupCriterionService);

            string adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId);

            // Creates a positive ad group criterion for gender.
            AdGroupCriterion genderAdGroupCriterion = new AdGroupCriterion()
            {
                AdGroup = adGroupResourceName,
                // Targets male.
                Gender = new GenderInfo()
                {
                    Type = GenderType.Male
                }
            };

            // Creates a negative ad group criterion for age range.
            AdGroupCriterion ageRangeNegativeAdGroupCriterion = new AdGroupCriterion()
            {
                AdGroup = adGroupResourceName,
                // Makes this ad group criterion negative.
                Negative = true,
                // Targets the age range of 18 to 24.
                AgeRange = new AgeRangeInfo()
                {
                    Type = AgeRangeType.AgeRange1824
                }
            };

            // Creates ad group criterion operations for both ad group criteria.
            AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[]
            {
                new AdGroupCriterionOperation()
                {
                    Create = genderAdGroupCriterion
                },
                new AdGroupCriterionOperation()
                {
                    Create = ageRangeNegativeAdGroupCriterion
                }
            };

            try
            {
                // Issues a mutate request to add the ad group criteria and print out some
                // information.
                MutateAdGroupCriteriaResponse response =
                    adGroupCriterionService.MutateAdGroupCriteria(
                        customerId.ToString(), operations);

                Console.WriteLine($"Added {response.Results.Count} demographic ad group" +
                                  $" criteria:");

                foreach (MutateAdGroupCriterionResult result in response.Results)
                {
                    Console.WriteLine(result.ResourceName);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Displays the result from the mutate operation.
        /// </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="adGroupId">The ad group to which keywords are added.</param>
        /// <param name="threadIndex">The thread ID.</param>
        private async Task CreateKeyword(GoogleAdsClient client, int threadIndex, long customerId,
                                         long adGroupId)
        {
            await Task.Run(() =>
            {
                // Get the AdGroupCriterionServiceClient.
                AdGroupCriterionServiceClient adGroupCriterionService =
                    client.GetService(Services.V3.AdGroupCriterionService);

                List <AdGroupCriterionOperation> operations = new List <AdGroupCriterionOperation>();

                for (int i = 0; i < NUM_KEYWORDS; i++)
                {
                    AdGroupCriterion criterion = new AdGroupCriterion()
                    {
                        Keyword = new KeywordInfo()
                        {
                            Text      = $"mars cruise thread {threadIndex} seed {i}",
                            MatchType = KeywordMatchType.Exact
                        },
                        AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                        Status  = AdGroupCriterionStatus.Paused
                    };

                    // Creates the operation.
                    operations.Add(new AdGroupCriterionOperation()
                    {
                        Create = criterion
                    });
                }

                int retryCount        = 0;
                int retrySeconds      = 30;
                const int NUM_RETRIES = 3;

                while (retryCount < NUM_RETRIES)
                {
                    try
                    {
                        // Makes the validateOnly mutate request.
                        MutateAdGroupCriteriaResponse response =
                            adGroupCriterionService.MutateAdGroupCriteria(
                                customerId.ToString(), operations, false, true);
                        Console.WriteLine($"[{threadIndex}] Validated {operations.Count} " +
                                          $"ad group criteria:");
                        break;
                    }
                    catch (GoogleAdsException e)
                    {
                        // Checks if any of the errors are QuotaError.RESOURCE_EXHAUSTED or
                        // QuotaError.RESOURCE_TEMPORARILY_EXHAUSTED.
                        // Note: The code assumes that the developer token is approved for
                        // Standard Access.
                        if (e.Failure != null)
                        {
                            bool isRateExceededError = false;
                            e.Failure.Errors
                            .Where(err =>
                                   err.ErrorCode.QuotaError == QuotaError.ResourceExhausted ||
                                   err.ErrorCode.QuotaError == QuotaError.ResourceTemporarilyExhausted)
                            .ToList()
                            .ForEach(delegate(GoogleAdsError err)
                            {
                                Console.Error.WriteLine($"[{threadIndex}] Received rate " +
                                                        $"exceeded error. Message says, \"{err.Message}\".");
                                isRateExceededError = true;
                            }
                                     );
                            if (isRateExceededError)
                            {
                                Console.Error.WriteLine(
                                    $"[{threadIndex}] Will retry after  {retrySeconds} seconds.");
                                Thread.Sleep(retrySeconds * 1000);
                                retryCount++;
                                // Uses an exponential backoff policy to avoid polling too
                                // aggressively.
                                retrySeconds *= 2;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Failure:");
                            Console.WriteLine($"Message: {e.Message}");
                            Console.WriteLine($"Failure: {e.Failure}");
                            Console.WriteLine($"Request ID: {e.RequestId}");
                            break;
                        }
                    }
                    finally
                    {
                        if (retryCount == NUM_RETRIES)
                        {
                            throw new Exception($"[{ threadIndex }] Could not recover after " +
                                                $"making {retryCount} attempts.");
                        }
                    }
                }
            });
        }