Google Ads API 会公开 SmartCampaignSuggestService,以便在制作智能广告系列时建议配置详细信息。它会使用所宣传商家的详细信息(以 SmartCampaignSuggestionInfo 实例的形式)来建议关键字主题、预算金额,以及各个广告的标题和广告内容描述。
创建 SmartCampaignSuggestionInfo 实例
若要生成智能广告系列建议,您需要使用包含所宣传业务详细信息的 SmartCampaignSuggestionInfo 实例。由于可以使用同一 SmartCampaignSuggestionInfo 实例检索所有不同类型的智能广告系列建议,因此您可以先创建一个实例,然后多次重复使用。
SmartCampaignSuggestionInfo 的主要要求:
着陆页。这可以是现有网站 (
final_url),也可以是使用通过business_profile_location标识符获得的商家资料信息为您的广告系列创建的自动着陆页。如果您打算使用自动着陆页,请务必在生成建议时设置business_profile_location字段。- 如果设置了
final_url,则可以设置business_profile_location或business_name。 - 如果未设置
final_url,则必须设置business_profile_location。
- 如果设置了
当用于从
SuggestKeywordThemes方法检索关键字主题建议时,无需设置keyword_themes字段。当用于从
SuggestSmartCampaignAd方法检索广告建议时,language_code和keyword_themes字段是必需的。应尽可能多地向对象添加详细信息,以获得最佳建议。
Java
private SmartCampaignSuggestionInfo getSmartCampaignSuggestionInfo( GoogleAdsClient googleAdsClient, String businessProfileLocation, String businessName) { SmartCampaignSuggestionInfo.Builder suggestionInfoBuilder = SmartCampaignSuggestionInfo.newBuilder() // Adds the URL of the campaign's landing page. .setFinalUrl(LANDING_PAGE_URL) // Adds the language code for the campaign. .setLanguageCode(LANGUAGE_CODE) // Constructs location information using the given geo target constant. It's also // possible to provide a geographic proximity using the "proximity" field, // for example: // .setProximity( // ProximityInfo.newBuilder() // .setAddress( // AddressInfo.newBuilder() // .setPostalCode(INSERT_POSTAL_CODE) // .setProvinceCode(INSERT_PROVINCE_CODE) // .setCountryCode(INSERT_COUNTRY_CODE) // .setProvinceName(INSERT_PROVINCE_NAME) // .setStreetAddress(INSERT_STREET_ADDRESS) // .setStreetAddress2(INSERT_STREET_ADDRESS_2) // .setCityName(INSERT_CITY_NAME) // .build()) // .setRadius(INSERT_RADIUS) // .setRadiusUnits(INSERT_RADIUS_UNITS) // .build()) // For more information on proximities see: // https://developers.google.com/google-ads/api/reference/rpc/latest/ProximityInfo // // Adds LocationInfo objects to the list of locations. You have the option of // providing multiple locations when using location-based suggestions. .setLocationList( LocationList.newBuilder() // Sets one location to the resource name of the given geo target constant. .addLocations( LocationInfo.newBuilder() .setGeoTargetConstant( ResourceNames.geoTargetConstant(GEO_TARGET_CONSTANT)) .build()) .build()) // Adds a schedule detailing which days of the week the business is open. // This schedule describes a schedule in which the business is open on // Mondays from 9am to 5pm. .addAdSchedules( AdScheduleInfo.newBuilder() // Sets the day of this schedule as Monday. .setDayOfWeek(DayOfWeek.MONDAY) // Sets the start hour to 9am. .setStartHour(9) // Sets the end hour to 5pm. .setEndHour(17) // Sets the start and end minute of zero, for example: 9:00 and 5:00. .setStartMinute(MinuteOfHour.ZERO) .setEndMinute(MinuteOfHour.ZERO) .build()); // Sets either of the business_profile_location or business_name, depending on whichever is // provided. if (businessProfileLocation != null) { suggestionInfoBuilder.setBusinessProfileLocation(businessProfileLocation); } else { suggestionInfoBuilder.setBusinessContext( BusinessContext.newBuilder().setBusinessName(businessName).build()); } return suggestionInfoBuilder.build(); }
C#
/// <summary> /// Builds a SmartCampaignSuggestionInfo object with business details. /// /// The details are used by the SmartCampaignSuggestService to suggest a /// budget amount as well as creatives for the ad. /// /// Note that when retrieving ad creative suggestions it's required that the /// "final_url", "language_code" and "keyword_themes" fields are set on the /// SmartCampaignSuggestionInfo instance. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="businessProfileLocation">The identifier of a Business Profile location. /// </param> /// <param name="businessName">The name of a Business Profile.</param> /// <returns>A SmartCampaignSuggestionInfo instance .</returns> private SmartCampaignSuggestionInfo GetSmartCampaignSuggestionInfo(GoogleAdsClient client, string businessProfileLocation, string businessName) { // Note: This is broken since businessLocationId is not yet renamed in // SmartCampaignSuggestionInfo. The use of dynamic temporarily fixes the broken build. // TODO(Anash): Revert the type change once this field is fixed. dynamic suggestionInfo = new SmartCampaignSuggestionInfo { // Add the URL of the campaign's landing page. FinalUrl = LANDING_PAGE_URL, LanguageCode = LANGUAGE_CODE, // Construct location information using the given geo target constant. It's // also possible to provide a geographic proximity using the "proximity" // field on suggestion_info, for example: // Proximity = new ProximityInfo // { // Address = new AddressInfo // { // PostalCode = "INSERT_POSTAL_CODE", // ProvinceCode = "INSERT_PROVINCE_CODE", // CountryCode = "INSERT_COUNTRY_CODE", // ProvinceName = "INSERT_PROVINCE_NAME", // StreetAddress = "INSERT_STREET_ADDRESS", // StreetAddress2 = "INSERT_STREET_ADDRESS_2", // CityName = "INSERT_CITY_NAME" // }, // Radius = Double.Parse("INSERT_RADIUS"), // RadiusUnits = ProximityRadiusUnits.Kilometers // } // For more information on proximities see: // https://developers.google.com/google-ads/api/reference/rpc/latest/ProximityInfo LocationList = new LocationList() { Locations = { new LocationInfo { // Set the location to the resource name of the given geo target // constant. GeoTargetConstant = ResourceNames.GeoTargetConstant(GEO_TARGET_CONSTANT) } } } }; // Add the Business Profile location if provided. if (!string.IsNullOrEmpty(businessProfileLocation)) { suggestionInfo.BusinessProfileLocation = businessProfileLocation; } else { suggestionInfo.BusinessContext = new BusinessContext { BusinessName = businessName, }; } // Add a schedule detailing which days of the week the business is open. This schedule // describes a business that is open on Mondays from 9:00 AM to 5:00 PM. AdScheduleInfo adScheduleInfo = new AdScheduleInfo { // Set the day of this schedule as Monday. DayOfWeek = DayOfWeekEnum.Types.DayOfWeek.Monday, // Set the start hour to 9 AM. StartHour = 9, // Set the end hour to 5 PM. EndHour = 17, // Set the start and end minutes to zero. StartMinute = MinuteOfHourEnum.Types.MinuteOfHour.Zero, EndMinute = MinuteOfHourEnum.Types.MinuteOfHour.Zero }; suggestionInfo.AdSchedules.Add(adScheduleInfo); return suggestionInfo; }
PHP
private static function getSmartCampaignSuggestionInfo( ?string $businessProfileLocationResourceName, ?string $businessName ): SmartCampaignSuggestionInfo { $suggestionInfo = new SmartCampaignSuggestionInfo([ // Adds the URL of the campaign's landing page. 'final_url' => self::LANDING_PAGE_URL, // Adds the language code for the campaign. 'language_code' => self::LANGUAGE_CODE, // Constructs location information using the given geo target constant. It's also // possible to provide a geographic proximity using the "proximity" field, // for example: // // 'proximity' => new ProximityInfo([ // 'address' => mew AddressInfo([ // 'post_code' => INSERT_POSTAL_CODE, // 'province_code' => INSERT_PROVINCE_CODE, // 'country_code' => INSERT_COUNTRY_CODE, // 'province_name' => INSERT_PROVINCE_NAME, // 'street_address' => INSERT_STREET_ADDRESS, // 'street_address2' => INSERT_STREET_ADDRESS_2, // 'city_name' => INSERT_CITY_NAME // ]), // 'radius' => INSERT_RADIUS, // 'radius_units' => INSERT_RADIUS_UNITS // ]) // // For more information on proximities see: // https://developers.google.com/google-ads/api/reference/rpc/latest/ProximityInfo // Adds LocationInfo objects to the list of locations. You have the option of // providing multiple locations when using location-based suggestions. 'location_list' => new LocationList([ // Sets one location to the resource name of the given geo target constant. 'locations' => [new LocationInfo([ 'geo_target_constant' => ResourceNames::forGeoTargetConstant( self::GEO_TARGET_CONSTANT ) ])] ]), // Adds a schedule detailing which days of the week the business is open. // This schedule describes a schedule in which the business is open on // Mondays from 9am to 5pm. 'ad_schedules' => [new AdScheduleInfo([ // Sets the day of this schedule as Monday. 'day_of_week' => DayOfWeek::MONDAY, // Sets the start hour to 9am. 'start_hour' => 9, // Sets the end hour to 5pm. 'end_hour' => 17, // Sets the start and end minute of zero, for example: 9:00 and 5:00. 'start_minute' => MinuteOfHour::ZERO, 'end_minute' => MinuteOfHour::ZERO ])] ]); // Sets either of the business_profile_location or business_name, depending on whichever is // provided. if ($businessProfileLocationResourceName) { $suggestionInfo->setBusinessProfileLocation($businessProfileLocationResourceName); } else { $suggestionInfo->setBusinessContext(new BusinessContext([ 'business_name' => $businessName ])); } return $suggestionInfo; }