Example #1
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 conversion action is
        /// added.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the CustomAudienceService client.
            CustomAudienceServiceClient customAudienceServiceClient =
                client.GetService(Services.V10.CustomAudienceService);

            // Create a custom audience.
            CustomAudience customAudience = new CustomAudience
            {
                Name        = $"Example CustomAudience #{ExampleUtilities.GetRandomString()}",
                Description = "Custom audiences who have searched specific terms on Google Search",
                // Match customers by what they searched on Google Search.
                // Note: "INTEREST" OR "PURCHASE_INTENT" is not allowed for the type field of newly
                // created custom audience. Use "AUTO" instead of these 2 options when creating a
                // new custom audience.
                Type   = CustomAudienceType.Search,
                Status = CustomAudienceStatus.Enabled,
            };

            // Add custom audience members to the custom audience. Customers that meet any of the
            // membership conditions will be reached.
            // Keywords or keyword phrases, which describe the customers' interests or search terms.
            customAudience.Members.Add(CreateCustomAudienceMember(CustomAudienceMemberType.Keyword,
                                                                  "mars cruise"));
            customAudience.Members.Add(CreateCustomAudienceMember(CustomAudienceMemberType.Keyword,
                                                                  "jupiter cruise"));
            // Website URLs that your customers might visit.
            customAudience.Members.Add(CreateCustomAudienceMember(CustomAudienceMemberType.Url,
                                                                  "http://www.example.com/locations/mars"));
            customAudience.Members.Add(CreateCustomAudienceMember(CustomAudienceMemberType.Url,
                                                                  "http://www.example.com/locations/jupiter"));
            // Package names of Android apps which customers might install.
            customAudience.Members.Add(CreateCustomAudienceMember(CustomAudienceMemberType.App,
                                                                  "com.google.android.apps.adwords"));

            // Create a custom audience operation.
            CustomAudienceOperation customAudienceOperation = new CustomAudienceOperation
            {
                Create = customAudience
            };

            try
            {
                // Add the custom audience and display the results.
                MutateCustomAudiencesResponse customAudiencesResponse = customAudienceServiceClient
                                                                        .MutateCustomAudiences(customerId.ToString(), new[] { customAudienceOperation });

                Console.WriteLine("New custom audience added with resource name: " +
                                  $"'{customAudiencesResponse.Results.First().ResourceName}'.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Example #2
0
 /// <summary>Snippet for MutateCustomAudiences</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCustomAudiences()
 {
     // Create client
     CustomAudienceServiceClient customAudienceServiceClient = CustomAudienceServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CustomAudienceOperation> operations = new CustomAudienceOperation[]
     {
         new CustomAudienceOperation(),
     };
     // Make the request
     MutateCustomAudiencesResponse response = customAudienceServiceClient.MutateCustomAudiences(customerId, operations);
 }
Example #3
0
        /// <summary>Snippet for MutateCustomAudiencesAsync</summary>
        public async Task MutateCustomAudiencesAsync()
        {
            // Snippet: MutateCustomAudiencesAsync(string, IEnumerable<CustomAudienceOperation>, CallSettings)
            // Additional: MutateCustomAudiencesAsync(string, IEnumerable<CustomAudienceOperation>, CancellationToken)
            // Create client
            CustomAudienceServiceClient customAudienceServiceClient = await CustomAudienceServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <CustomAudienceOperation> operations = new CustomAudienceOperation[]
            {
                new CustomAudienceOperation(),
            };
            // Make the request
            MutateCustomAudiencesResponse response = await customAudienceServiceClient.MutateCustomAudiencesAsync(customerId, operations);

            // End snippet
        }