추천 가져오기에서는 단어나 구문을 사용하여 KeywordThemeConstant 객체 집합을 가져오는 방법을 보여드렸습니다. 이 단계에서는 이러한 동일한 키워드 테마 상수를 사용하여
CampaignCriterion 객체 집합을 만들어 스마트 캠페인이 타겟팅하도록 합니다.
예산을 만들 때
SmartCampaignSuggestService에서 제안한 예산 금액을 사용한 것과 마찬가지로예산을 만드는 것이 좋습니다. 추천 가져오기
에서
KeywordThemeConstantService에서 가져온 키워드 테마 상수를 기반으로
캠페인 기준을 만드세요.
다음은 스마트 캠페인 기준의 주요 요구사항입니다.
스마트 캠페인은 다음 기준 유형만 지원합니다.
위치 타겟팅의 경우 위치 가 지정되지 않으면 타겟팅은 기본적으로 모든 지역을 포함합니다.
여러
location기준을 스마트 캠페인과 연결할 수 있지만proximity기준은 하나만 사용할 수 있습니다.location및proximity타겟팅을 모두 사용할 수는 없습니다.
다음 예에서는 리소스 이름을
KeywordThemeInfo.keyword_theme_constant
필드에 설정하여 키워드 테마 상수가
KeywordThemeInfo객체로 변환되었습니다. 이전 단계에서 캠페인에 설정된 임시 리소스
이름을 사용하여 campaign 필드를 설정합니다.
자바
/** * Creates {@link com.google.ads.googleads.v25.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()); }
C#
/// <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; }
Python
def create_campaign_criterion_operations( client: GoogleAdsClient, customer_id: str, keyword_theme_infos: List[KeywordThemeInfo], suggestion_info: SmartCampaignSuggestionInfo, ) -> List[MutateOperation]: """Creates a list of MutateOperations that create new campaign criteria. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. keyword_theme_infos: a list of KeywordThemeInfos. suggestion_info: A SmartCampaignSuggestionInfo instance. Returns: a list of MutateOperations that create new campaign criteria. """ campaign_service: CampaignServiceClient = client.get_service( "CampaignService" ) operations: List[MutateOperation] = [] info: KeywordThemeInfo for info in keyword_theme_infos: mutate_operation: MutateOperation = client.get_type("MutateOperation") campaign_criterion_operation: CampaignCriterionOperation = ( mutate_operation.campaign_criterion_operation ) campaign_criterion: CampaignCriterion = ( campaign_criterion_operation.create ) # Set the campaign ID to a temporary ID. campaign_criterion.campaign = campaign_service.campaign_path( customer_id, _SMART_CAMPAIGN_TEMPORARY_ID ) # Set the keyword theme to the given KeywordThemeInfo. campaign_criterion.keyword_theme.CopyFrom(info) # Add the mutate operation to the list of other operations. operations.append(mutate_operation) # Create a location criterion for each location in the suggestion info # object to add corresponding location targeting to the Smart campaign location_info: LocationInfo for location_info in suggestion_info.location_list.locations: mutate_operation: MutateOperation = client.get_type("MutateOperation") campaign_criterion_operation: CampaignCriterionOperation = ( mutate_operation.campaign_criterion_operation ) campaign_criterion: CampaignCriterion = ( campaign_criterion_operation.create ) # Set the campaign ID to a temporary ID. campaign_criterion.campaign = campaign_service.campaign_path( customer_id, _SMART_CAMPAIGN_TEMPORARY_ID ) # Set the location to the given location. campaign_criterion.location.CopyFrom(location_info) # Add the mutate operation to the list of other operations. operations.append(mutate_operation) return operations
Ruby
# Creates a list of mutate_operations that create new campaign criteria. def create_campaign_criterion_operations( client, customer_id, keyword_theme_infos, suggestion_info) operations = [] keyword_theme_infos.each do |info| operations << client.operation.mutate do |m| m.campaign_criterion_operation = client.operation.create_resource.campaign_criterion do |cc| # Sets the campaign ID to a temporary ID. cc.campaign = client.path.campaign( customer_id, SMART_CAMPAIGN_TEMPORARY_ID) # Sets the keyword theme to the given keyword_theme_info. cc.keyword_theme = info end end end # Create a location criterion for each location in the suggestion info object # to add corresponding location targeting to the Smart campaign suggestion_info.location_list.locations.each do |location| operations << client.operation.mutate do |m| m.campaign_criterion_operation = client.operation.create_resource.campaign_criterion do |cc| # Sets the campaign ID to a temporary ID. cc.campaign = client.path.campaign( customer_id, SMART_CAMPAIGN_TEMPORARY_ID) # Sets the location to the given location. cc.location = location end end end operations end
Perl
# Creates a list of MutateOperations that create new campaign criteria. sub _create_campaign_criterion_operations { my ($customer_id, $keyword_theme_infos, $suggestion_info) = @_; my $campaign_criterion_operations = []; foreach my $keyword_theme_info (@$keyword_theme_infos) { push @$campaign_criterion_operations, Google::Ads::GoogleAds::V25::Services::GoogleAdsService::MutateOperation ->new({ campaignCriterionOperation => Google::Ads::GoogleAds::V25::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => Google::Ads::GoogleAds::V25::Resources::CampaignCriterion->new({ # Set the campaign ID to a temporary ID. campaign => Google::Ads::GoogleAds::V25::Utils::ResourceNames::campaign( $customer_id, SMART_CAMPAIGN_TEMPORARY_ID ), # Set the keyword theme to the given KeywordThemeInfo. keywordTheme => $keyword_theme_info })})}); } # Create a location criterion for each location in the suggestion info object # to add corresponding location targeting to the Smart campaign. foreach my $location_info (@{$suggestion_info->{locationList}{locations}}) { push @$campaign_criterion_operations, Google::Ads::GoogleAds::V25::Services::GoogleAdsService::MutateOperation ->new({ campaignCriterionOperation => Google::Ads::GoogleAds::V25::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => Google::Ads::GoogleAds::V25::Resources::CampaignCriterion->new({ # Set the campaign ID to a temporary ID. campaign => Google::Ads::GoogleAds::V25::Utils::ResourceNames::campaign( $customer_id, SMART_CAMPAIGN_TEMPORARY_ID ), # Set the location to the given location. location => $location_info })})}); } return $campaign_criterion_operations; }
curl
제외 키워드 테마 캠페인 기준
스마트 캠페인에서 키워드 테마 캠페인 기준을 제외 타겟팅하려면
자유 형식 키워드 테마를
사용해야 합니다. 이 작업은
free_form_keyword_theme
필드를
KeywordThemeInfo 인스턴스에 설정하여 수행합니다.
제외 키워드 테마 기준은 포함 키워드 테마 기준과 다르게 작동합니다. 포함 키워드 테마 기준은 유사한 다른 기준을 자동으로 타겟팅하도록 조정되는 반면, 제외 키워드 테마 기준은 정확히 지정된 용어만 제외 타겟팅하도록 제한됩니다. 이 동작은 제외 구문검색 키워드의 동작과 동일합니다.