/// <summary>
        /// Adds the hotel 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="campaignResourceName">The resource name of campaign that a new ad group
        /// will belong to.</param>
        /// <returns>The resource name of the newly created ad group.</returns>
        private static string AddHotelAdGroup(GoogleAdsClient client, long customerId,
                                              string campaignResourceName)
        {
            // Get the AdGroupService.
            AdGroupServiceClient service = client.GetService(Services.V4.AdGroupService);

            // Create an ad group.
            AdGroup adGroup = new AdGroup()
            {
                Name = "Earth to Mars Cruise #" + ExampleUtilities.GetRandomString(),

                // Sets the campaign.
                Campaign = campaignResourceName,

                // Optional: Sets the ad group type to HOTEL_ADS.
                // This cannot be set to other types.
                Type = AdGroupType.HotelAds,

                CpcBidMicros = 10000000,
                Status       = AdGroupStatus.Enabled
            };

            // Create an ad group operation.
            AdGroupOperation adGroupOperation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Issue a mutate request to add an ad group.
            MutateAdGroupsResponse response = service.MutateAdGroups(customerId.ToString(),
                                                                     new AdGroupOperation[] { adGroupOperation });

            return(response.Results[0].ResourceName);
        }
        /// <summary>Adds an 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="campaignResourceName">The campaign resource name.</param>
        /// <returns>The ad group resource name.</returns>
        private static string AddAdGroup(GoogleAdsClient client, long customerId,
                                         string campaignResourceName)
        {
            // Get the AdGroupService.
            AdGroupServiceClient adGroupService = client.GetService(Services.V4.AdGroupService);

            // Create the ad group.
            AdGroup adGroup = new AdGroup()
            {
                Name                = "Earth to Mars Cruises #" + ExampleUtilities.GetRandomString(),
                Campaign            = campaignResourceName,
                Type                = AdGroupType.SearchDynamicAds,
                Status              = AdGroupStatus.Paused,
                TrackingUrlTemplate = "http://tracker.examples.com/traveltracker/{escapedlpurl}",
                CpcBidMicros        = 50_000
            };

            // Create the operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Add the ad group.
            MutateAdGroupsResponse response =
                adGroupService.MutateAdGroups(customerId.ToString(),
                                              new AdGroupOperation[] { operation });

            // Display the results.
            string adGroupResourceName = response.Results[0].ResourceName;

            Console.WriteLine($"Added ad group with resource name '{adGroupResourceName}'.");

            return(adGroupResourceName);
        }
Example #3
0
        /// <summary>
        /// Creates an ad group for the remarketing campaign.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="campaignResourceName">The campaign resource name.</param>
        /// <returns>The string resource name for the newly created ad group.</returns>
        private string CreateAdGroup(GoogleAdsClient client, long customerId,
                                     string campaignResourceName)
        {
            // Creates the ad group service client.
            AdGroupServiceClient adGroupServiceClient =
                client.GetService(Services.V6.AdGroupService);

            // Creates the ad group.
            AdGroup adGroup = new AdGroup()
            {
                Name     = "Dynamic remarketing ad group",
                Campaign = campaignResourceName,
                Status   = AdGroupStatus.Enabled
            };

            // Creates the ad group operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Adds the ad group.
            MutateAdGroupsResponse response = adGroupServiceClient.MutateAdGroups(
                customerId.ToString(), new[] { operation });

            string adGroupResourceName = response.Results.First().ResourceName;

            Console.WriteLine($"Created ad group with resource name '{adGroupResourceName}'.");
            return(adGroupResourceName);
        }
        // [END add_shopping_product_ad_2]

        /// <summary>
        /// Creates a new product shopping ad group in the specified campaign.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="campaignResourceName">Resource name of the shopping campaign that the
        /// new ad group will belong to.</param>
        /// <returns>Resource name of the newly created ad group.</returns>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        // [START add_shopping_product_ad_1]
        private string AddProductShoppingAdGroup(GoogleAdsClient client, long customerId,
                                                 string campaignResourceName)
        {
            // Get the AdGroupService.
            AdGroupServiceClient adGroupService = client.GetService(Services.V10.AdGroupService);

            // Creates an ad group.
            AdGroup adGroup = new AdGroup()
            {
                Name     = "Earth to Mars Cruises #" + ExampleUtilities.GetRandomString(),
                Campaign = campaignResourceName,
                // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible
                // for ad groups that contain shopping product ads.
                Type         = AdGroupType.ShoppingProductAds,
                CpcBidMicros = 1_000_000L,
                Status       = AdGroupStatus.Enabled
            };

            // Creates an ad group operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Issues a mutate request to add an ad group.
            MutateAdGroupResult mutateAdGroupResult =
                adGroupService
                .MutateAdGroups(customerId.ToString(), new AdGroupOperation[] { operation })
                .Results[0];

            Console.WriteLine("Added a product shopping ad group with resource name: '{0}'.",
                              mutateAdGroupResult.ResourceName);
            return(mutateAdGroupResult.ResourceName);
        }
Example #5
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">ID of the ad group to remove.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupService.
            AdGroupServiceClient service = client.GetService(Services.V10.AdGroupService);

            // Construct an operation that will remove the ad group with the specified
            // resource name.
            AdGroupOperation operation = new AdGroupOperation
            {
                Remove = ResourceNames.AdGroup(customerId, adGroupId)
            };

            try
            {
                // Send the operation in a mutate request.
                MutateAdGroupsResponse response = service.MutateAdGroups(customerId.ToString(),
                                                                         new AdGroupOperation[] { operation });

                // Display the result.
                foreach (MutateAdGroupResult result in response.Results)
                {
                    Console.WriteLine($"Removed ad group with resourceName: " +
                                      $"{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;
            }
        }
Example #6
0
        /// <summary>
        /// Creates an ad group for a given campaign
        /// </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="campaignResourceName">Resource name of the campaign to add the ad group
        /// to.</param>
        /// <returns>The resource name of the newly created ad group.</returns>
        private string CreateAdGroup(GoogleAdsClient client, long customerId,
                                     string campaignResourceName)
        {
            // Get the AdGroupService.
            AdGroupServiceClient adGroupService = client.GetService(Services.V4.AdGroupService);

            // Creates an ad group.
            // Note that the ad group type must not be set.
            // Since the advertising_channel_sub_type is APP_CAMPAIGN,
            //   1. you cannot override bid settings at the ad group level.
            //   2. you cannot add ad group criteria.
            AdGroup adGroup = new AdGroup()
            {
                Name     = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
                Status   = AdGroupStatus.Enabled,
                Campaign = campaignResourceName
            };

            // Creates an ad group operation.
            // Create the operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Submits the ad group operation to add the ad group and prints the results.
            MutateAdGroupsResponse response =
                adGroupService.MutateAdGroups(customerId.ToString(), new[] { operation });

            // Prints and returns the ad group resource name.
            string adGroupResourceName = response.Results[0].ResourceName;

            Console.WriteLine($"Created an ad group with resource name '{adGroupResourceName}'.");
            return(adGroupResourceName);
        }
Example #7
0
        /// <summary>
        /// Creates the 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="campaignResourceName">The campaign resource name.</param>
        /// <returns>The resource name of the newly created ad group.</returns>
        private string CreateAdGroup(GoogleAdsClient client, long customerId,
                                     string campaignResourceName)
        {
            // Get the AdGroupService.
            AdGroupServiceClient adGroupService = client.GetService(Services.V3.AdGroupService);

            // Create the ad group.
            AdGroup adGroup = new AdGroup()
            {
                Name     = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
                Status   = AdGroupStatusEnum.Types.AdGroupStatus.Enabled,
                Campaign = campaignResourceName,
            };

            // Create the operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Create = adGroup
            };

            // Create the ad groups.
            MutateAdGroupsResponse response = adGroupService.MutateAdGroups(
                customerId.ToString(), new[] { operation });

            string adGroupResourceName = response.Results.First().ResourceName;

            // Print out some information about the added ad group.
            Console.WriteLine($"Added ad group with resource name = '{adGroupResourceName}'.");

            return(adGroupResourceName);
        }
        /// <summary>
        /// Updates the given TargetingSetting of an ad group.
        /// </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 for which to update the audience targeting
        ///     restriction.</param>
        /// <param name="targetingSetting">The updated targeting setting.</param>
        // [START update_audience_target_restriction_2]
        private void UpdateTargetingSetting(GoogleAdsClient client, long customerId, long
                                            adGroupId, TargetingSetting targetingSetting)
        {
            // Get the AdGroupService client.
            AdGroupServiceClient adGroupServiceClient =
                client.GetService(Services.V10.AdGroupService);

            // Create an ad group object with the updated targeting setting.
            AdGroup adGroup = new AdGroup
            {
                ResourceName     = ResourceNames.AdGroup(customerId, adGroupId),
                TargetingSetting = targetingSetting
            };

            // Construct an operation that will update the ad group, using the FieldMasks utility
            // to derive the update mask. This mask tells the Google Ads API which attributes of the
            // ad group you want to change.
            AdGroupOperation operation = new AdGroupOperation
            {
                Update     = adGroup,
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroup)
            };

            // Send the operation in a mutate request.
            MutateAdGroupsResponse response =
                adGroupServiceClient.MutateAdGroups(customerId.ToString(), new[] { operation });

            // Print the resource name of the updated object.
            Console.WriteLine("Updated targeting setting of ad group with resource name " +
                              $"'{response.Results.First().ResourceName}'; set the AUDIENCE target restriction " +
                              "to 'Observation'.");
        }
        /// <summary>
        /// Attempts to create 3 ad groups with partial failure enabled. One of the ad groups
        /// will succeed, while the other will fail.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">ID of the campaign to which ad groups are added.</param>
        /// <returns>The mutate response from the Google Ads server.</returns>
        private static MutateAdGroupsResponse CreateAdGroups(GoogleAdsClient client,
                                                             long customerId, long campaignId)
        {
            // Get the AdGroupServiceClient.
            AdGroupServiceClient adGroupService = client.GetService(Services.V5.AdGroupService);

            string validAdGroupName = "Valid AdGroup: " + ExampleUtilities.GetRandomString();

            AdGroupOperation[] operations = new AdGroupOperation[]
            {
                // This operation will be successful, assuming the campaign specified in
                // campaignId parameter is correct.
                new AdGroupOperation()
                {
                    Create = new AdGroup()
                    {
                        Campaign = ResourceNames.Campaign(customerId, campaignId),
                        Name     = validAdGroupName
                    }
                },
                // This operation will fail since we are using campaign ID = 0, which results
                // in an invalid resource name.
                new AdGroupOperation()
                {
                    Create = new AdGroup()
                    {
                        Campaign = ResourceNames.Campaign(customerId, 0),
                        Name     = "Broken AdGroup: " + ExampleUtilities.GetRandomString()
                    },
                },
                // This operation will fail since the ad group is using the same name as the ad
                // group from the first operation. Duplicate ad group names are not allowed.
                new AdGroupOperation()
                {
                    Create = new AdGroup()
                    {
                        Campaign = ResourceNames.Campaign(customerId, campaignId),
                        Name     = validAdGroupName
                    }
                }
            };

            // Add the ad groups.
            MutateAdGroupsResponse response =
                adGroupService.MutateAdGroups(new MutateAdGroupsRequest()
            {
                CustomerId     = customerId.ToString(),
                Operations     = { operations },
                PartialFailure = true,
                ValidateOnly   = false
            });

            return(response);
        }
 /// <summary>Snippet for MutateAdGroups</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroups()
 {
     // Create client
     AdGroupServiceClient adGroupServiceClient = AdGroupServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <AdGroupOperation> operations = new AdGroupOperation[]
     {
         new AdGroupOperation(),
     };
     // Make the request
     MutateAdGroupsResponse response = adGroupServiceClient.MutateAdGroups(customerId, operations);
 }
Example #11
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="campaignId">ID of the campaign to which ad groups are added.</param>
        public void Run(GoogleAdsClient client, long customerId, long campaignId)
        {
            // Get the AdGroupService.
            AdGroupServiceClient adGroupService = client.GetService(Services.V6.AdGroupService);

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

            for (int i = 0; i < NUM_ADGROUPS_TO_CREATE; i++)
            {
                // Create the ad group.
                AdGroup adGroup = new AdGroup()
                {
                    Name     = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
                    Status   = AdGroupStatusEnum.Types.AdGroupStatus.Enabled,
                    Campaign = ResourceNames.Campaign(customerId, campaignId),

                    // Set the ad group bids.
                    CpcBidMicros = 10000000
                };

                // Create the operation.
                AdGroupOperation operation = new AdGroupOperation()
                {
                    Create = adGroup
                };
                operations.Add(operation);
            }

            try
            {
                // Create the ad groups.
                MutateAdGroupsResponse response = adGroupService.MutateAdGroups(
                    customerId.ToString(), operations);

                // Display the results.
                foreach (MutateAdGroupResult newAdGroup in response.Results)
                {
                    Console.WriteLine("Ad group with resource name '{0}' was created.",
                                      newAdGroup.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 #12
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">Id of the ad group to be updated.</param>
        /// <param name="cpcBidMicroAmount">The CPC bid amount for the ad group in micros.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId,
                        long?cpcBidMicroAmount)
        {
            AdGroupServiceClient adGroupService = client.GetService(Services.V4.AdGroupService);

            // Create an ad group with the specified ID.
            AdGroup adGroup = new AdGroup();

            adGroup.ResourceName = ResourceNames.AdGroup(customerId, adGroupId);

            // Pause the ad group.
            adGroup.Status = AdGroupStatusEnum.Types.AdGroupStatus.Paused;

            // Update the CPC bid if specified.
            if (cpcBidMicroAmount != null)
            {
                adGroup.CpcBidMicros = cpcBidMicroAmount;
            }

            // Create the operation.
            AdGroupOperation operation = new AdGroupOperation()
            {
                Update     = adGroup,
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroup)
            };

            try
            {
                // Update the ad group.
                MutateAdGroupsResponse retVal = adGroupService.MutateAdGroups(
                    customerId.ToString(), new AdGroupOperation[] { operation });

                // Display the results.
                MutateAdGroupResult adGroupResult = retVal.Results[0];

                Console.WriteLine($"Ad group with resource name '{adGroupResult.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;
            }
        }
Example #13
0
 /// <summary>Snippet for MutateAdGroups</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupsRequestObject()
 {
     // Create client
     AdGroupServiceClient adGroupServiceClient = AdGroupServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupsRequest request = new MutateAdGroupsRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateAdGroupsResponse response = adGroupServiceClient.MutateAdGroups(request);
 }
 /// <summary>Snippet for MutateAdGroups</summary>
 public void MutateAdGroupsRequestObject()
 {
     // Snippet: MutateAdGroups(MutateAdGroupsRequest, CallSettings)
     // Create client
     AdGroupServiceClient adGroupServiceClient = AdGroupServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupsRequest request = new MutateAdGroupsRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateAdGroupsResponse response = adGroupServiceClient.MutateAdGroups(request);
     // End snippet
 }