制作自适应展示广告

与其他广告一样,广告制作是通过使用 AdGroupAdService.MutateAdGroupAds 完成的。然后,您可以将自适应展示广告添加到标准展示广告系列。

广告制作

如需制作自适应展示广告,请在父级 Ad 资源中填充 final_urls(至少 1 个网址),并在 ResponsiveDisplayAdInfo 中填充以下必需字段:

  • marketing_images:一个重复的横向AdImageAsset 对象列表(至少需要 1 个;宽高比为 1.91:1,最小尺寸为 600x314 像素;最多可与 square_marketing_images 合计 15 个)。
  • square_marketing_images:一个重复的方形 AdImageAsset 对象列表(至少需要 1 个;宽高比为 1:1,最小尺寸为 300x300 像素;最多可与 marketing_images 组合使用 15 个)。
  • headlines:一个重复列表,包含 1 到 5 个 AdTextAsset 对象(每个对象最多 30 个字符)。
  • long_headline:一条 AdTextAsset 消息(最多 90 个字符)。
  • descriptions:一个重复列表,包含 1 到 5 个 AdTextAsset 对象(每个对象最多 90 个字符)。
  • business_name:一个最多包含 25 个字符的字符串。

如需了解所有其他字段和图片规范,请参阅ResponsiveDisplayAdInfo参考页面和帮助中心文章。

Java

private void createAd(
    GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName)
    throws IOException {
  String marketingImageUrl = "https://gaagl.page.link/Eit5";
  String marketingImageName = "Marketing Image";
  String marketingImageResourceName =
      uploadAsset(googleAdsClient, customerId, marketingImageUrl, marketingImageName);
  String squareMarketingImageName = "Square Marketing Image";
  String squareMarketingImageUrl = "https://gaagl.page.link/bjYi";
  String squareMarketingImageResourceName =
      uploadAsset(googleAdsClient, customerId, squareMarketingImageUrl, squareMarketingImageName);

  // Creates the responsive display ad info object.
  ResponsiveDisplayAdInfo responsiveDisplayAdInfo =
      ResponsiveDisplayAdInfo.newBuilder()
          .addMarketingImages(
              AdImageAsset.newBuilder().setAsset(marketingImageResourceName).build())
          .addSquareMarketingImages(
              AdImageAsset.newBuilder().setAsset(squareMarketingImageResourceName).build())
          .addHeadlines(AdTextAsset.newBuilder().setText("Travel").build())
          .setLongHeadline(AdTextAsset.newBuilder().setText("Travel the World").build())
          .addDescriptions(AdTextAsset.newBuilder().setText("Take to the air!").build())
          .setBusinessName("Interplanetary Cruises")
          // Optional: Call to action text.
          // Valid texts: https://support.google.com/adwords/answer/7005917
          .setCallToActionText("Apply Now")
          // Optional: Sets the ad colors.
          .setMainColor("#0000ff")
          .setAccentColor("#ffff00")
          // Optional: Sets to false to strictly render the ad using the colors.
          .setAllowFlexibleColor(false)
          // Optional: Sets the format setting that the ad will be served in.
          .setFormatSetting(DisplayAdFormatSetting.NON_NATIVE)
          // Optional: Creates a logo image and sets it to the ad.
          /*
          .addLogoImages(
              AdImageAsset.newBuilder()
                  .setAsset(StringValue.of("INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"))
                  .build())
          */
          // Optional: Creates a square logo image and sets it to the ad.
          /*
          .addSquareLogoImages(
              AdImageAsset.newBuilder()
                  .setAsset(StringValue.of("INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"))
                  .build())
          */
          .build();

  // Creates the ad.
  Ad ad =
      Ad.newBuilder()
          .setResponsiveDisplayAd(responsiveDisplayAdInfo)
          .addFinalUrls("http://www.example.com/")
          .build();

  // Creates the ad group ad.
  AdGroupAd adGroupAd = AdGroupAd.newBuilder().setAdGroup(adGroupResourceName).setAd(ad).build();

  // Creates the ad group ad operation.
  AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();

  // Creates the ad group ad service client.
  try (AdGroupAdServiceClient adGroupAdServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {
    // Adds the ad group ad.
    MutateAdGroupAdsResponse response =
        adGroupAdServiceClient.mutateAdGroupAds(
            Long.toString(customerId), ImmutableList.of(operation));
    System.out.printf(
        "Created ad group ad with resource name '%s'.%n",
        response.getResults(0).getResourceName());
  }
}

      

C#

private void CreateAd(GoogleAdsClient client, long customerId, string adGroupResourceName)
{
    // Creates the ad group ad service client.
    AdGroupAdServiceClient adGroupAdServiceClient =
        client.GetService(Services.V25.AdGroupAdService);

    string marketingImageUrl = "https://gaagl.page.link/Eit5";
    string marketingImageName = "Marketing Image";
    string marketingImageResourceName =
        UploadAsset(client, customerId, marketingImageUrl, marketingImageName);
    string squareMarketingImageName = "Square Marketing Image";
    string squareMarketingImageUrl = "https://gaagl.page.link/bjYi";
    string squareMarketingImageResourceName =
        UploadAsset(client, customerId, squareMarketingImageUrl, squareMarketingImageName);

    // Creates the responsive display ad info object.
    ResponsiveDisplayAdInfo responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo()
    {
        MarketingImages =
        {
            new AdImageAsset()
            {
                Asset = marketingImageResourceName
            }
        },
        SquareMarketingImages =
        {
            new AdImageAsset()
            {
                Asset = squareMarketingImageResourceName
            }
        },
        Headlines =
        {
            new AdTextAsset()
            {
                Text = "Travel"
            }
        },
        LongHeadline = new AdTextAsset()
        {
            Text = "Travel the World"
        },
        Descriptions =
        {
            new AdTextAsset()
            {
                Text = "Take to the air!"
            }
        },
        BusinessName = "Interplanetary Cruises",
        // Optional: Call to action text.
        // Valid texts: https://support.google.com/adwords/answer/7005917
        CallToActionText = "Apply Now",
        // Optional: Sets the ad colors.
        MainColor = "#0000ff",
        AccentColor = "#ffff00",
        // Optional: Sets to false to strictly render the ad using the colors.
        AllowFlexibleColor = false,
        // Optional: Sets the format setting that the ad will be served in.
        FormatSetting = DisplayAdFormatSetting.NonNative,
        // Optional: Creates a logo image and sets it to the ad.
        /*
            LogoImages = { new AdImageAsset()
            {
                Asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
            }}
        */
        // Optional: Creates a square logo image and sets it to the ad.
        /*
            SquareLogoImages = { new AdImageAsset()
            {
                Asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
            }}
        */
    };

    // Creates the ad.
    Ad ad = new Ad()
    {
        ResponsiveDisplayAd = responsiveDisplayAdInfo,
        FinalUrls = { "http://www.example.com/" }
    };

    // Creates the ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd()
    {
        AdGroup = adGroupResourceName,
        Ad = ad
    };

    // Creates the ad group ad operation.
    AdGroupAdOperation operation = new AdGroupAdOperation()
    {
        Create = adGroupAd
    };

    // Adds the ad group ad.
    MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds
        (customerId.ToString(), new[] { operation });
    Console.WriteLine("Created ad group ad with resource name " +
                      $"'{response.Results.First().ResourceName}'.");
}
      

PHP

    private static function createAd(
        GoogleAdsClient $googleAdsClient,
        int $customerId,
        string $adGroupResourceName
    ) {
        $marketingImageResourceName = self::uploadAsset(
            $googleAdsClient,
            $customerId,
            'https://gaagl.page.link/Eit5',
            'Marketing Image'
        );
        $squareMarketingImageResourceName = self::uploadAsset(
            $googleAdsClient,
            $customerId,
            'https://gaagl.page.link/bjYi',
            'Square Marketing Image'
        );

        // Creates the responsive display ad info object.
        $responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo(
            [
            'marketing_images' => [new AdImageAsset(['asset' => $marketingImageResourceName])],
            'square_marketing_images' => [new AdImageAsset(
                [
                'asset' => $squareMarketingImageResourceName
                ]
            )],
            'headlines' => [new AdTextAsset(['text' => 'Travel'])],
            'long_headline' => new AdTextAsset(['text' => 'Travel the World']),
            'descriptions' => [new AdTextAsset(['text' => 'Take to the air!'])],
            'business_name' => 'Interplanetary Cruises',
            // Optional: Call to action text.
            // Valid texts: https://support.google.com/google-ads/answer/7005917
            'call_to_action_text' => 'Apply Now',
            // Optional: Sets the ad colors.
            'main_color' => '#0000ff',
            'accent_color' => '#ffff00',
            // Optional: Sets to false to strictly render the ad using the colors.
            'allow_flexible_color' => false,
            // Optional: Sets the format setting that the ad will be served in.
            'format_setting' => DisplayAdFormatSetting::NON_NATIVE
            // Optional: Creates a logo image and sets it to the ad.
            // 'logo_images' => [new AdImageAsset([
            //     'asset' => 'INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE'
            // ])],
            // Optional: Creates a square logo image and sets it to the ad.
            // 'square_logo_images' => [new AdImageAsset([
            //     'asset' => 'INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE'
            // ])]
            ]
        );

        // Creates a new ad group ad.
        $adGroupAd = new AdGroupAd(
            [
            'ad' => new Ad(
                [
                'responsive_display_ad' => $responsiveDisplayAdInfo,
                'final_urls' => ['http://www.example.com/']
                ]
            ),
            'ad_group' => $adGroupResourceName
            ]
        );

        // Creates an ad group ad operation.
        $adGroupAdOperation = new AdGroupAdOperation();
        $adGroupAdOperation->setCreate($adGroupAd);

        // Issues a mutate request to add the ad group ad.
        $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
        $response = $adGroupAdServiceClient->mutateAdGroupAds(
            MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation])
        );

        /**
 * @var AdGroupAd $addedAdGroupAd
*/
        $addedAdGroupAd = $response->getResults()[0];
        printf(
            "Created ad group ad with resource name '%s'.%s",
            $addedAdGroupAd->getResourceName(),
            PHP_EOL
        );
    }
      

Python

def create_ad(
    client: GoogleAdsClient, customer_id: str, ad_group_resource_name: str
) -> None:
    """Creates the responsive display ad.

    Args:
        client: An initialized GoogleAds client.
        customer_id: The Google Ads customer ID.
        ad_group_resource_name: The resource name of the target ad group.
    """
    # Get the AdGroupAdService client.
    ad_group_ad_service: AdGroupAdServiceClient = client.get_service(
        "AdGroupAdService"
    )

    # Upload image assets for the ad.
    marketing_image_resource_name: str = upload_image_asset(
        client, customer_id, "https://gaagl.page.link/Eit5", "Marketing Image"
    )
    square_marketing_image_resource_name: str = upload_image_asset(
        client,
        customer_id,
        "https://gaagl.page.link/bjYi",
        "Square Marketing Image",
    )

    # Create the relevant asset objects for the ad.
    marketing_image: AdImageAsset = client.get_type("AdImageAsset")
    marketing_image.asset = marketing_image_resource_name
    square_marketing_image: AdImageAsset = client.get_type("AdImageAsset")
    square_marketing_image.asset = square_marketing_image_resource_name
    headline: AdTextAsset = client.get_type("AdTextAsset")
    headline.text = "Travel"
    description: AdTextAsset = client.get_type("AdTextAsset")
    description.text = "Take to the air!"

    # Create an ad group ad operation and set the ad group ad values.
    ad_group_ad_operation: AdGroupAdOperation = client.get_type(
        "AdGroupAdOperation"
    )
    ad_group_ad: AdGroupAd = ad_group_ad_operation.create
    ad_group_ad.ad_group = ad_group_resource_name
    ad_group_ad.ad.final_urls.append("http://www.example.com/")

    # Configure the responsive display ad info object.
    responsive_display_ad_info: ResponsiveDisplayAdInfo = (
        ad_group_ad.ad.responsive_display_ad
    )
    responsive_display_ad_info.marketing_images.append(marketing_image)
    responsive_display_ad_info.square_marketing_images.append(
        square_marketing_image
    )
    responsive_display_ad_info.headlines.append(headline)
    responsive_display_ad_info.long_headline.text = "Travel the World"
    responsive_display_ad_info.descriptions.append(description)
    responsive_display_ad_info.business_name = "Interplanetary Cruises"
    # Optional: Call to action text.
    # Valid texts: https://support.google.com/google-ads/answer/7005917
    responsive_display_ad_info.call_to_action_text = "Apply Now"
    # Optional: Set the ad colors.
    responsive_display_ad_info.main_color = "#0000ff"
    responsive_display_ad_info.accent_color = "#ffff00"
    # Optional: Set to false to strictly render the ad using the colors.
    responsive_display_ad_info.allow_flexible_color = False
    # Optional: Set the format setting that the ad will be served in.
    responsive_display_ad_info.format_setting = (
        client.enums.DisplayAdFormatSettingEnum.NON_NATIVE
    )
    # Optional: Create a logo image and set it to the ad.
    # logo_image = client.get_type("AdImageAsset")
    # logo_image.asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
    # responsive_display_ad_info.logo_images.append(logo_image)
    # Optional: Create a square logo image and set it to the ad.
    # square_logo_image = client.get_type("AdImageAsset")
    # square_logo_image.asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
    # responsive_display_ad_info.square_logo_images.append(square_logo_image)

    # Issue a mutate request to add the ad group ad.
    ad_group_ad_response: MutateAdGroupAdsResponse = (
        ad_group_ad_service.mutate_ad_group_ads(
            customer_id=customer_id, operations=[ad_group_ad_operation]
        )
    )
    print(
        "Created ad group ad with resource name "
        f"'{ad_group_ad_response.results[0].resource_name}'."
    )
      

Ruby

def create_ad(client, customer_id, ad_group_resource_name)
  marketing_image_url = "https://gaagl.page.link/Eit5"
  square_marketing_image_url = "https://gaagl.page.link/bjYi"
  marketing_image_asset_resource_name = upload_asset(
    client, customer_id, marketing_image_url, "Marketing Image"
  )
  square_marketing_image_asset_resource_name = upload_asset(
    client, customer_id, square_marketing_image_url, "Square Marketing Image"
  )

  # Creates an ad group ad operation.
  operation = client.operation.create_resource.ad_group_ad do |aga|
    aga.ad_group = ad_group_resource_name
    aga.status = :PAUSED
    aga.ad = client.resource.ad do |a|
      a.final_urls << "https://www.example.com"

      # Creates the responsive display ad info object.
      a.responsive_display_ad = client.resource.responsive_display_ad_info do |rda|
        rda.headlines << client.resource.ad_text_asset do |ata|
          ata.text = "Travel"
        end
        rda.long_headline = client.resource.ad_text_asset do |ata|
          ata.text = "Travel the World"
        end
        rda.descriptions << client.resource.ad_text_asset do |ata|
          ata.text = "Take to the air!"
        end
        rda.business_name = "Interplanetary Cruises"
        rda.marketing_images << client.resource.ad_image_asset do |aia|
          aia.asset = marketing_image_asset_resource_name
        end
        rda.square_marketing_images << client.resource.ad_image_asset do |aia|
          aia.asset = square_marketing_image_asset_resource_name
        end
        # Optional: Call to action text.
        # Valid texts: https://support.google.com/google-ads/answer/7005917
        rda.call_to_action_text = "Apply Now"
        # Optional: Sets the ad colors.
        rda.main_color = "#0000ff"
        rda.accent_color = "#ffff00"
        # Optional: Sets to false to strictly render the ad using the colors.
        rda.allow_flexible_color = false
        # Optional: Sets the format setting that the ad will be served in.
        rda.format_setting = :NON_NATIVE
        # Optional: Creates a logo image and sets it to the ad.
        # rda.logo_images << client.resource.ad_image_asset do |aia|
        #   aia.asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
        # end
        # Optional: Creates a square logo image and sets it to the ad.
        # rda.square_logo_images << client.resource.ad_image_asset do |aia|
        #   aia.asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
        # end
      end
    end
  end

  # Issues a mutate request to add the ad group ad.
  response = client.service.ad_group_ad.mutate_ad_group_ads(
    customer_id: customer_id,
    operations: [operation]
  )

  # Prints out some information about the newly created ad.
  resource_name = response.results.first.resource_name
  puts "Created ad group ad: #{resource_name}"

  resource_name
end
      

Perl

sub create_ad {
  my ($api_client, $customer_id, $ad_group_resource_name) = @_;

  my $marketing_image_resource_name = upload_asset(
    $api_client, $customer_id,
    "https://gaagl.page.link/Eit5",
    "Marketing Image"
  );

  my $square_marketing_image_resource_name = upload_asset(
    $api_client, $customer_id,
    "https://gaagl.page.link/bjYi",
    "Square Marketing Image"
  );

  # Create the responsive display ad info object.
  my $responsive_display_ad_info =
    Google::Ads::GoogleAds::V25::Common::ResponsiveDisplayAdInfo->new({
      marketingImages => [
        Google::Ads::GoogleAds::V25::Common::AdImageAsset->new({
            asset => $marketing_image_resource_name
          })
      ],
      squareMarketingImages => [
        Google::Ads::GoogleAds::V25::Common::AdImageAsset->new({
            asset => $square_marketing_image_resource_name
          })
      ],
      headlines => [
        Google::Ads::GoogleAds::V25::Common::AdTextAsset->new({
            text => "Travel"
          })
      ],
      longHeadline => Google::Ads::GoogleAds::V25::Common::AdTextAsset->new({
          text => "Travel the World"
        }
      ),
      descriptions => [
        Google::Ads::GoogleAds::V25::Common::AdTextAsset->new({
            text => "Take to the air!"
          })
      ],
      businessName => "Interplanetary Cruises",
      # Optional: Call to action text.
      # Valid texts: https://support.google.com/google-ads/answer/7005917
      callToActionText => "Apply Now",
      # Optional: Set the ad colors.
      mainColor   => "#0000ff",
      accentColor => "#ffff00",
      # Optional: Set to false to strictly render the ad using the colors.
      allowFlexibleColor => "false",
      # Optional: Set the format setting that the ad will be served in.
      formatSetting => NON_NATIVE,
      # Optional: Create a logo image and set it to the ad.
      # logoImages => [
      #   Google::Ads::GoogleAds::V25::Common::AdImageAsset->new({
      #       asset => "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
      #     })
      # ],
      # Optional: Create a square logo image and set it to the ad.
      # squareLogoImages => [
      #   Google::Ads::GoogleAds::V25::Common::AdImageAsset->new({
      #       asset => "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
      #     })
      # ]
    });

  # Create an ad group ad.
  my $ad_group_ad = Google::Ads::GoogleAds::V25::Resources::AdGroupAd->new({
      adGroup => $ad_group_resource_name,
      ad      => Google::Ads::GoogleAds::V25::Resources::Ad->new({
          responsiveDisplayAd => $responsive_display_ad_info,
          finalUrls           => ["http://www.example.com/"]})});

  # Create an ad group ad operation.
  my $ad_group_ad_operation =
    Google::Ads::GoogleAds::V25::Services::AdGroupAdService::AdGroupAdOperation
    ->new({create => $ad_group_ad});

  # Issue a mutate request to add the ad group ad.
  my $ad_group_ads_response = $api_client->AdGroupAdService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_ad_operation]});

  printf "Created ad group ad with resource name '%s'.\n",
    $ad_group_ads_response->{results}[0]{resourceName};
}
      

curl

高级功能

颜色控制
您可以指定 main_color 和 accent_color 作为 6 位十六进制颜色字符串(例如 #ffffff),从而自定义自适应展示广告的颜色,以满足您的品牌推广需求。设置 main_color 或 accent_color 时,必须同时设置另一个。如果您希望广告在必要时以优化后的颜色(而非您指定的颜色)投放,请将 allow_flexible_color(默认值为 true)设置为 true;如果未设置 main_color 和 accent_color,则 allow_flexible_color 必须为 true。
展示广告格式设置

自适应展示广告可以采用 ALL_FORMATS(默认)、NATIVE 或 NON_NATIVE 格式投放。 NATIVE 格式的呈现由发布商控制,而 NON_NATIVE 格式的呈现则由 Google 模型使用广告客户的输入内容(例如来自 main_color 和 accent_color 的颜色信息)进行优化。

您可以设置 format_setting 字段来选择广告的投放格式。不过,当 allow_flexible_color 为 false 时,您无法将 format_setting 设置为 NATIVE,因为对于 NATIVE 格式,着色由发布商控制。

广告控制选项

自适应展示广告可以通过 control_spec 字段(例如 enable_asset_enhancements 和 enable_autogen_video)指定是否选择启用自动生成的视频或素材资源增强功能。