در دریافت پیشنهادات ، نحوه بازیابی مجموعه ای از اشیاء KeywordThemeConstant را با استفاده از یک کلمه یا عبارت نشان دادیم. در این مرحله، از همان ثابتهای موضوع کلیدواژه برای ایجاد مجموعهای از اشیاء CampaignCriterion برای هدف کمپین هوشمند استفاده میکنیم.
مشابه نحوه استفاده از مبلغ بودجه پیشنهادی SmartCampaignSuggestService هنگام ایجاد بودجه ، توصیه می کنیم معیارهای کمپین را بر اساس ثابت های موضوع کلیدواژه بازیابی شده از KeywordThemeConstantService در دریافت پیشنهادات ایجاد کنید.
در اینجا الزامات کلیدی برای معیارهای کمپین هوشمند آمده است:
کمپین های هوشمند فقط از انواع معیارهای زیر پشتیبانی می کنند:
برای مکان یابی ، اگر مکانی مشخص نشده باشد، هدف گذاری به طور پیش فرض شامل همه مناطق می شود.
چندین معیار
locationمی توان با یک کمپین هوشمند مرتبط کرد، اما فقط می توان از یک معیارproximityاستفاده کرد.شما نمی توانید هم
locationو هم از هدف گذاریproximityاستفاده کنید.
در مثال زیر، با تنظیم نام منبع خود در فیلد KeywordThemeInfo.keyword_theme_constant ، ثابتهای موضوع کلیدواژه به اشیاء KeywordThemeInfo تبدیل شدهاند. فیلد campaign را با استفاده از نام منبع موقتی که در مرحله قبل روی کمپین تنظیم شده بود تنظیم کردیم.
جاوا
/** * Creates {@link com.google.ads.googleads.v22.resources.CampaignCriterion} operations for add * each {@link KeywordThemeInfo}. */ private Collection<? extends MutateOperation> createCampaignCriterionOperations( long customerId, List<KeywordThemeInfo> keywordThemeInfos, SmartCampaignSuggestionInfo suggestionInfo) { List<MutateOperation> keywordThemeOperations = keywordThemeInfos.stream() .map( keywordTheme -> { MutateOperation.Builder builder = MutateOperation.newBuilder(); builder .getCampaignCriterionOperationBuilder() .getCreateBuilder() .setCampaign(ResourceNames.campaign(customerId, SMART_CAMPAIGN_TEMPORARY_ID)) .setKeywordTheme(keywordTheme); return builder.build(); }) .collect(Collectors.toList()); List<MutateOperation> locationOperations = suggestionInfo.getLocationList().getLocationsList().stream() .map( location -> { MutateOperation.Builder builder = MutateOperation.newBuilder(); builder .getCampaignCriterionOperationBuilder() .getCreateBuilder() .setCampaign(ResourceNames.campaign(customerId, SMART_CAMPAIGN_TEMPORARY_ID)) .setLocation(location); return builder.build(); }) .collect(Collectors.toList()); return Stream.concat(keywordThemeOperations.stream(), locationOperations.stream()) .collect(Collectors.toList()); }
سی شارپ
/// <summary> /// Creates a list of MutateOperations that create new campaign criteria. /// </summary> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="keywordThemeInfos">A list of KeywordThemeInfos.</param> /// <param name="suggestionInfo">A SmartCampaignSuggestionInfo instance.</param> /// <returns>A list of MutateOperations that create new campaign criteria.</returns> private IEnumerable<MutateOperation> CreateCampaignCriterionOperations(long customerId, IEnumerable<KeywordThemeInfo> keywordThemeInfos, SmartCampaignSuggestionInfo suggestionInfo) { List<MutateOperation> mutateOperations = keywordThemeInfos.Select( keywordThemeInfo => new MutateOperation { CampaignCriterionOperation = new CampaignCriterionOperation { Create = new CampaignCriterion { // Set the campaign ID to a temporary ID. Campaign = ResourceNames.Campaign( customerId, SMART_CAMPAIGN_TEMPORARY_ID), // Set the keyword theme to each KeywordThemeInfo in turn. KeywordTheme = keywordThemeInfo, } } }).ToList(); // Create a location criterion for each location in the suggestion info. mutateOperations.AddRange( suggestionInfo.LocationList.Locations.Select( locationInfo => new MutateOperation() { CampaignCriterionOperation = new CampaignCriterionOperation() { Create = new CampaignCriterion() { // Set the campaign ID to a temporary ID. Campaign = ResourceNames.Campaign(customerId, SMART_CAMPAIGN_TEMPORARY_ID), // Set the location to the given location. Location = locationInfo } } }).ToList() ); return mutateOperations; }
PHP
private static function createCampaignCriterionOperations( int $customerId, array $keywordThemeInfos, SmartCampaignSuggestionInfo $smartCampaignSuggestionInfo ): array { $operations = []; foreach ($keywordThemeInfos as $info) { // Creates the campaign criterion object. $campaignCriterion = new CampaignCriterion([ // Sets the campaign ID to a temporary ID. 'campaign' => ResourceNames::forCampaign($customerId, self::SMART_CAMPAIGN_TEMPORARY_ID), // Sets the keyword theme to the given KeywordThemeInfo. 'keyword_theme' => $info ]); // Creates the MutateOperation that creates the campaign criterion and adds it to the // list of operations. $operations[] = new MutateOperation([ 'campaign_criterion_operation' => new CampaignCriterionOperation([ 'create' => $campaignCriterion ]) ]); } // Create a location criterion for each location in the suggestion info object to add // corresponding location targeting to the Smart campaign. foreach ($smartCampaignSuggestionInfo->getLocationList()->getLocations() as $location) { // Creates the campaign criterion object. $campaignCriterion = new CampaignCriterion([ // Sets the campaign ID to a temporary ID. 'campaign' => ResourceNames::forCampaign($customerId, self::SMART_CAMPAIGN_TEMPORARY_ID), // Set the location to the given location. 'location' => $location ]); // Creates the MutateOperation that creates the campaign criterion and adds it to the // list of operations. $operations[] = new MutateOperation([ 'campaign_criterion_operation' => new CampaignCriterionOperation([ 'create' => $campaignCriterion ]) ]); } return $operations; }