示例:使用 Google Merchant Center 制作动态再营销广告系列

在本示例中,您有一个零售网站,该网站会将商品详情上传到 Google Merchant Center,并且您希望向访问过该零售网站的用户再营销一组商品。这些用户可能访问过商品页面,或者将商品放入购物车或结账,这些行为会触发再营销代码。然后,您可以制作一个广告系列,仅定位此用户群组,或者扩大到类似受众群体,以扩大覆盖面。

详细了解生成受众群体名单的最佳 做法

您需要以下内容才能设置此类广告系列:

  1. 再营销名单
  2. Merchant Center 账号
  3. 商品 Feed 来自 Merchant Center。
  4. 展示广告自适应广告所需的媒体资源 。

以下是支持 Merchant Center 商品 Feed 的广告素材列表:

第 1 步 - 制作与 Merchant Center 商品 Feed 相关联的广告系列

如需再营销零售商品,您需要制作一个 定位到展示广告 网络的广告系列。这需要以下内容:

  • 一个 CampaignBudget,用于指定广告系列 能够支出的金额。
  • 一个 UserList,其中包含要通过 广告系列定位的用户列表。
  • 一个 ShoppingSetting,用于指定哪个 Merchant Center 账号将用于广告系列的商品 Feed。

配置广告系列的基本步骤如下:

  1. 制作新广告系列,并将 AdvertisingChannelType 设置为 DISPLAY

  2. 为广告系列设置 CampaignBudget。这可以是新创建的预算,也可以是共享预算。

  3. 设置 ShoppingSetting for the campaign。请注意,此处使用的是 CampaignService,而不是 AdGroupService,因为 Feed 必须在广告系列一级附加。

  4. 应用 mutate 操作,将新广告系列添加到账号。

代码示例

Java

private String createCampaign(
    GoogleAdsClient googleAdsClient,
    long customerId,
    long merchantCenterAccountId,
    long campaignBudgetId) {
  String budgetResourceName = ResourceNames.campaignBudget(customerId, campaignBudgetId);

  // Creates the campaign.
  Campaign campaign =
      Campaign.newBuilder()
          .setName("Shopping campaign #" + getPrintableDateTime())
          // Dynamic remarketing campaigns are only available on the Google Display Network.
          .setAdvertisingChannelType(AdvertisingChannelType.DISPLAY)
          .setStatus(CampaignStatus.PAUSED)
          .setCampaignBudget(budgetResourceName)
          .setManualCpc(ManualCpc.newBuilder().build())
          // The settings for the shopping campaign.
          // This connects the campaign to the merchant center account.
          .setShoppingSetting(
              ShoppingSetting.newBuilder()
                  .setCampaignPriority(0)
                  .setMerchantId(merchantCenterAccountId)
                  .setEnableLocal(true)
                  .build())
          // Declares whether this campaign serves political ads targeting the EU.
          .setContainsEuPoliticalAdvertising(DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING)
          .build();

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

  // Creates the campaign service client.
  try (CampaignServiceClient campaignServiceClient =
      googleAdsClient.getLatestVersion().createCampaignServiceClient()) {
    // Adds the campaign.
    MutateCampaignsResponse response =
        campaignServiceClient.mutateCampaigns(
            Long.toString(customerId), ImmutableList.of(operation));
    String campaignResourceName = response.getResults(0).getResourceName();
    System.out.printf("Created campaign with resource name '%s'.%n", campaignResourceName);
    return campaignResourceName;
  }
}

      

C#

private string CreateCampaign(GoogleAdsClient client, long customerId,
    long merchantCenterAccountId, long campaignBudgetId)
{
    // Creates the Campaign Service client.
    CampaignServiceClient campaignServiceClient =
        client.GetService(Services.V23.CampaignService);

    string budgetResourceName = ResourceNames.CampaignBudget(customerId, campaignBudgetId);

    // Creates the campaign.
    Campaign campaign = new Campaign()
    {
        Name = "Shopping campaign #" + ExampleUtilities.GetRandomString(),
        // Dynamic remarketing campaigns are only available on the Google Display Network.
        AdvertisingChannelType = AdvertisingChannelType.Display,
        Status = CampaignStatus.Paused,
        CampaignBudget = budgetResourceName,
        ManualCpc = new ManualCpc(),
        // The settings for the shopping campaign.
        // This connects the campaign to the Merchant Center account.
        ShoppingSetting = new Campaign.Types.ShoppingSetting()
        {
            CampaignPriority = 0,
            MerchantId = merchantCenterAccountId,
            EnableLocal = true
        },

        // Declare whether or not this campaign contains political ads targeting the EU.
        ContainsEuPoliticalAdvertising = EuPoliticalAdvertisingStatus.DoesNotContainEuPoliticalAdvertising,
    };

    // Creates the campaign operation.
    CampaignOperation operation = new CampaignOperation()
    {
        Create = campaign
    };

    // Adds the campaign.
    MutateCampaignsResponse response = campaignServiceClient.MutateCampaigns(customerId
        .ToString(), new[] { operation });
    string campaignResourceName = response.Results.First().ResourceName;
    Console.WriteLine($"Created campaign with resource name '{campaignResourceName}'.");
    return campaignResourceName;
}
      

PHP

private static function createCampaign(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    int $merchantCenterAccountId,
    int $campaignBudgetId
): string {
    // Configures the settings for the shopping campaign.
    $shoppingSettings = new ShoppingSetting([
        'campaign_priority' => 0,
        'merchant_id' => $merchantCenterAccountId,
        'enable_local' => true
    ]);

    // Creates the campaign.
    $campaign = new Campaign([
        'name' => 'Shopping campaign #' . Helper::getPrintableDatetime(),
        // Dynamic remarketing campaigns are only available on the Google Display Network.
        'advertising_channel_type' => AdvertisingChannelType::DISPLAY,
        'status' => CampaignStatus::PAUSED,
        'campaign_budget' => ResourceNames::forCampaignBudget($customerId, $campaignBudgetId),
        'manual_cpc' => new ManualCpc(),
        // Declare whether or not this campaign serves political ads targeting the EU.
        'contains_eu_political_advertising' =>
            EuPoliticalAdvertisingStatus::DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING
        // This connects the campaign to the merchant center account.
        'shopping_setting' => $shoppingSettings
    ]);

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

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

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

    return $addedCampaignResourceName;
}
      

Python

def create_campaign(
    client: GoogleAdsClient,
    customer_id: str,
    merchant_center_account_id: int,
    campaign_budget_id: int,
) -> str:
    """Creates a campaign linked to a Merchant Center product feed.

    Args:
        client: An initialized GoogleAds client.
        customer_id: The Google Ads customer ID.
        merchant_center_account_id: The target Merchant Center account ID.
        campaign_budget_id: The ID of the campaign budget to utilize.
    Returns:
        The string resource name of the newly created campaign.
    """
    # Gets the CampaignService client.
    campaign_service: CampaignServiceClient = client.get_service(
        "CampaignService"
    )

    # Creates a campaign operation and configures the new campaign.
    campaign_operation: CampaignOperation = client.get_type("CampaignOperation")
    campaign: Campaign = campaign_operation.create
    campaign.name = f"Shopping campaign #{uuid4()}"
    # Configures the settings for the shopping campaign.
    campaign.shopping_setting.campaign_priority = 0
    # This connects the campaign to the Merchant Center account.
    campaign.shopping_setting.merchant_id = merchant_center_account_id
    campaign.shopping_setting.enable_local = True
    # Dynamic remarketing campaigns are only available on the Google Display
    # Network.
    campaign.advertising_channel_type = (
        client.enums.AdvertisingChannelTypeEnum.DISPLAY
    )
    campaign.status = client.enums.CampaignStatusEnum.PAUSED
    campaign.campaign_budget = client.get_service(
        "CampaignBudgetService"
    ).campaign_budget_path(customer_id, str(campaign_budget_id))
    client.copy_from(campaign.manual_cpc, client.get_type("ManualCpc"))

    # Declare whether or not this campaign serves political ads targeting the
    # EU. Valid values are:
    #   CONTAINS_EU_POLITICAL_ADVERTISING
    #   DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING
    campaign.contains_eu_political_advertising = (
        client.enums.EuPoliticalAdvertisingStatusEnum.DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING
    )

    # Issues a mutate request to add the campaign.
    campaign_response: MutateCampaignsResponse = (
        campaign_service.mutate_campaigns(
            customer_id=customer_id, operations=[campaign_operation]
        )
    )
    campaign_resource_name: str = campaign_response.results[0].resource_name
    print(f"Created campaign with resource name '{campaign_resource_name}'.")

    return campaign_resource_name
      

Ruby

def create_campaign(client, customer_id, merchant_center_id, campaign_budget_id)
  operation = client.operation.create_resource.campaign do |c|
    c.name = "Shopping campaign ##{(Time.new.to_f * 1000).to_i}"

    # Dynamic remarketing campaigns are only available on the Google Display
    # Network.
    c.advertising_channel_type = :DISPLAY
    c.status = :PAUSED
    c.campaign_budget = client.path.campaign_budget(customer_id,
                                                    campaign_budget_id)
    c.manual_cpc = client.resource.manual_cpc

    # Declare whether or not this campaign serves political ads targeting the EU.
    # Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and
    # DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.
    c.contains_eu_political_advertising = :DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING

    # The settings for the shopping campaign.
    # This connects the campaign to the merchant center account.
    c.shopping_setting = client.resource.shopping_setting do |ss|
      ss.campaign_priority = 0
      ss.merchant_id = merchant_center_id.to_i
      ss.enable_local = true
    end
  end

  response = client.service.campaign.mutate_campaigns(
    customer_id: customer_id,
    operations: [operation]
  )

  puts "Created campaign: #{response.results.first.resource_name}"
  response.results.first.resource_name
end
      

Perl

sub create_campaign {
  my ($api_client, $customer_id, $merchant_center_account_id,
    $campaign_budget_id)
    = @_;

  # Configure the settings for the shopping campaign.
  my $shopping_settings =
    Google::Ads::GoogleAds::V24::Resources::ShoppingSetting->new({
      campaignPriority => 0,
      merchantId       => $merchant_center_account_id,
      enableLocal      => "true"
    });

  # Create the campaign.
  my $campaign = Google::Ads::GoogleAds::V24::Resources::Campaign->new({
      name => "Shopping campaign #" . uniqid(),
      # Dynamic remarketing campaigns are only available on the Google Display Network.
      advertisingChannelType => DISPLAY,
      status => Google::Ads::GoogleAds::V24::Enums::CampaignStatusEnum::PAUSED,
      campaignBudget =>
        Google::Ads::GoogleAds::V24::Utils::ResourceNames::campaign_budget(
        $customer_id, $campaign_budget_id
        ),
      manualCpc => Google::Ads::GoogleAds::V24::Common::ManualCpc->new(),
      # This connects the campaign to the Merchant Center account.
      shoppingSetting => $shopping_settings,
      # Declare whether or not this campaign serves political ads targeting the EU.
      # Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and
      # DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.
      containsEuPoliticalAdvertising =>
        DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING
    });

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

  # Issue a mutate request to add the campaign.
  my $campaigns_response = $api_client->CampaignService()->mutate({
      customerId => $customer_id,
      operations => [$campaign_operation]});

  my $campaign_resource_name = $campaigns_response->{results}[0]{resourceName};
  printf "Created campaign with resource name '%s'.\n", $campaign_resource_name;

  return $campaign_resource_name;
}
      

curl

第 2 步 - 为再营销广告系列制作广告组

代码示例

Java

private String createAdGroup(
    GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {
  // Creates the ad group.
  AdGroup adGroup =
      AdGroup.newBuilder()
          .setName("Dynamic remarketing ad group")
          .setCampaign(campaignResourceName)
          .setStatus(AdGroupStatus.ENABLED)
          .build();

  // Creates the ad group operation.
  AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();

  // Creates the ad group service client.
  try (AdGroupServiceClient adGroupServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {
    // Adds the ad group.
    MutateAdGroupsResponse response =
        adGroupServiceClient.mutateAdGroups(
            Long.toString(customerId), ImmutableList.of(operation));
    String adGroupResourceName = response.getResults(0).getResourceName();
    System.out.printf("Created ad group with resource name '%s'.%n", adGroupResourceName);
    return adGroupResourceName;
  }
}

      

C#

private string CreateAdGroup(GoogleAdsClient client, long customerId,
    string campaignResourceName)
{
    // Creates the ad group service client.
    AdGroupServiceClient adGroupServiceClient =
        client.GetService(Services.V23.AdGroupService);

    // Creates the ad group.
    AdGroup adGroup = new AdGroup()
    {
        Name = "Dynamic remarketing ad group",
        Campaign = campaignResourceName,
        Status = AdGroupStatus.Enabled
    };

    // Creates the ad group operation.
    AdGroupOperation operation = new AdGroupOperation()
    {
        Create = adGroup
    };

    // Adds the ad group.
    MutateAdGroupsResponse response = adGroupServiceClient.MutateAdGroups(
        customerId.ToString(), new[] { operation });

    string adGroupResourceName = response.Results.First().ResourceName;
    Console.WriteLine($"Created ad group with resource name '{adGroupResourceName}'.");
    return adGroupResourceName;
}
      

PHP

private static function createAdGroup(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $campaignResourceName
): string {
    // Creates the ad group.
    $adGroup = new AdGroup([
        'name' => 'Dynamic remarketing ad group',
        'campaign' => $campaignResourceName,
        'status' => AdGroupStatus::ENABLED
    ]);

    // Creates an ad group operation.
    $adGroupOperation = new AdGroupOperation();
    $adGroupOperation->setCreate($adGroup);

    // Issues a mutate request to add the ad group.
    $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient();
    $response = $adGroupServiceClient->mutateAdGroups(
        MutateAdGroupsRequest::build($customerId, [$adGroupOperation])
    );

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

    return $addedAdGroupResourceName;
}
      

Python

def create_ad_group(
    client: GoogleAdsClient, customer_id: str, campaign_resource_name: str
) -> str:
    """Creates an ad group for the remarketing campaign.

    Args:
        client: An initialized GoogleAds client.
        customer_id: The Google Ads customer ID.
        campaign_resource_name: The resource name of the target campaign.
    Returns:
        The string resource name of the newly created ad group.
    """
    # Gets the AdGroupService.
    ad_group_service: AdGroupServiceClient = client.get_service(
        "AdGroupService"
    )

    # Creates an ad group operation and configures the new ad group.
    ad_group_operation: AdGroupOperation = client.get_type("AdGroupOperation")
    ad_group: AdGroup = ad_group_operation.create
    ad_group.name = "Dynamic remarketing ad group"
    ad_group.campaign = campaign_resource_name
    ad_group.status = client.enums.AdGroupStatusEnum.ENABLED

    # Issues a mutate request to add the ad group.
    ad_group_response: MutateAdGroupsResponse = (
        ad_group_service.mutate_ad_groups(
            customer_id=customer_id, operations=[ad_group_operation]
        )
    )
    ad_group_resource_name: str = ad_group_response.results[0].resource_name

    return ad_group_resource_name
      

Ruby

def create_ad_group(client, customer_id, campaign_resource_name)
  # Creates the ad group.
  ad_group = client.resource.ad_group do |ag|
    ag.name = "Dynamic remarketing ad group #{(Time.now.to_f * 1000).to_i}"
    ag.campaign = campaign_resource_name
    ag.status = :ENABLED
  end

  # Creates the ad group operation.
  operation = client.operation.create_resource.ad_group(ad_group)
  response = client.service.ad_group.mutate_ad_groups(
    customer_id: customer_id,
    operations: [operation]
  )

  puts "Created ad group: #{response.results.first.resource_name}"
  response.results.first.resource_name
end
      

Perl

sub create_ad_group {
  my ($api_client, $customer_id, $campaign_resource_name) = @_;

  # Create the ad group.
  my $ad_group = Google::Ads::GoogleAds::V24::Resources::AdGroup->new({
    name     => "Dynamic remarketing ad group",
    campaign => $campaign_resource_name,
    status   => Google::Ads::GoogleAds::V24::Enums::AdGroupStatusEnum::ENABLED
  });

  # Create an ad group operation.
  my $ad_group_operation =
    Google::Ads::GoogleAds::V24::Services::AdGroupService::AdGroupOperation->
    new({create => $ad_group});

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

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

  return $ad_group_resource_name;
}
      

curl

第 3 步 - 制作自适应展示广告

代码示例

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.V23.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::V24::Common::ResponsiveDisplayAdInfo->new({
      marketingImages => [
        Google::Ads::GoogleAds::V24::Common::AdImageAsset->new({
            asset => $marketing_image_resource_name
          })
      ],
      squareMarketingImages => [
        Google::Ads::GoogleAds::V24::Common::AdImageAsset->new({
            asset => $square_marketing_image_resource_name
          })
      ],
      headlines => [
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text => "Travel"
          })
      ],
      longHeadline => Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
          text => "Travel the World"
        }
      ),
      descriptions => [
        Google::Ads::GoogleAds::V24::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::V24::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::V24::Common::AdImageAsset->new({
      #       asset => "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
      #     })
      # ]
    });

  # Create an ad group ad.
  my $ad_group_ad = Google::Ads::GoogleAds::V24::Resources::AdGroupAd->new({
      adGroup => $ad_group_resource_name,
      ad      => Google::Ads::GoogleAds::V24::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::V24::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

第 4 步 - 定位用户列表

代码示例

Java

private void attachUserList(
    GoogleAdsClient googleAdsClient,
    long customerId,
    String adGroupResourceName,
    long userListId) {
  String userListResourceName = ResourceNames.userList(customerId, userListId);
  // Creates the ad group criterion that targets the user list.
  AdGroupCriterion adGroupCriterion =
      AdGroupCriterion.newBuilder()
          .setAdGroup(adGroupResourceName)
          .setUserList(UserListInfo.newBuilder().setUserList(userListResourceName).build())
          .build();

  // Creates the ad group criterion operation.
  AdGroupCriterionOperation operation =
      AdGroupCriterionOperation.newBuilder().setCreate(adGroupCriterion).build();

  // Creates the ad group criterion service client.
  try (AdGroupCriterionServiceClient adGroupCriterionServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) {
    // Adds the ad group criterion.
    MutateAdGroupCriteriaResponse response =
        adGroupCriterionServiceClient.mutateAdGroupCriteria(
            Long.toString(customerId), ImmutableList.of(operation));
    System.out.printf(
        "Created ad group criterion with resource name '%s'.%n",
        response.getResults(0).getResourceName());
  }
}
      

C#

private void AttachUserList(GoogleAdsClient client, long customerId,
    string adGroupResourceName, long userListId)
{
    // Creates the ad group criterion service client.
    AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService
        (Services.V23.AdGroupCriterionService);

    string userListResourceName = ResourceNames.UserList(customerId, userListId);

    // Creates the ad group criterion that targets the user list.
    AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
    {
        AdGroup = adGroupResourceName,
        UserList = new UserListInfo()
        {
            UserList = userListResourceName
        }
    };

    // Creates the ad group criterion operation.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
    {
        Create = adGroupCriterion
    };

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

PHP

private static function attachUserList(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $adGroupResourceName,
    int $userListId
) {
    // Creates the ad group criterion that targets the user list.
    $adGroupCriterion = new AdGroupCriterion([
        'ad_group' => $adGroupResourceName,
        'user_list' => new UserListInfo([
            'user_list' => ResourceNames::forUserList($customerId, $userListId)
        ])
    ]);

    // Creates an ad group criterion operation.
    $adGroupCriterionOperation = new AdGroupCriterionOperation();
    $adGroupCriterionOperation->setCreate($adGroupCriterion);

    // Issues a mutate request to add the ad group criterion.
    $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient();
    $response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
        MutateAdGroupCriteriaRequest::build($customerId, [$adGroupCriterionOperation])
    );

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

Python

def attach_user_list(
    client: GoogleAdsClient,
    customer_id: str,
    ad_group_resource_name: str,
    user_list_id: int,
) -> None:
    """Targets a user list with an ad group.

    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.
        user_list_id: The ID of the user list to target for remarketing.
    """
    # Get the AdGroupCriterionService client.
    ad_group_criterion_service: AdGroupCriterionServiceClient = (
        client.get_service("AdGroupCriterionService")
    )

    # Create an ad group criterion operation and set the ad group criterion
    # values.
    ad_group_criterion_operation: AdGroupCriterionOperation = client.get_type(
        "AdGroupCriterionOperation"
    )
    ad_group_criterion: AdGroupCriterion = ad_group_criterion_operation.create
    ad_group_criterion.ad_group = ad_group_resource_name
    ad_group_criterion.user_list.user_list = client.get_service(
        "UserListService"
    ).user_list_path(customer_id, str(user_list_id))

    # Issue a mutate request to add the ad group criterion.
    ad_group_criterion_response: MutateAdGroupCriteriaResponse = (
        ad_group_criterion_service.mutate_ad_group_criteria(
            customer_id=customer_id, operations=[ad_group_criterion_operation]
        )
    )
    print(
        "Created ad group criterion with resource name "
        f"'{ad_group_criterion_response.results[0].resource_name}'."
    )
      

Ruby

def attach_user_list(client, customer_id, ad_group_resource_name, user_list_id)
  user_list_resource_name = client.path.user_list(customer_id, user_list_id)

  # Creates the ad group criterion that targets the user list.
  ad_group_criterion = client.resource.ad_group_criterion do |agc|
    agc.ad_group = ad_group_resource_name
    agc.user_list = client.resource.user_list_info do |ul|
      ul.user_list = user_list_resource_name
    end
  end

  # Creates the ad group criterion operation.
  op = client.operation.create_resource.ad_group_criterion(ad_group_criterion)

  response = client.service.ad_group_criterion.mutate_ad_group_criteria(
    customer_id: customer_id,
    operations: [op]
  )

  puts "Created ad group criterion: #{response.results.first.resource_name}"
end
      

Perl

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

  # Create the ad group criterion that targets the user list.
  my $ad_group_criterion =
    Google::Ads::GoogleAds::V24::Resources::AdGroupCriterion->new({
      adGroup  => $ad_group_resource_name,
      userList => Google::Ads::GoogleAds::V24::Common::UserListInfo->new({
          userList =>
            Google::Ads::GoogleAds::V24::Utils::ResourceNames::user_list(
            $customer_id, $user_list_id
            )})});

  # Create an ad group criterion operation.
  my $ad_group_criterion_operation =
    Google::Ads::GoogleAds::V24::Services::AdGroupCriterionService::AdGroupCriterionOperation
    ->new({create => $ad_group_criterion});

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

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

curl

为 Merchant Center Feed 设置动态再营销广告系列后,您可以使用 广告预览 工具从您的 Google Ads 账号中查看从 Merchant Center Feed 中提取的内容。