Ví dụ: Tạo chiến dịch tái tiếp thị linh động bằng Google Merchant Center

Trong ví dụ này, bạn có một trang web bán lẻ tải trang thông tin sản phẩm lên Google Merchant Center và bạn muốn tái tiếp thị các nhóm sản phẩm cho những người dùng đã truy cập trang web bán lẻ. Những người dùng này có thể đã truy cập vào trang sản phẩm hoặc đặt mặt hàng trong giỏ hàng hoặc trang thanh toán, được ghi lại khi kích hoạt thẻ tái tiếp thị. Bạn sau đó, bạn có thể tạo một chiến dịch để chỉ nhắm mục tiêu đến nhóm này hoặc mở rộng thành nhóm tương tự để tăng phạm vi tiếp cận của bạn.

Đọc thêm về cách tạo danh sách đối tượng hiệu quả nhất .

Bạn sẽ cần có những yếu tố sau để thiết lập một chiến dịch như vậy:

  1. Danh sách tái tiếp thị.
  2. Tài khoản Merchant Center.
  3. Nguồn cấp dữ liệu sản phẩm từ người bán ở giữa.
  4. Yêu cầu về nội dung nghe nhìn cho Quảng cáo thích ứng cho Hiển thị.

Dưới đây là danh sách các mẫu quảng cáo hỗ trợ nguồn cấp dữ liệu sản phẩm trong Merchant Center:

Bước 1 – Tạo chiến dịch liên kết với nguồn cấp dữ liệu sản phẩm trong Merchant Center

Để có thể tái tiếp thị các sản phẩm bán lẻ, bạn cần phải tạo nhắm mục tiêu theo Hiển thị Mạng. Điều này sẽ yêu cầu sau:

  • CampaignBudget để chỉ định số tiền mà chiến dịch có thể chi tiêu hay không.
  • UserList bao gồm danh sách người dùng cần nhắm mục tiêu bằng chiến dịch.
  • ShoppingSetting để chỉ định Tài khoản Merchant Center mà nguồn cấp dữ liệu sản phẩm sẽ được sử dụng cho chiến dịch.

Các bước cơ bản để định cấu hình chiến dịch là:

  1. Tạo chiến dịch mới, đặt giá trị AdvertisingChannelType đến DISPLAY.

  2. Đặt CampaignBudget cho chiến dịch. Điều này có thể là ngân sách mới tạo hoặc ngân sách dùng chung.

  3. Đặt ShoppingSetting cho giá trị chiến dịch. Xin lưu ý rằng CampaignService được sử dụng ở đây, thay vì AdGroupService, bởi vì nguồn cấp dữ liệu phải được đính kèm ở cấp chiến dịch.

  4. Áp dụng thao tác thay đổi để thêm chiến dịch mới vào tài khoản.

Ví dụ về mã

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())
          .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.V17.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
        }
    };

    // 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(),
        // 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, customer_id, merchant_center_account_id, campaign_budget_id
):
    """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 = client.get_service("CampaignService")

    # Creates a campaign operation and configures the new campaign.
    campaign_operation = client.get_type("CampaignOperation")
    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, campaign_budget_id)
    client.copy_from(campaign.manual_cpc, client.get_type("ManualCpc"))

    # Issues a mutate request to add the campaign.
    campaign_response = campaign_service.mutate_campaigns(
        customer_id=customer_id, operations=[campaign_operation]
    )
    campaign_resource_name = 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

    # 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::V17::Resources::ShoppingSetting->new({
      campaignPriority => 0,
      merchantId       => $merchant_center_account_id,
      enableLocal      => "true"
    });

  # Create the campaign.
  my $campaign = Google::Ads::GoogleAds::V17::Resources::Campaign->new({
      name => "Shopping campaign #" . uniqid(),
      # Dynamic remarketing campaigns are only available on the Google Display Network.
      advertisingChannelType => DISPLAY,
      status => Google::Ads::GoogleAds::V17::Enums::CampaignStatusEnum::PAUSED,
      campaignBudget =>
        Google::Ads::GoogleAds::V17::Utils::ResourceNames::campaign_budget(
        $customer_id, $campaign_budget_id
        ),
      manualCpc => Google::Ads::GoogleAds::V17::Common::ManualCpc->new(),
      # This connects the campaign to the Merchant Center account.
      shoppingSetting => $shopping_settings
    });

  # Create a campaign operation.
  my $campaign_operation =
    Google::Ads::GoogleAds::V17::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;
}
      

Bước 2 – Tạo nhóm quảng cáo cho chiến dịch tiếp thị lại

Ví dụ về mã

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.V17.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, customer_id, campaign_resource_name):
    """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 = client.get_service("AdGroupService")

    # Creates an ad group operation and configures the new ad group.
    ad_group_operation = client.get_type("AdGroupOperation")
    ad_group = 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 = ad_group_service.mutate_ad_groups(
        customer_id=customer_id, operations=[ad_group_operation]
    )
    ad_group_resource_name = 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::V17::Resources::AdGroup->new({
    name     => "Dynamic remarketing ad group",
    campaign => $campaign_resource_name,
    status   => Google::Ads::GoogleAds::V17::Enums::AdGroupStatusEnum::ENABLED
  });

  # Create an ad group operation.
  my $ad_group_operation =
    Google::Ads::GoogleAds::V17::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;
}
      

Bước 3 – Tạo quảng cáo hiển thị thích ứng

Ví dụ về mã

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.V17.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, customer_id, ad_group_resource_name):
    """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 = client.get_service("AdGroupAdService")

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

    # Create the relevant asset objects for the ad.
    marketing_image = client.get_type("AdImageAsset")
    marketing_image.asset = marketing_image_resource_name
    square_marketing_image = client.get_type("AdImageAsset")
    square_marketing_image.asset = square_marketing_image_resource_name
    headline = client.get_type("AdTextAsset")
    headline.text = "Travel"
    description = 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 = client.get_type("AdGroupAdOperation")
    ad_group_ad = 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 = 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 = 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::V17::Common::ResponsiveDisplayAdInfo->new({
      marketingImages => [
        Google::Ads::GoogleAds::V17::Common::AdImageAsset->new({
            asset => $marketing_image_resource_name
          })
      ],
      squareMarketingImages => [
        Google::Ads::GoogleAds::V17::Common::AdImageAsset->new({
            asset => $square_marketing_image_resource_name
          })
      ],
      headlines => [
        Google::Ads::GoogleAds::V17::Common::AdTextAsset->new({
            text => "Travel"
          })
      ],
      longHeadline => Google::Ads::GoogleAds::V17::Common::AdTextAsset->new({
          text => "Travel the World"
        }
      ),
      descriptions => [
        Google::Ads::GoogleAds::V17::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::V17::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::V17::Common::AdImageAsset->new({
      #       asset => "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
      #     })
      # ]
    });

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

Bước 4 – Nhắm mục tiêu danh sách người dùng

Ví dụ về mã

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.V17.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, customer_id, ad_group_resource_name, user_list_id):
    """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 = client.get_service("AdGroupCriterionService")

    # Create an ad group criterion operation and set the ad group criterion
    # values.
    ad_group_criterion_operation = client.get_type("AdGroupCriterionOperation")
    ad_group_criterion = 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, user_list_id)

    # Issue a mutate request to add the ad group criterion.
    ad_group_criterion_response = (
        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::V17::Resources::AdGroupCriterion->new({
      adGroup  => $ad_group_resource_name,
      userList => Google::Ads::GoogleAds::V17::Common::UserListInfo->new({
          userList =>
            Google::Ads::GoogleAds::V17::Utils::ResourceNames::user_list(
            $customer_id, $user_list_id
            )})});

  # Create an ad group criterion operation.
  my $ad_group_criterion_operation =
    Google::Ads::GoogleAds::V17::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};
}
      

Sau khi thiết lập chiến dịch tái tiếp thị linh động cho tài khoản Merchant Center nguồn cấp dữ liệu, bạn có thể sử dụng tính năng Xem trước quảng cáo của bạn trong Google Ads để xem nội dung được lấy từ nguồn cấp dữ liệu Merchant Center của bạn.