Creating a Hotel Campaign

The first step in implementing Hotel Ads is creating a Hotel campaign. In creating a Hotel campaign, you set its budget, bidding strategy, and Hotel Ads Center account ID.

Here are the steps in setting up a Hotel campaign:

  1. Setting the campaign's advertising_channel_type to HOTEL.
  2. Creating a HotelSettingInfo, setting its hotel_center_id, and then adding it to the campaign.
  3. Creating a PercentCpc bidding strategy for the campaign.

These steps are demonstrated in the following code.

Java
private void runExample(
    GoogleAdsClient googleAdsClient,
    long customerId,
    long hotelCenterAccountId,
    long cpcBidCeilingMicroAmount) {

  // Creates a budget to be used by the campaign that will be created below.
  String budgetResourceName = addCampaignBudget(googleAdsClient, customerId);

  // Creates a hotel campaign.
  String campaignResourceName =
      addHotelCampaign(
          googleAdsClient,
          customerId,
          budgetResourceName,
          hotelCenterAccountId,
          cpcBidCeilingMicroAmount);

  // Creates a hotel ad group.
  String adGroupResourceName = addHotelAdGroup(googleAdsClient, customerId, campaignResourceName);

  // Creates a hotel ad group ad.
  addHotelAdGroupAd(googleAdsClient, customerId, adGroupResourceName);
}
C#
public void Run(GoogleAdsClient client, long customerId, long hotelCenterAccountId,
    long cpcBidCeilingMicroAmount)
{
    try
    {
        // Create a budget to be used by the campaign that will be created below.
        string budgetResourceName = AddCampaignBudget(client, customerId);

        // Create a hotel campaign.
        string campaignResourceName = AddHotelCampaign(client, customerId,
            budgetResourceName, hotelCenterAccountId, cpcBidCeilingMicroAmount);

        // Create a hotel ad group.
        string adGroupResourceName = AddHotelAdGroup(client, customerId,
            campaignResourceName);

        // Create a hotel ad group ad.
        AddHotelAdGroupAd(client, customerId, adGroupResourceName);
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
    }
}
PHP
private static function addHotelCampaign(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $budgetResourceName,
    $hotelCenterAccountId,
    $cpcBidCeilingMicroAmount
) {
    // Creates a campaign.
    $campaign = new Campaign([
        'name' => new StringValue(['value' => 'Interplanetary Cruise Campaign #' . uniqid()]),
        // Configures settings related to hotel campaigns including advertising channel type
        // and hotel setting info.
        'advertising_channel_type' => AdvertisingChannelType::HOTEL,
        'hotel_setting' => new HotelSettingInfo([
            'hotel_center_id' => new Int64Value(['value' => $hotelCenterAccountId])
        ]),
        // 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 PercentCpc. Only Manual CPC and Percent CPC can be used
        // for hotel campaigns.
        'percent_cpc' => new PercentCpc([
            'cpc_bid_ceiling_micros' => new Int64Value(['value' => $cpcBidCeilingMicroAmount])
        ]),
        // Sets the budget.
        'campaign_budget' => new StringValue(['value' => $budgetResourceName]),
        // Configures the campaign network options. Only Google Search is allowed for
        // hotel campaigns.
        'network_settings' => new NetworkSettings([
            'target_google_search' => new BoolValue(['value' => true]),
        ]),
    ]);

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

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

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

    return $addedCampaign->getResourceName();
}
Python
def add_hotel_campaign(client, customer_id, budget_resource_name,
                       hotel_center_account_id, bid_ceiling_micro_amount):
    campaign_service = client.get_service('CampaignService', version='v1')

    # Create campaign.
    campaign_operation = client.get_type('CampaignOperation', version='v1')
    campaign = campaign_operation.create
    campaign.name.value = 'Interplanetary Cruise Campaign %s' % uuid.uuid4()

    # Configures settings related to hotel campaigns including advertising
    # channel type and hotel setting info.
    campaign.advertising_channel_type = client.get_type(
        'AdvertisingChannelTypeEnum').HOTEL
    campaign.hotel_setting.hotel_center_id.value = hotel_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.get_type('CampaignStatusEnum', version='v1').PAUSED

    # Set the bidding strategy to PercentCpc. Only Manual CPC and Percent CPC
    # can be used for hotel campaigns.
    campaign.percent_cpc.cpc_bid_ceiling_micros.value = (
        bid_ceiling_micro_amount)

    # Sets the budget.
    campaign.campaign_budget.value = budget_resource_name

    # Set the campaign network options. Only Google Search is allowed for hotel
    # campaigns.
    campaign.network_settings.target_google_search.value = True

    # Add the campaign.
    try:
        campaign_response = campaign_service.mutate_campaigns(
            customer_id, [campaign_operation])
    except google.ads.google_ads.errors.GoogleAdsException as ex:
        print('Request with ID "%s" failed with status "%s" and includes the '
              'following errors:' % (ex.request_id, ex.error.code().name))
        for error in ex.failure.errors:
            print('\tError with message "%s".' % error.message)
            if error.location:
                for field_path_element in error.location.field_path_elements:
                    print('\t\tOn field: %s' % field_path_element.field_name)
        sys.exit(1)

    campaign_resource_name = campaign_response.results[0].resource_name

    print('Added a hotel campaign with resource name "%s".'
          % campaign_resource_name)

    return campaign_resource_name
Ruby
def add_hotel_campaign(client, customer_id, budget_resource,
    hotel_center_account_id, cpc_bid_ceiling_micro_amount)
  # Create a campaign.
  campaign = client.resource(:Campaign)
  campaign.name = generate_random_name_field(client,
      'Interplanetary Cruise Campaign')

  # Configure settings related to hotel campaigns.
  campaign.advertising_channel_type =
      client.enum(:AdvertisingChannelType)::HOTEL
  hotel_setting_info = client.resource(:HotelSettingInfo)
  hotel_setting_info.hotel_center_id =
      client.wrapper.int64(hotel_center_account_id)
  campaign.hotel_setting = hotel_setting_info

  # 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.enum(:CampaignStatus)::PAUSED

  # Set the bidding strategy to PercentCpc. Only Manual CPC and Percent CPC can
  # be used for hotel campaigns.
  campaign.percent_cpc = client.resource(:PercentCpc)
  campaign.percent_cpc.cpc_bid_ceiling_micros =
      client.wrapper.int64(cpc_bid_ceiling_micro_amount)

  # Set the budget.
  campaign.campaign_budget = client.wrapper.string(budget_resource)

  # Configures the campaign network options. Only Google Search is allowed for
  # hotel campaigns.
  network_settings = client.resource(:NetworkSettings)
  network_settings.target_google_search = client.wrapper.bool(true)
  campaign.network_settings = network_settings

  # Create a campaign operation.
  campaign_operation = client.operation(:Campaign)
  campaign_operation['create'] = campaign

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

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

  puts sprintf('Added hotel campaign with resource name "%s".',
      campaign_resource)

  return campaign_resource
end

Envoyer des commentaires concernant…

Besoin d'aide ? Consultez notre page d'assistance.