Tạo chiến dịch Điểm tham quan

Bước đầu tiên để triển khai quảng cáo Điểm tham quan là tạo chiến dịch Điểm tham quan. Khi tạo chiến dịch, bạn sẽ đặt ngân sách, chiến lược đặt giá thầu và mã tài khoản Things to Do Center.

Dưới đây là các bước để thiết lập một chiến dịch:

  1. Đặt advertising_channel_type của chiến dịch thành TRAVELadvertising_channel_sub_type thành TRAVEL_ACTIVITIES.
  2. Tạo TravelCampaignSettings, đặt travel_account_id, rồi thêm đối tượng này vào chiến dịch.
  3. Tạo chiến lược đặt giá thầu MaximizeConversionValue cho chiến dịch.

Mã sau đây minh hoạ các bước này.

Java

private String addThingsToDoCampaign(
    GoogleAdsClient googleAdsClient,
    long customerId,
    String budgetResourceName,
    long thingsToDoCenterAccountId) {
  // Creates the campaign.
  Campaign campaign =
      Campaign.newBuilder()
          .setName("Interplanetary Cruise #" + getPrintableDateTime())
          // Configures settings related to Things to do campaigns including advertising channel
          // type, advertising channel sub type and travel campaign settings.
          .setAdvertisingChannelType(AdvertisingChannelType.TRAVEL)
          .setAdvertisingChannelSubType(AdvertisingChannelSubType.TRAVEL_ACTIVITIES)
          .setTravelCampaignSettings(
              TravelCampaignSettings.newBuilder().setTravelAccountId(thingsToDoCenterAccountId))
          // Recommendation: Sets the campaign to PAUSED when creating it to prevent
          // the ads from immediately serving. Set to ENABLED once you've added
          // targeting and the ads are ready to serve
          .setStatus(CampaignStatus.PAUSED)
          // Sets the bidding strategy to MaximizeConversionValue. Only this type can be used
          // for Things to do campaigns.
          .setMaximizeConversionValue(MaximizeConversionValue.newBuilder())
          // Sets the budget.
          .setCampaignBudget(budgetResourceName)
          // Configures the campaign network options. Only Google Search is allowed for
          // Things to do campaigns.
          .setNetworkSettings(NetworkSettings.newBuilder().setTargetGoogleSearch(true))
          .build();

  // Creates a campaign operation.
  CampaignOperation operation = CampaignOperation.newBuilder().setCreate(campaign).build();

  // Issues a mutate request to add the campaign.
  try (CampaignServiceClient campaignServiceClient =
      googleAdsClient.getLatestVersion().createCampaignServiceClient()) {
    MutateCampaignsResponse response =
        campaignServiceClient.mutateCampaigns(
            Long.toString(customerId), Collections.singletonList(operation));
    MutateCampaignResult result = response.getResults(0);
    System.out.printf(
        "Added a Things to do campaign with resource name: '%s'%n", result.getResourceName());
    return result.getResourceName();
  }
}
      

C#

// Creates a campaign.
Campaign campaign = new Campaign()
{
    Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),
    AdvertisingChannelType = AdvertisingChannelType.Travel,
    AdvertisingChannelSubType = AdvertisingChannelSubType.TravelActivities,

    TravelCampaignSettings = new TravelCampaignSettings()
    {
        TravelAccountId = thingsToDoCenterAccountId
    },

    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve
    Status = CampaignStatus.Paused,

    // Set the bidding strategy and budget.
    MaximizeConversionValue = new MaximizeConversionValue(),
    CampaignBudget = budget,

    // Set the campaign network options.
    NetworkSettings = new NetworkSettings
    {
        TargetGoogleSearch = true
    }
};
      

1.199

private static function addThingsToDoCampaign(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $budgetResourceName,
    int $thingsToDoCenterAccountId
) {
    // Creates a campaign.
    $campaign = new Campaign([
        'name' => 'Interplanetary Cruise Campaign #' . Helper::getPrintableDatetime(),
        // Configures settings related to Things to do campaigns including advertising channel
        // type, advertising channel sub type and travel campaign settings.
        'advertising_channel_type' => AdvertisingChannelType::TRAVEL,
        'advertising_channel_sub_type' => AdvertisingChannelSubType::TRAVEL_ACTIVITIES,
        'travel_campaign_settings'
            => new TravelCampaignSettings(['travel_account_id' => $thingsToDoCenterAccountId]),
        // Recommendation: Set the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        'status' => CampaignStatus::PAUSED,
        // Sets the bidding strategy to MaximizeConversionValue. Only this type can be used
        // for Things to do campaigns.
        'maximize_conversion_value' => new MaximizeConversionValue(),
        // Sets the budget.
        'campaign_budget' => $budgetResourceName,
        // Configures the campaign network options. Only Google Search is allowed for
        // Things to do campaigns.
        'network_settings' => new NetworkSettings(['target_google_search' => true])
    ]);

    // Creates a campaign operation.
    $campaignOperation = new CampaignOperation();
    $campaignOperation->setCreate($campaign);

    // Issues a mutate request to add campaigns.
    $campaignServiceClient = $googleAdsClient->getCampaignServiceClient();
    $response = $campaignServiceClient->mutateCampaigns(
        MutateCampaignsRequest::build($customerId, [$campaignOperation])
    );

    /** @var Campaign $addedCampaign */
    $addedCampaign = $response->getResults()[0];
    printf(
        "Added a Things to do campaign with resource name '%s'.%s",
        $addedCampaign->getResourceName(),
        PHP_EOL
    );

    return $addedCampaign->getResourceName();
}
      

Python

def add_things_to_do_campaign(
    client, customer_id, budget_resource_name, things_to_do_center_account_id
):
    """Creates a new Things to do campaign in the specified customer account.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        budget_resource_name: the resource name of a budget for a new campaign.
        things_to_do_center_account_id: the Things to Do Center account ID.

    Returns:
        The resource name of the newly created campaign.
    """
    # Creates a campaign operation.
    operation = client.get_type("CampaignOperation")
    # Creates a campaign.
    campaign = operation.create
    campaign.name = (
        f"Interplanetary Cruise Campaign #{get_printable_datetime()}"
    )
    # Configures settings related to Things to do campaigns including
    # advertising channel type, advertising channel sub type and travel
    # campaign settings.
    campaign.advertising_channel_type = (
        client.enums.AdvertisingChannelTypeEnum.TRAVEL
    )
    campaign.advertising_channel_sub_type = (
        client.enums.AdvertisingChannelSubTypeEnum.TRAVEL_ACTIVITIES
    )
    campaign.travel_campaign_settings.travel_account_id = (
        things_to_do_center_account_id
    )
    # Recommendation: Set the campaign to PAUSED when creating it to prevent
    # the ads from immediately serving. Set to ENABLED once you've added
    # targeting and the ads are ready to serve.
    campaign.status = client.enums.CampaignStatusEnum.PAUSED
    # Sets the bidding strategy to MaximizeConversionValue. Only this type can
    # be used for Things to do campaigns.
    campaign.maximize_conversion_value = client.get_type(
        "MaximizeConversionValue"
    )
    # Sets the budget.
    campaign.campaign_budget = budget_resource_name
    # Configures the campaign network options. Only Google Search is allowed for
    # Things to do campaigns.
    campaign.network_settings.target_google_search = True

    # Issues a mutate request to add campaigns.
    campaign_service = client.get_service("CampaignService")
    response = campaign_service.mutate_campaigns(
        customer_id=customer_id, operations=[operation]
    )

    resource_name = response.results[0].resource_name
    print(
        f"Added a Things to do campaign with resource name: '{resource_name}'."
    )
    return resource_name
      

Ruby

def add_things_to_do_campaign(client, customer_id, budget_resource,
  things_to_do_center_account_id)

  # Create a campaign.
  campaign_operation = client.operation.create_resource.campaign do |c|
    c.name = generate_random_name_field("Interplanetary Cruise Campaign")

    #  Configures settings related to Things to Do campaigns including
    # advertising channel type, advertising channel sub type and
    # travel campaign settings.
    c.advertising_channel_type = :TRAVEL
    c.advertising_channel_sub_type = :TRAVEL_ACTIVITIES

    c.travel_campaign_settings = client.resource.travel_campaign_settings do |tcs|
      tcs.travel_account_id = things_to_do_center_account_id
    end

    # Recommendation: Set the campaign to PAUSED when creating it to prevent the
    # ads from immediately serving. Set to ENABLED once you've added targeting
    # and the ads are ready to serve.
    c.status = :PAUSED

    # Sets the bidding strategy to MaximizeConversionValue. Only this type can
    # be used for Things to Do campaigns.
    c.maximize_conversion_value = client.resource.maximize_conversion_value

    # Set the budget.
    c.campaign_budget = budget_resource

    # Configures the campaign network options. Only Google Search is allowed for
    # Things to Do campaigns.
    c.network_settings = client.resource.network_settings do |ns|
      ns.target_google_search = true
    end
  end

  # Issue a mutate request to add the campaign.
  campaign_service = client.service.campaign
  response = campaign_service.mutate_campaigns(
    customer_id: customer_id,
    operations: [campaign_operation],
  )

  # Fetch the new campaign's resource name.
  campaign_resource = response.results.first.resource_name

  puts "Added Things To Do campaign with resource name '#{campaign_resource}'."

  campaign_resource
end
      

Perl

sub add_things_to_do_campaign {
  my ($api_client, $customer_id, $budget_resource_name,
    $things_to_do_center_account_id)
    = @_;

  # Create a campaign.
  my $campaign = Google::Ads::GoogleAds::V16::Resources::Campaign->new({
      name => "Interplanetary Cruise Campaign #" . uniqid(),
      # Configure settings related to Things to do campaigns including
      # advertising channel type, advertising channel sub type and travel
      # campaign settings.
      advertisingChannelType    => TRAVEL,
      advertisingChannelSubType => TRAVEL_ACTIVITIES,
      travelCampaignSettings    =>
        Google::Ads::GoogleAds::V16::Resources::TravelCampaignSettings->new({
          travelAccountId => $things_to_do_center_account_id
        }
        ),
      # Recommendation: Set the campaign to PAUSED when creating it to prevent
      # the ads from immediately serving. Set to ENABLED once you've added
      # targeting and the ads are ready to serve.
      status => Google::Ads::GoogleAds::V16::Enums::CampaignStatusEnum::PAUSED,
      # Set the bidding strategy to MaximizeConversionValue. Only this type can be
      # used for Things to do campaigns.
      maximizeConversionValue =>
        Google::Ads::GoogleAds::V16::Common::MaximizeConversionValue->new(),
      # Set the budget.
      campaignBudget => $budget_resource_name,
      # Configure the campaign network options. Only Google Search is allowed for
      # Things to do campaigns.
      networkSettings =>
        Google::Ads::GoogleAds::V16::Resources::NetworkSettings->new({
          targetGoogleSearch => "true"
        })});

  # Create a campaign operation.
  my $campaign_operation =
    Google::Ads::GoogleAds::V16::Services::CampaignService::CampaignOperation->
    new({create => $campaign});

  # Add the campaign.
  my $campaign_resource_name = $api_client->CampaignService()->mutate({
      customerId => $customer_id,
      operations => [$campaign_operation]})->{results}[0]{resourceName};

  printf "Added a Things to do campaign with resource name: '%s'.\n",
    $campaign_resource_name;

  return $campaign_resource_name;
}