public async stt::Task MutateRequestObjectAsync()
        {
            moq::Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new moq::Mock <GoogleAdsService.GoogleAdsServiceClient>(moq::MockBehavior.Strict);
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "customer_id3b3724cb",
                MutateOperations =
                {
                    new MutateOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = true,
                ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly,
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse
            {
                MutateOperationResponses =
                {
                    new MutateOperationResponse(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateGoogleAdsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            GoogleAdsServiceClient  client = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            MutateGoogleAdsResponse responseCallSettings = await client.MutateAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            MutateGoogleAdsResponse responseCancellationToken = await client.MutateAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void Mutate()
        {
            moq::Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new moq::Mock <GoogleAdsService.GoogleAdsServiceClient>(moq::MockBehavior.Strict);
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "customer_id3b3724cb",
                MutateOperations =
                {
                    new MutateOperation(),
                },
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse
            {
                MutateOperationResponses =
                {
                    new MutateOperationResponse(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.Mutate(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            GoogleAdsServiceClient  client   = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            MutateGoogleAdsResponse response = client.Mutate(request.CustomerId, request.MutateOperations);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #3
0
        public void MutateRequestObject()
        {
            moq::Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new moq::Mock <GoogleAdsService.GoogleAdsServiceClient>(moq::MockBehavior.Strict);
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "customer_id3b3724cb",
                MutateOperations =
                {
                    new MutateOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = true,
                ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly,
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse
            {
                MutateOperationResponses =
                {
                    new MutateOperationResponse(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.Mutate(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            GoogleAdsServiceClient  client   = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            MutateGoogleAdsResponse response = client.Mutate(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #4
0
        // [END add_performance_max_campaign_9]

        /// <summary>
        /// Prints the details of a MutateGoogleAdsResponse. Parses the "response" oneof field name
        /// and uses it to extract the new entity's name and resource name.
        /// </summary>
        /// <param name="response">A MutateGoogleAdsResponse instance.</param>
        private void PrintResponseDetails(MutateGoogleAdsResponse response)
        {
            // Parse the Mutate response to print details about the entities that were created
            // in the request.
            foreach (MutateOperationResponse operationResponse in response.MutateOperationResponses)
            {
                string entityName = operationResponse.ResponseCase.ToString();
                // Trim the substring "Result" from the end of the entity name.
                entityName = entityName.Remove(entityName.Length - 6);

                string resourceName;
                switch (operationResponse.ResponseCase)
                {
                case MutateOperationResponse.ResponseOneofCase.AdGroupResult:
                    resourceName = operationResponse.AdGroupResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.AdGroupAdResult:
                    resourceName = operationResponse.AdGroupAdResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.CampaignResult:
                    resourceName = operationResponse.CampaignResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.CampaignBudgetResult:
                    resourceName = operationResponse.CampaignBudgetResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.CampaignCriterionResult:
                    resourceName = operationResponse.CampaignCriterionResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.SmartCampaignSettingResult:
                    resourceName = operationResponse.SmartCampaignSettingResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.AssetResult:
                    resourceName = operationResponse.AssetResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.AssetGroupResult:
                    resourceName = operationResponse.AssetGroupResult.ResourceName;
                    break;

                case MutateOperationResponse.ResponseOneofCase.AssetGroupAssetResult:
                    resourceName = operationResponse.AssetGroupAssetResult.ResourceName;
                    break;

                default:
                    resourceName = "<not found>";
                    break;
                }

                Console.WriteLine(
                    $"Created a(n) {entityName} with resource name: '{resourceName}'.");
            }
        }
 /// <summary>Snippet for Mutate</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void Mutate()
 {
     // Create client
     GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(customerId, mutateOperations);
 }
Example #6
0
        // [END add_performance_max_campaign_4]

        // [START add_performance_max_campaign_5]
        /// <summary>
        /// Creates multiple text assets and returns the list of resource names.
        /// </summary>
        /// <param name="client">The Google Ads Client.</param>
        /// <param name="customerId">The customer's ID.</param>
        /// <param name="texts">The texts to add.</param>
        /// <returns>A list of asset resource names.</returns>
        private List <string> CreateMultipleTextAssets(
            GoogleAdsClient client,
            long customerId,
            string[] texts)
        {
            // Get the GoogleAdsService.
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest()
            {
                CustomerId = customerId.ToString()
            };

            foreach (string text in texts)
            {
                request.MutateOperations.Add(
                    new MutateOperation()
                {
                    AssetOperation = new AssetOperation()
                    {
                        Create = new Asset()
                        {
                            TextAsset = new TextAsset()
                            {
                                Text = text
                            }
                        }
                    }
                }
                    );
            }

            // Send the operations in a single Mutate request.
            MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);

            List <string> assetResourceNames = new List <string>();

            foreach (MutateOperationResponse operationResponse in response.MutateOperationResponses)
            {
                MutateAssetResult assetResult = operationResponse.AssetResult;
                assetResourceNames.Add(assetResult.ResourceName);
            }

            PrintResponseDetails(response);

            return(assetResourceNames);
        }
        public void Mutate3()
        {
            Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new Mock <GoogleAdsService.GoogleAdsServiceClient>(MockBehavior.Strict);
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "customerId-1772061412",
                MutateOperations = { },
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse();

            mockGrpcClient.Setup(x => x.Mutate(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            GoogleAdsServiceClient  client   = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            MutateGoogleAdsResponse response = client.Mutate(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #8
0
 /// <summary>Snippet for Mutate</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateRequestObject()
 {
     // Create client
     GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
     // Initialize request argument(s)
     MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
     {
         CustomerId       = "",
         MutateOperations =
         {
             new MutateOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);
 }
        public async Task MutateAsync3()
        {
            Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new Mock <GoogleAdsService.GoogleAdsServiceClient>(MockBehavior.Strict);
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "customerId-1772061412",
                MutateOperations = { },
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse();

            mockGrpcClient.Setup(x => x.MutateAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateGoogleAdsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            GoogleAdsServiceClient  client   = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            MutateGoogleAdsResponse response = await client.MutateAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #10
0
        /// <summary>Snippet for MutateAsync</summary>
        public async Task MutateAsync()
        {
            // Snippet: MutateAsync(string, IEnumerable<MutateOperation>, CallSettings)
            // Additional: MutateAsync(string, IEnumerable<MutateOperation>, CancellationToken)
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = await GoogleAdsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            MutateGoogleAdsResponse response = await googleAdsServiceClient.MutateAsync(customerId, mutateOperations);

            // End snippet
        }
        /// <summary>Snippet for MutateAsync</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 MutateRequestObjectAsync()
        {
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = await GoogleAdsServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "",
                MutateOperations =
                {
                    new MutateOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = false,
                ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
            };
            // Make the request
            MutateGoogleAdsResponse response = await googleAdsServiceClient.MutateAsync(request);
        }
Example #12
0
 /// <summary>Snippet for Mutate</summary>
 public void MutateRequestObject()
 {
     // Snippet: Mutate(MutateGoogleAdsRequest, CallSettings)
     // Create client
     GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
     // Initialize request argument(s)
     MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
     {
         CustomerId       = "",
         MutateOperations =
         {
             new MutateOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);
     // End snippet
 }
        // [END add_performance_max_product_listing_group_tree_7]

        /// <summary>
        /// Prints the details of a MutateGoogleAdsResponse. Parses the "response" oneof field name
        /// and uses it to extract the new entity's name and resource name.
        /// </summary>
        /// <param name="request">A MutateGoogleAdsRequest instance.</param>
        /// <param name="response">A MutateGoogleAdsResponse instance.</param>
        private void PrintResponseDetails(MutateGoogleAdsRequest request, MutateGoogleAdsResponse response)
        {
            // Parse the Mutate response to print details about the entities that were created
            // in the request.
            for (int i = 0; i < response.MutateOperationResponses.Count; i++)
            {
                MutateOperation         operationRequest  = request.MutateOperations[i];
                MutateOperationResponse operationResponse = response.MutateOperationResponses[i];

                if (operationResponse.ResponseCase != MutateOperationResponse.ResponseOneofCase.AssetGroupListingGroupFilterResult)
                {
                    string entityName = operationResponse.ResponseCase.ToString();
                    // Trim the substring "Result" from the end of the entity name.
                    entityName = entityName.Remove(entityName.Length - 6);

                    Console.WriteLine($"Unsupported entity type: {entityName}");
                }

                string resourceName = operationResponse.AssetGroupListingGroupFilterResult.ResourceName;
                AssetGroupListingGroupFilterOperation assetOperation = operationRequest.AssetGroupListingGroupFilterOperation;

                switch (assetOperation.OperationCase)
                {
                case AssetGroupListingGroupFilterOperation.OperationOneofCase.Create:
                    Console.WriteLine(
                        $"Created a(n) AssetGroupListingGroupFilter with resource name: '{resourceName}'.");
                    break;

                case AssetGroupListingGroupFilterOperation.OperationOneofCase.Remove:
                    Console.WriteLine(
                        $"Removed a(n) AssetGroupListingGroupFilter with resource name: '{resourceName}'.");
                    break;

                default:
                    Console.WriteLine($"Unsupported operation type: {assetOperation.OperationCase.ToString()}");
                    continue;
                }
            }
        }
        /// <summary>Snippet for MutateAsync</summary>
        public async Task MutateRequestObjectAsync()
        {
            // Snippet: MutateAsync(MutateGoogleAdsRequest, CallSettings)
            // Additional: MutateAsync(MutateGoogleAdsRequest, CancellationToken)
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = await GoogleAdsServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId       = "",
                MutateOperations =
                {
                    new MutateOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateGoogleAdsResponse response = await googleAdsServiceClient.MutateAsync(request);

            // End snippet
        }
        public async Task MutateAsync()
        {
            Mock <GoogleAdsService.GoogleAdsServiceClient> mockGrpcClient = new Mock <GoogleAdsService.GoogleAdsServiceClient>(MockBehavior.Strict);
            MutateGoogleAdsRequest expectedRequest = new MutateGoogleAdsRequest
            {
                CustomerId       = "customerId-1772061412",
                MutateOperations = { },
                PartialFailure   = true,
                ValidateOnly     = false,
            };
            MutateGoogleAdsResponse expectedResponse = new MutateGoogleAdsResponse();

            mockGrpcClient.Setup(x => x.MutateAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateGoogleAdsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            GoogleAdsServiceClient client = new GoogleAdsServiceClientImpl(mockGrpcClient.Object, null);
            string customerId             = "customerId-1772061412";
            IEnumerable <MutateOperation> mutateOperations = new List <MutateOperation>();
            bool partialFailure = true;
            bool validateOnly   = false;
            MutateGoogleAdsResponse response = await client.MutateAsync(customerId, mutateOperations, partialFailure, validateOnly);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #16
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="keywordText">A keyword string used for generating keyword themes.</param>
        /// <param name="freeFormKeywordText">A keyword used to create a free-form keyword theme.
        /// </param>
        /// <param name="businessLocationId">The ID of a Business Profile location.</param>
        /// <param name="businessName">The name of a Business Profile business.</param>
        public void Run(GoogleAdsClient client, long customerId, string keywordText,
                        string freeFormKeywordText, ulong?businessLocationId, string businessName)
        {
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            try
            {
                // [START add_smart_campaign_12]
                // Gets the SmartCampaignSuggestionInfo object which acts as the basis for many
                // of the entities necessary to create a Smart campaign. It will be reused a number
                // of times to retrieve suggestions for keyword themes, budget amount, ad
                //creatives, and campaign criteria.
                SmartCampaignSuggestionInfo suggestionInfo =
                    GetSmartCampaignSuggestionInfo(client, businessLocationId, businessName);

                // Generates a list of keyword themes using the SuggestKeywordThemes method on the
                // SmartCampaignSuggestService. It is strongly recommended that you use this
                // strategy for generating keyword themes.
                List <KeywordThemeConstant> keywordThemeConstants =
                    GetKeywordThemeSuggestions(client, customerId, suggestionInfo);

                // Optionally retrieves auto-complete suggestions for the given keyword text and
                // adds them to the list of keyWordThemeConstants.
                if (keywordText != null)
                {
                    keywordThemeConstants.AddRange(GetKeywordTextAutoCompletions(
                                                       client, keywordText));
                }

                // Converts the KeywordThemeConstants to KeywordThemeInfos.
                List <KeywordThemeInfo> keywordThemeInfos = keywordThemeConstants.Select(
                    constant =>
                    new KeywordThemeInfo {
                    KeywordThemeConstant = constant.ResourceName
                })
                                                            .ToList();

                // Optionally includes any freeform keywords verbatim.
                if (freeFormKeywordText != null)
                {
                    keywordThemeInfos.Add(new KeywordThemeInfo()
                    {
                        FreeFormKeywordTheme = freeFormKeywordText
                    });
                }

                // Includes the keyword suggestions in the overall SuggestionInfo object.
                // [START add_smart_campaign_13]
                suggestionInfo.KeywordThemes.Add(keywordThemeInfos);
                // [END add_smart_campaign_13]
                // [END add_smart_campaign_12]

                SmartCampaignAdInfo adSuggestions = GetAdSuggestions(client, customerId,
                                                                     suggestionInfo);

                long suggestedBudgetAmount = GetBudgetSuggestion(client, customerId,
                                                                 suggestionInfo);

                // [START add_smart_campaign_7]
                // The below methods create and return MutateOperations that we later provide to
                // the GoogleAdsService.Mutate method in order to create the entities in a single
                // request. Since the entities for a Smart campaign are closely tied to one-another
                // it's considered a best practice to create them in a single Mutate request; the
                // entities will either all complete successfully or fail entirely, leaving no
                // orphaned entities. See:
                // https://developers.google.com/google-ads/api/docs/mutating/overview
                MutateOperation campaignBudgetOperation =
                    CreateCampaignBudgetOperation(customerId, suggestedBudgetAmount);
                MutateOperation smartCampaignOperation =
                    CreateSmartCampaignOperation(customerId);
                MutateOperation smartCampaignSettingOperation =
                    CreateSmartCampaignSettingOperation(customerId, businessLocationId,
                                                        businessName);
                IEnumerable <MutateOperation> campaignCriterionOperations =
                    CreateCampaignCriterionOperations(customerId, keywordThemeInfos,
                                                      suggestionInfo);
                MutateOperation adGroupOperation   = CreateAdGroupOperation(customerId);
                MutateOperation adGroupAdOperation = CreateAdGroupAdOperation(customerId,
                                                                              adSuggestions);

                // Send the operations in a single mutate request.
                MutateGoogleAdsRequest mutateGoogleAdsRequest = new MutateGoogleAdsRequest
                {
                    CustomerId = customerId.ToString()
                };
                // It's important to create these entities in this order because they depend on
                // each other, for example the SmartCampaignSetting and ad group depend on the
                // campaign, and the ad group ad depends on the ad group.
                mutateGoogleAdsRequest.MutateOperations.Add(campaignBudgetOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(smartCampaignOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(smartCampaignSettingOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(campaignCriterionOperations);
                mutateGoogleAdsRequest.MutateOperations.Add(adGroupOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(adGroupAdOperation);

                MutateGoogleAdsResponse response =
                    googleAdsServiceClient.Mutate(mutateGoogleAdsRequest);

                PrintResponseDetails(response);
                // [END add_smart_campaign_7]
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Example #17
0
        // [START add_performance_max_campaign_1]
        /// <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="audienceId">The optional audience ID.</param>
        public void Run(GoogleAdsClient client, long customerId, long?audienceId)
        {
            try
            {
                // [START add_performance_max_campaign_1]
                GoogleAdsServiceClient googleAdsServiceClient =
                    client.GetService(Services.V10.GoogleAdsService);

                // Performance Max campaigns require that repeated assets such as headlines and
                // descriptions be created before the campaign.
                //
                // For the list of required assets for a Performance Max campaign, see
                // https://developers.google.com/google-ads/api/docs/performance-max/assets
                //
                // Create the headlines.
                List <string> headlineAssetResourceNames = CreateMultipleTextAssets(
                    client,
                    customerId,
                    new[] {
                    "Travel",
                    "Travel Reviews",
                    "Book travel"
                }
                    );

                // Create the descriptions.
                List <string> descriptionAssetResourceNames = CreateMultipleTextAssets(
                    client,
                    customerId,
                    new[] {
                    "Take to the air!",
                    "Fly to the sky!"
                }
                    );

                string tempResourceNameCampaignBudget = ResourceNames.CampaignBudget(
                    customerId,
                    TEMPORARY_ID_BUDGET
                    );

                // The below methods create and return MutateOperations that we later provide to
                // the GoogleAdsService.Mutate method in order to create the entities in a single
                // request. Since the entities for a Performance Max campaign are closely tied to
                // one-another, it is considered a best practice to create them in a single Mutate
                // request so they all complete successfully or fail entirely, leaving no
                // orphaned entities.
                //
                // See: https://developers.google.com/google-ads/api/docs/mutating/overview
                MutateOperation campaignBudgetOperation = CreateCampaignBudgetOperation(
                    tempResourceNameCampaignBudget
                    );

                string tempResourceNameCampaign = ResourceNames.Campaign(
                    customerId,
                    TEMPORARY_ID_CAMPAIGN
                    );

                MutateOperation performanceMaxCampaignOperation =
                    CreatePerformanceMaxCampaignOperation(
                        tempResourceNameCampaign,
                        tempResourceNameCampaignBudget
                        );

                List <MutateOperation> campaignCriterionOperations =
                    CreateCampaignCriterionOperations(tempResourceNameCampaign);

                List <MutateOperation> assetGroupOperations =
                    CreateAssetGroupOperations(
                        tempResourceNameCampaign,
                        ResourceNames.AssetGroup(customerId, TEMPORARY_ID_ASSET_GROUP),
                        headlineAssetResourceNames,
                        descriptionAssetResourceNames,
                        new AssetGroupAssetTemporaryResourceNameGenerator(
                            customerId,
                            TEMPORARY_ID_ASSET_GROUP
                            ),
                        client.Config
                        );

                List <MutateOperation> assetGroupSignalOperations =
                    CreateAssetGroupSignalOperations(
                        customerId,
                        ResourceNames.AssetGroup(customerId, TEMPORARY_ID_ASSET_GROUP),
                        audienceId
                        );

                MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
                {
                    CustomerId = customerId.ToString()
                };

                // It's important to create these entities in this order because they depend on
                // each other.
                //
                // Additionally, we take several lists of operations and flatten them into one
                // large list.
                request.MutateOperations.Add(campaignBudgetOperation);
                request.MutateOperations.Add(performanceMaxCampaignOperation);
                request.MutateOperations.AddRange(campaignCriterionOperations);
                request.MutateOperations.AddRange(assetGroupOperations);
                request.MutateOperations.AddRange(assetGroupSignalOperations);

                MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);

                PrintResponseDetails(response);
                // [END add_performance_max_campaign_1]
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        // [START add_performance_max_product_listing_group_tree]
        /// <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="assetGroupId">The asset group id for the Performance Max campaign.</param>
        /// <param name="replaceExistingTree">Option to remove existing product tree
        /// from the passed in asset group.</param>
        public void Run(
            GoogleAdsClient client,
            long customerId,
            long assetGroupId,
            bool replaceExistingTree)
        {
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            string assetGroupResourceName = ResourceNames.AssetGroup(customerId, assetGroupId);

            // We use a factory to create all the MutateOperations that manipulate a specific
            // AssetGroup for a specific customer. The operations returned by the factory's methods
            // are used to optionally remove all AssetGroupListingGroupFilters from the tree, and
            // then to construct a new tree of filters. These filters can have a parent-child
            // relationship, and also include a special root that includes all children.
            //
            // When creating these filters, we use temporary IDs to create the hierarchy between
            // the root listing group filter, and the subdivisions and leave nodes beneath that.
            //
            // The factory specific to a customerId and assetGroupId is created below.
            AssetGroupListingGroupFilterCreateOperationFactory createOperationFactory =
                new AssetGroupListingGroupFilterCreateOperationFactory(
                    customerId,
                    assetGroupId,
                    TEMPORARY_ID_LISTING_GROUP_ROOT
                    );

            MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
            {
                CustomerId = customerId.ToString()
            };

            if (replaceExistingTree)
            {
                List <AssetGroupListingGroupFilter> existingListingGroupFilters =
                    GetAllExistingListingGroupFilterAssetsInAssetGroup(
                        client,
                        customerId,
                        assetGroupResourceName
                        );

                if (existingListingGroupFilters.Count > 0)
                {
                    // A special factory object that ensures the creation of remove operations in the
                    // correct order (child listing group filters must be removed before their parents).
                    AssetGroupListingGroupFilterRemoveOperationFactory removeOperationFactory =
                        new AssetGroupListingGroupFilterRemoveOperationFactory(
                            existingListingGroupFilters
                            );

                    request.MutateOperations.AddRange(removeOperationFactory.RemoveAll());
                }
            }

            request.MutateOperations.Add(createOperationFactory.CreateRoot());

            request.MutateOperations.Add(
                createOperationFactory.CreateUnit(
                    TEMPORARY_ID_LISTING_GROUP_ROOT,
                    createOperationFactory.NextId(),
                    new ListingGroupFilterDimension()
            {
                ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition()
                {
                    Condition = ListingGroupFilterProductCondition.New
                }
            }
                    )
                );

            request.MutateOperations.Add(
                createOperationFactory.CreateUnit(
                    TEMPORARY_ID_LISTING_GROUP_ROOT,
                    createOperationFactory.NextId(),
                    new ListingGroupFilterDimension()
            {
                ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition()
                {
                    Condition = ListingGroupFilterProductCondition.Used
                }
            }
                    )
                );

            // We save this ID because create child nodes underneath it.
            long subdivisionIdConditionOther = createOperationFactory.NextId();

            request.MutateOperations.Add(
                // We're calling CreateSubdivision because this listing group will have children.
                createOperationFactory.CreateSubdivision(
                    TEMPORARY_ID_LISTING_GROUP_ROOT,
                    subdivisionIdConditionOther,
                    new ListingGroupFilterDimension()
            {
                // All sibling nodes must have the same dimension type. We use an empty
                // ProductCondition to indicate that this is an "Other" partition.
                ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition()
            }
                    )
                );

            request.MutateOperations.Add(
                createOperationFactory.CreateUnit(
                    subdivisionIdConditionOther,
                    createOperationFactory.NextId(),
                    new ListingGroupFilterDimension()
            {
                ProductBrand = new ProductBrand()
                {
                    Value = "CoolBrand"
                }
            }
                    )
                );

            request.MutateOperations.Add(
                createOperationFactory.CreateUnit(
                    subdivisionIdConditionOther,
                    createOperationFactory.NextId(),
                    new ListingGroupFilterDimension()
            {
                ProductBrand = new ProductBrand()
                {
                    Value = "CheapBrand"
                }
            }
                    )
                );

            request.MutateOperations.Add(
                createOperationFactory.CreateUnit(
                    subdivisionIdConditionOther,
                    createOperationFactory.NextId(),
                    new ListingGroupFilterDimension()
            {
                ProductBrand = new ProductBrand()
            }
                    )
                );

            MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);

            PrintResponseDetails(request, response);
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="campaignId">ID of the campaign from which sitelinks will be removed.
        /// </param>
        // [START remove_entire_sitelink_campaign_extension_setting]
        public void Run(GoogleAdsClient client, long customerId, long campaignId)
        {
            // Get the GoogleAdsService client.
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            List <MutateOperation> mutateOperations = new List <MutateOperation>();

            try
            {
                // Create a mutate operation the contains the campaign extension setting operation
                // to remove the specified sitelink campaign extension setting.
                mutateOperations.Add(
                    CreateSitelinkCampaignExtensionSettingMutateOperation(customerId, campaignId));

                // Get all sitelink extension feed items of the specified campaign.
                List <string> extensionFeedItemResourceNames =
                    GetAllSitelinkExtensionFeedItems(googleAdsServiceClient, customerId,
                                                     campaignId);

                // Create mutate operations, each of which contains an extension feed item
                // operation to remove the specified extension feed items.
                mutateOperations.AddRange(CreateExtensionFeedItemMutateOperations(
                                              extensionFeedItemResourceNames));

                // Issue a mutate request to remove the campaign extension setting and its
                // extension feed items.
                MutateGoogleAdsResponse mutateGoogleAdsResponse = googleAdsServiceClient.Mutate(
                    customerId
                    .ToString(), mutateOperations);
                RepeatedField <MutateOperationResponse> mutateOpResponses =
                    mutateGoogleAdsResponse.MutateOperationResponses;

                // Print the information on the removed campaign extension setting and its
                // extension feed items.
                // Each mutate operation response is returned in the same order as we passed its
                // corresponding operation. Therefore, the first belongs to the campaign setting
                // operation, and the rest belong to the extension feed item operations.
                Console.WriteLine("Removed a campaign extension setting with resource name: " +
                                  $"'{mutateOpResponses.First().CampaignExtensionSettingResult.ResourceName}'.");
                foreach (MutateOperationResponse response in mutateOpResponses.Skip(1))
                {
                    Console.WriteLine("Removed an extension feed item with resource name: " +
                                      $"'{response.ExtensionFeedItemResult.ResourceName}'.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Argument Exception:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }