कैंपेन के लिए शर्तें बनाएं

सुझाव पाएं में, हमने किसी शब्द या वाक्यांश का इस्तेमाल करके, KeywordThemeConstant ऑब्जेक्ट के सेट को वापस पाने का तरीका दिखाया है. इस चरण में, हम कीवर्ड थीम कॉन्स्टेंट का इस्तेमाल स्मार्ट कैंपेन के लिए टारगेट करने के लिए, CampaignCriterion ऑब्जेक्ट का एक सेट बनाने में करते हैं.

हमने बजट बनाते समय, SmartCampaignSuggestService के सुझाए गए बजट की रकम का इस्तेमाल जिस तरह किया है उसी तरह सुझाव पाएं में जाकर, KeywordThemeConstantService से मिले कीवर्ड थीम कॉन्सटेंट के आधार पर कैंपेन की शर्तें तय करें.

स्मार्ट कैंपेन की ज़रूरी शर्तों के बारे में यहां बताया गया है:

  • स्मार्ट कैंपेन में, सिर्फ़ इन तरह की शर्तों का इस्तेमाल किया जा सकता है:

  • जगह के हिसाब से टारगेटिंग के लिए, अगर किसी जगह के लिए जानकारी नहीं दी गई है, तो डिफ़ॉल्ट रूप से सभी इलाकों को टारगेटिंग में शामिल कर लिया जाएगा.

  • एक से ज़्यादा location शर्तों को स्मार्ट कैंपेन के साथ जोड़ा जा सकता है, लेकिन सिर्फ़ एक proximity शर्त का इस्तेमाल किया जा सकता है.

  • location और proximity, दोनों टारगेटिंग इस्तेमाल नहीं की जा सकती.

यहां दिए गए उदाहरण में, कीवर्ड थीम कॉन्सटेंट को KeywordThemeInfo ऑब्जेक्ट में बदला गया है. ऐसा करने के लिए, अपने रिसॉर्स का नाम KeywordThemeInfo.keyword_theme_constant फ़ील्ड पर सेट किया गया है. हम campaign फ़ील्ड को सेट करने के लिए, पिछले चरण में कैंपेन पर सेट किए गए कुछ समय के लिए उपलब्ध रिसॉर्स का नाम इस्तेमाल करते हैं.

Java

/**
 * Creates {@link com.google.ads.googleads.v16.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, customer_id, keyword_theme_infos, suggestion_info
):
    """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 = client.get_service("CampaignService")

    operations = []
    for info in keyword_theme_infos:
        mutate_operation = client.get_type("MutateOperation")
        campaign_criterion = (
            mutate_operation.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 = 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
    for location_info in suggestion_info.location_list.locations:
        mutate_operation = client.get_type("MutateOperation")
        campaign_criterion = (
            mutate_operation.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 = 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::V16::Services::GoogleAdsService::MutateOperation
      ->new({
        campaignCriterionOperation =>
          Google::Ads::GoogleAds::V16::Services::CampaignCriterionService::CampaignCriterionOperation
          ->new({
            create =>
              Google::Ads::GoogleAds::V16::Resources::CampaignCriterion->new({
                # Set the campaign ID to a temporary ID.
                campaign =>
                  Google::Ads::GoogleAds::V16::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::V16::Services::GoogleAdsService::MutateOperation
      ->new({
        campaignCriterionOperation =>
          Google::Ads::GoogleAds::V16::Services::CampaignCriterionService::CampaignCriterionOperation
          ->new({
            create =>
              Google::Ads::GoogleAds::V16::Resources::CampaignCriterion->new({
                # Set the campaign ID to a temporary ID.
                campaign =>
                  Google::Ads::GoogleAds::V16::Utils::ResourceNames::campaign(
                  $customer_id, SMART_CAMPAIGN_TEMPORARY_ID
                  ),
                # Set the location to the given location.
                location => $location_info
              })})});
  }

  return $campaign_criterion_operations;
}
      

नेगेटिव कीवर्ड थीम वाले कैंपेन की शर्तें

स्मार्ट कैंपेन में, कीवर्ड थीम वाले कैंपेन की शर्तों को नेगेटिव में टारगेट करने के लिए, आपको फ़्री-फ़ॉर्म कीवर्ड थीम का इस्तेमाल करना होगा. इसके लिए, KeywordThemeInfo इंस्टेंस पर free_form_keyword_theme फ़ील्ड को सेट करें.

नेगेटिव कीवर्ड थीम का मानदंड, पॉज़िटिव कीवर्ड थीम के मानदंड से अलग तरीके से काम करता है. जहां एक पॉज़िटिव कीवर्ड थीम शर्त को, दूसरे मिलते-जुलते मानदंड को अपने-आप टारगेट करने के लिए अडजस्ट किया जाता है, वहीं नेगेटिव कीवर्ड थीम से जुड़ी शर्त को सिर्फ़ किसी खास शब्द को नेगेटिव टारगेट करने के लिए ही सीमित किया जाता है. यह व्यवहार, किसी नेगेटिव फ़्रेज़ मैच वाले कीवर्ड के काम करने के तरीके के बराबर होता है.