← 返回目录
来源:Google Ads API 官方文档 · 中文版 · 本地归档

创建广告组和广告组广告

本文档介绍了如何创建广告组,以及如何创建属于广告组的广告。

创建广告组

与之前步骤中创建的 Campaign 类似, 此广告组需要最少的配置,因为它会自动进行优化 。

智能广告系列广告组的主要要求:

在此示例中,我们将 campaign 字段设置为 在之前的步骤中用于创建广告系列的 临时资源名称。

Java

private MutateOperation createAdGroupOperation(long customerId) {
  MutateOperation.Builder builder = MutateOperation.newBuilder();
  builder
      .getAdGroupOperationBuilder()
      .getCreateBuilder()
      .setResourceName(ResourceNames.adGroup(customerId, AD_GROUP_TEMPORARY_ID))
      .setName("Smart campaign ad group " + CodeSampleHelper.getShortPrintableDateTime())
      .setCampaign(ResourceNames.campaign(customerId, SMART_CAMPAIGN_TEMPORARY_ID))
      .setType(AdGroupType.SMART_CAMPAIGN_ADS);
  return builder.build();
}
      

C#

/// <summary>
/// Creates a MutateOperation that creates a new ad group.
/// A temporary ID will be used in the campaign resource name for this ad group to
/// associate it with the Smart campaign created in earlier steps. A temporary ID will
/// also be used for its own resource name so that we can associate an ad group ad with
/// it later in the process.
/// Only one ad group can be created for a given Smart campaign.
/// </summary>
/// <param name="customerId">The Google Ads customer ID.</param>
/// <returns>A MutateOperation that creates a new ad group.</returns>
private MutateOperation CreateAdGroupOperation(long customerId)
{
    return new MutateOperation
    {
        AdGroupOperation = new AdGroupOperation
        {
            Create = new AdGroup
            {
                // Set the ad group ID to a temporary ID.
                ResourceName = ResourceNames.AdGroup(customerId, AD_GROUP_TEMPORARY_ID),
                Name = $"Smart campaign ad group #{ExampleUtilities.GetRandomString()}",
                // Set the campaign ID to a temporary ID.
                Campaign = ResourceNames.Campaign(customerId, SMART_CAMPAIGN_TEMPORARY_ID),
                // The ad group type must be SmartCampaignAds.
                Type = AdGroupType.SmartCampaignAds
            }
        }
    };
}
      

PHP

private static function createAdGroupOperation(int $customerId): MutateOperation
{
    // Creates the ad group object.
    $adGroup = new AdGroup([
        // Sets the ad group ID to a temporary ID.
        'resource_name' => ResourceNames::forAdGroup($customerId, self::AD_GROUP_TEMPORARY_ID),
        'name' => "Smart campaign ad group #" . Helper::getPrintableDatetime(),
        // Sets the campaign ID to a temporary ID.
        'campaign' =>
            ResourceNames::forCampaign($customerId, self::SMART_CAMPAIGN_TEMPORARY_ID),
        // The ad group type must be set to SMART_CAMPAIGN_ADS.
        'type' => AdGroupType::SMART_CAMPAIGN_ADS
    ]);

    // Creates the MutateOperation that creates the ad group.
    return new MutateOperation([
        'ad_group_operation' => new AdGroupOperation(['create' => $adGroup])
    ]);
}
在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →