/// <summary> /// Creates a new hotel ad group ad in the specified 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 ad group that a new ad group /// ad will belong to</param> private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId, string adGroupResourceName) { // Get the AdGroupAdService. AdGroupAdServiceClient service = client.GetService(Services.V0.AdGroupAdService); // Create a new ad group ad and sets the hotel ad to it. AdGroupAd adGroupAd = new AdGroupAd() { // Create a new hotel ad. Ad = new Ad() { HotelAd = new HotelAdInfo(), }, // Set the ad group. AdGroup = adGroupResourceName, Status = AdGroupAdStatus.Paused }; // Create an ad group ad operation. AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation() { Create = adGroupAd }; // Issue a mutate request to add an ad group ad. MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(), new AdGroupAdOperation[] { adGroupAdOperation }); MutateAdGroupAdResult addedAdGroupAd = response.Results[0]; Console.WriteLine($"Added a hotel ad group ad with resource name " + $"{addedAdGroupAd.ResourceName}."); }
// [END add_shopping_product_ad_1] /// <summary> /// Creates a new Shopping product ad group ad in 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 resource name of the ad group that the new ad /// group ad will belong to.</param> /// <returns>Resource name of the newly created ad group ad.</returns> /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more /// service errors.</exception> // [START add_shopping_product_ad] private string AddProductShoppingAdGroupAd(GoogleAdsClient client, long customerId, string adGroupResourceName) { // Get the AdGroupAdService. AdGroupAdServiceClient adGroupAdService = client.GetService( Services.V10.AdGroupAdService); // Creates a new shopping product ad. Ad ad = new Ad() { ShoppingProductAd = new ShoppingProductAdInfo() { } }; // Creates a new ad group ad and sets the shopping product ad to it. AdGroupAd adGroupAd = new AdGroupAd() { // Sets the ad to the ad created above. Ad = ad, Status = AdGroupAdStatus.Paused, // Sets the ad group. AdGroup = adGroupResourceName }; // Creates an ad group ad operation. AdGroupAdOperation operation = new AdGroupAdOperation() { Create = adGroupAd }; // Issues a mutate request to add an ad group ad. MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdService.MutateAdGroupAds( customerId.ToString(), new AdGroupAdOperation[] { operation }).Results[0]; Console.WriteLine("Added a product shopping ad group ad with resource name: '{0}'.", mutateAdGroupAdResult.ResourceName); return(mutateAdGroupAdResult.ResourceName); }
/// <summary> /// Creates a new hotel ad group ad in the specified 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 ad group that a new ad group /// ad will belong to</param> private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId, string adGroupResourceName) { // Get the AdGroupAdService. AdGroupAdServiceClient service = client.GetService(Services.V4.AdGroupAdService); // Create a new ad group ad and sets the hotel ad to it. AdGroupAd adGroupAd = new AdGroupAd() { // Create a new hotel ad. Ad = new Ad() { HotelAd = new HotelAdInfo(), }, // Set the ad group. AdGroup = adGroupResourceName, // Set the ad group ad to enabled. Setting this to paused will cause an error // for hotel campaigns. For hotels pausing should happen at either the ad group or // campaign level. Status = AdGroupAdStatus.Enabled }; // Create an ad group ad operation. AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation() { Create = adGroupAd }; // Issue a mutate request to add an ad group ad. MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(), new AdGroupAdOperation[] { adGroupAdOperation }); MutateAdGroupAdResult addedAdGroupAd = response.Results[0]; Console.WriteLine($"Added a hotel ad group ad with resource name " + $"{addedAdGroupAd.ResourceName}."); }