Feed halaman Iklan Penelusuran Dinamis

Secara default, Iklan Penelusuran Dinamis (DSA) menargetkan seluruh situs atau sebagian situs tanpa berfokus pada URL halaman tertentu. Jika Anda memerlukan kontrol yang lebih baik atas URL, Anda dapat menggunakan feed halaman DSA untuk menentukan URL yang akan digunakan dengan DSA. Dengan memberikan feed halaman produk dan halaman landing, Anda membantu Google Ads menentukan kapan iklan ditampilkan dan ke mana pengguna yang berada di situs diarahkan.

Panduan ini menunjukkan cara membuat feed halaman DSA berbasis aset. Di kampanye Performa Maksimal, feed halaman juga dikenal sebagai penyertaan URL.

Buat aset untuk setiap halaman di situs Anda

Pertama, buat Asset dengan PageFeedAsset (page_feed_asset.page_url dan labels opsional) untuk setiap URL di situs Anda:

Java

List<String> urls =
    ImmutableList.of(
        "http://www.example.com/discounts/rental-cars",
        "http://www.example.com/discounts/hotel-deals",
        "http://www.example.com/discounts/flight-deals");

// Creates one operation per URL.
List<AssetOperation> assetOperations = new ArrayList<>();
for (String url : urls) {
  PageFeedAsset pageFeedAsset =
      PageFeedAsset.newBuilder()
          // Sets the URL of the page to include.
          .setPageUrl(url)
          // Recommended: adds labels to the asset. These labels can be used later in ad group
          // targeting to restrict the set of pages that can serve.
          .addLabels(dsaPageUrlLabel)
          .build();
  Asset asset = Asset.newBuilder().setPageFeedAsset(pageFeedAsset).build();
  assetOperations.add(AssetOperation.newBuilder().setCreate(asset).build());
}

// Creates the service client.
try (AssetServiceClient assetServiceClient =
    googleAdsClient.getLatestVersion().createAssetServiceClient()) {
  // Adds the assets.
  MutateAssetsResponse response =
      assetServiceClient.mutateAssets(String.valueOf(customerId), assetOperations);
  // Prints some information about the result.
  List<String> resourceNames =
      response.getResultsList().stream()
          .map(MutateAssetResult::getResourceName)
          .collect(Collectors.toList());
  resourceNames.forEach(r -> System.out.printf("Created asset with resource name %s.%n", r));
  return resourceNames;
}
      

C#

/// <summary>
/// Creates Assets to be used in a DSA page feed.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
/// <param name="dsaPageUrlLabel">The DSA page URL label.</param>
/// <returns>The list of asset resource names.</returns>
private static List<string> CreateAssets(GoogleAdsClient client, long customerId,
    string dsaPageUrlLabel)
{
    AssetServiceClient assetService = client.GetService(Services.V25.AssetService);

    string[] urls = new[]
    {
        "http://www.example.com/discounts/rental-cars",
        "http://www.example.com/discounts/hotel-deals",
        "http://www.example.com/discounts/flight-deals"
    };

    // Creates one operation per URL.
    List<AssetOperation> assetOperations = new List<AssetOperation>();
    foreach (string url in urls)
    {
        PageFeedAsset pageFeedAsset = new PageFeedAsset()
        {
            // Sets the URL of the page to include.
            PageUrl = url,

            // Recommended: adds labels to the asset. These labels can be used later in
            // ad group targeting to restrict the set of pages that can serve.
            Labels = { dsaPageUrlLabel }
        };

        assetOperations.Add(
            new AssetOperation()
            {
                Create = new Asset()
                {
                    PageFeedAsset = pageFeedAsset
                }
            });
    }

    // Adds the assets.
    MutateAssetsResponse response =
        assetService.MutateAssets(customerId.ToString(), assetOperations);

    // Prints some information about the result.
    List<string> resourceNames = response.Results.Select(
        assetResult => assetResult.ResourceName).ToList();
    foreach (string resourceName in resourceNames)
    {
        Console.Write($"Created asset with resource name {resourceName}.");
    }
    return resourceNames;
}
      

PHP

        $urls = [
            'http://www.example.com/discounts/rental-cars',
            'http://www.example.com/discounts/hotel-deals',
            'http://www.example.com/discounts/flight-deals'
        ];
        $operations = [];
        // Creates one asset per URL.
        foreach ($urls as $url) {
            $pageFeedAsset = new PageFeedAsset(
                [
                'page_url' => $url,
                // Recommended: adds labels to the asset. These labels can be used later in ad group
                // targeting to restrict the set of pages that can serve.
                'labels' => [$dsaPageUrlLabel]
                ]
            );

            // Wraps the page feed asset in an asset.
            $asset = new Asset(['page_feed_asset' => $pageFeedAsset]);

            // Creates an asset operation and adds it to the list of operations.
            $assetOperation = new AssetOperation();
            $assetOperation->setCreate($asset);
            $operations[] = $assetOperation;
        }

        // Issues a mutate request to add the assets and prints its information.
        $assetServiceClient = $googleAdsClient->getAssetServiceClient();
        $response = $assetServiceClient->mutateAssets(
            MutateAssetsRequest::build(
                $customerId,
                $operations
            )
        );
        $assetResourceNames = [];
        printf("Added %d assets:%s", $response->getResults()->count(), PHP_EOL);
        foreach ($response->getResults() as $addedAsset) {
            /**
 * @var Asset $addedAsset
*/
            $assetResourceName = $addedAsset->getResourceName();
            printf(
                "Created an asset with resource name: '%s'.%s",
                $assetResourceName,
                PHP_EOL
            );
            $assetResourceNames[] = $assetResourceName;
        }
        return $assetResourceNames;
      

Python

def create_assets(
    client: GoogleAdsClient, customer_id: str, dsa_page_url_label: str
) -> List[str]:
    """Creates assets to be used in a DSA page feed.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        dsa_page_url_label: the label for the DSA page URLs.

    Returns:
        a list of the created assets' resource names.
    """
    urls: List[str] = [
        "http://www.example.com/discounts/rental-cars",
        "http://www.example.com/discounts/hotel-deals",
        "http://www.example.com/discounts/flight-deals",
    ]
    operations: List[AssetOperation] = []

    # Creates one asset per URL.
    for url in urls:
        # Creates an asset operation and adds it to the list of operations.
        operation: AssetOperation = client.get_type("AssetOperation")
        asset: Asset = operation.create
        page_feed_asset: PageFeedAsset = asset.page_feed_asset
        page_feed_asset.page_url = url
        # Recommended: adds labels to the asset. These labels can be used later
        # in ad group targeting to restrict the set of pages that can serve.
        page_feed_asset.labels.append(dsa_page_url_label)
        operations.append(operation)

    # Issues a mutate request to add the assets and prints its information.
    asset_service: AssetServiceClient = client.get_service("AssetService")
    response: MutateAssetsResponse = asset_service.mutate_assets(
        customer_id=customer_id, operations=operations
    )

    print(f"Added {len(response.results)} assets:")

    resource_names: List[str] = []
    result: MutateAssetResult
    for result in response.results:
        resource_name: str = result.resource_name
        print(f"\tCreated an asset with resource name: '{resource_name}'")
        resource_names.append(resource_name)

    return resource_names
      

Ruby

def create_assets(client, dsa_page_url_label, customer_id)
  urls = [
    'http://www.example.com/discounts/rental-cars',
    'http://www.example.com/discounts/hotel-deals',
    'http://www.example.com/discounts/flight-deals',
  ]

  operations = urls.map do |url|
    client.operation.create_resource.asset do |asset|
      asset.page_feed_asset = client.resource.page_feed_asset do |pfa|
        # Sets the URL of the page to include.
        pfa.page_url = url
        # Recommended: adds labels to the asset. These labels can be used later
        # in ad group targeting to restrict the set of pages that can serve.
        pfa.labels << dsa_page_url_label
      end
    end
  end

  response = client.service.asset.mutate_assets(
    customer_id: customer_id,
    operations: operations,
  )

  resource_names = []
  response.results.each do |result|
    resource_name = result.resource_name
    puts "Created asset with resource name '#{resource_name}'"
    resource_names << resource_name
  end

  resource_names
end
      

Perl

my $urls = [
  "http://www.example.com/discounts/rental-cars",
  "http://www.example.com/discounts/hotel-deals",
  "http://www.example.com/discounts/flight-deals"
];

# Create one operation per URL.
my $asset_operations = [];
foreach my $url (@$urls) {
  my $page_feed_asset =
    Google::Ads::GoogleAds::V25::Common::PageFeedAsset->new({
      # Set the URL of the page to include.
      pageUrl => $url,
      # Recommended: add labels to the asset. These labels can be used later in
      # ad group targeting to restrict the set of pages that can serve.
      labels => [$dsa_page_url_label]});
  my $asset = Google::Ads::GoogleAds::V25::Resources::Asset->new({
    pageFeedAsset => $page_feed_asset
  });

  push @$asset_operations,
    Google::Ads::GoogleAds::V25::Services::AssetService::AssetOperation->new({
      create => $asset
    });
}

# Add the assets.
my $response = $api_client->AssetService()->mutate({
  customerId => $customer_id,
  operations => $asset_operations
});

# Print some information about the response.
my $resource_names = [];
foreach my $result (@{$response->{results}}) {
  push @$resource_names, $result->{resourceName};
  printf "Created asset with resource name '%s'.\n", $result->{resourceName};
}
return $resource_names;
      

curl

Mengelompokkan pembatasan URL halaman ke dalam AssetSet

Selanjutnya, buat kumpulan aset ini (yang merepresentasikan penyertaan URL Anda) menggunakan AssetSet dengan type yang ditetapkan ke PAGE_FEED. Pengelompokan ini merepresentasikan semua URL yang perlu dipertimbangkan untuk kampanye tertentu. Asset dapat menjadi bagian dari beberapa objek AssetSet.

Pertama, buat AssetSet baru:

Java

// Creates an AssetSet which will be used to link the dynamic page feed assets to a campaign.
AssetSet assetSet =
    AssetSet.newBuilder()
        .setName("My dynamic page feed " + CodeSampleHelper.getPrintableDateTime())
        .setType(AssetSetType.PAGE_FEED)
        .build();
// Creates an operation to add the AssetSet.
AssetSetOperation operation = AssetSetOperation.newBuilder().setCreate(assetSet).build();
try (AssetSetServiceClient serviceClient =
    googleAdsClient.getLatestVersion().createAssetSetServiceClient()) {
  // Sends the mutate request.
  MutateAssetSetsResponse response =
      serviceClient.mutateAssetSets(
          String.valueOf(params.customerId), ImmutableList.of(operation));
  // Prints some information about the response.
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created asset set with resource name %s.%n", resourceName);
  return resourceName;
}
      

C#

/// <summary>
/// Creates an AssetSet.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
/// <returns>The resource name of the asset set.</returns>
private string CreateAssetSet(GoogleAdsClient client, long customerId)
{
    AssetSetServiceClient assetSetService = client.GetService(
        Services.V25.AssetSetService);

    // Creates an AssetSet which will be used to link the dynamic page feed assets
    // to a campaign.
    AssetSet assetSet = new AssetSet()
    {
        Name = "My dynamic page feed " + ExampleUtilities.GetRandomString(),
        Type = AssetSetType.PageFeed
    };

    // Creates an operation to add the AssetSet.
    AssetSetOperation operation = new AssetSetOperation()
    {
        Create = assetSet
    };

    // Sends the mutate request.
    MutateAssetSetsResponse response =
        assetSetService.MutateAssetSets(
            customerId.ToString(), new[] { operation });
    // Prints some information about the response.
    string resourceName = response.Results[0].ResourceName;
    Console.WriteLine($"Created asset set with resource name {resourceName}.");
    return resourceName;
}
      

PHP

// Creates an asset set which will be used to link the dynamic page feed assets to a
// campaign.
$assetSet = new AssetSet(
    [
    'name' => 'My dynamic page feed ' . Helper::getPrintableDatetime(),
    'type' => AssetSetType::PAGE_FEED
    ]
);

// Creates an asset set operation.
$assetSetOperation = new AssetSetOperation();
$assetSetOperation->setCreate($assetSet);

// Issues a mutate request to add the asset set and prints its information.
$assetSetServiceClient = $googleAdsClient->getAssetSetServiceClient();
$response = $assetSetServiceClient->mutateAssetSets(
    MutateAssetSetsRequest::build(
        $customerId,
        [$assetSetOperation]
    )
);
$assetSetResourceName = $response->getResults()[0]->getResourceName();
printf(
    "Created an asset set with resource name: '%s'.%s",
    $assetSetResourceName,
    PHP_EOL
);

return $assetSetResourceName;
      

Python

def create_asset_set(client: GoogleAdsClient, customer_id: str) -> str:
    """Creates an asset set.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.

    Returns:
        the created asset set's resource name.
    """
    operation: AssetSetOperation = client.get_type("AssetSetOperation")
    # Creates an asset set which will be used to link the dynamic page feed
    # assets to a campaign.
    asset_set: AssetSet = operation.create
    asset_set.name = f"My dynamic page feed {get_printable_datetime()}"
    asset_set.type_ = client.enums.AssetSetTypeEnum.PAGE_FEED

    # Issues a mutate request to add the asset set and prints its information.
    asset_set_service: AssetSetServiceClient = client.get_service(
        "AssetSetService"
    )
    response: MutateAssetSetsResponse = asset_set_service.mutate_asset_sets(
        customer_id=customer_id, operations=[operation]
    )

    resource_name: str = response.results[0].resource_name
    print(f"Created an asset set with resource name: '{resource_name}'")
    return resource_name
      

Ruby

def create_asset_set(client, customer_id)
  # Creates an AssetSet which will be used to link the dynamic page feed assets to a campaign.
  # Creates an operation to add the AssetSet.
  operation = client.operation.create_resource.asset_set do |asset_set|
    asset_set.name = "My dynamic page feed #{Time.now}"
    asset_set.type = :PAGE_FEED
  end

  # Sends the mutate request.
  response = client.service.asset_set.mutate_asset_sets(
    customer_id: customer_id,
    operations: [operation],
  )
  # Prints some information about the response.
  resource_name = response.results.first.resource_name
  puts "Created asset set with resource name '#{resource_name}'"

  resource_name
end
      

Perl

# Create an AssetSet which will be used to link the dynamic page feed assets to
# a campaign.
my $asset_set = Google::Ads::GoogleAds::V25::Resources::AssetSet->new({
  name => "My dynamic page feed #" . uniqid(),
  type => PAGE_FEED
});

# Create an operation to add the AssetSet.
my $operation =
  Google::Ads::GoogleAds::V25::Services::AssetSetService::AssetSetOperation->
  new({
    create => $asset_set
  });

# Send the mutate request.
my $response = $api_client->AssetSetService()->mutate({
    customerId => $customer_id,
    operations => [$operation]});

# Print some information about the response.
my $resource_name = $response->{results}[0]{resourceName};
printf "Created asset set with resource name '%s'.\n", $resource_name;
return $resource_name;
      

curl

Kemudian, tautkan aset feed halaman Anda ke AssetSet menggunakan AssetSetAsset:

Java

List<AssetSetAssetOperation> operations = new ArrayList<>();
for (String assetResourceName : assetResourceNames) {
  AssetSetAsset assetSetAsset =
      AssetSetAsset.newBuilder()
          .setAsset(assetResourceName)
          .setAssetSet(assetSetResourceName)
          .build();
  // Creates an operation to add the link.
  AssetSetAssetOperation operation =
      AssetSetAssetOperation.newBuilder().setCreate(assetSetAsset).build();
  operations.add(operation);
}
try (AssetSetAssetServiceClient client =
    googleAdsClient.getLatestVersion().createAssetSetAssetServiceClient()) {
  // Sends the mutate request.
  MutateAssetSetAssetsResponse response =
      client.mutateAssetSetAssets(String.valueOf(params.customerId), operations);
  // Prints some information about the response.
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created AssetSetAsset link with resource name %s.%n", resourceName);
}
      

C#

/// <summary>
/// Adds an Asset to an AssetSet by creating an AssetSetAsset link.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
/// <param name="assetResourceNames">The asset resource names.</param>
/// <param name="assetSetResourceName">Resource name of the asset set.</param>
private void AddAssetsToAssetSet(GoogleAdsClient client, long customerId,
    List<string> assetResourceNames, string assetSetResourceName)
{
    AssetSetAssetServiceClient assetSetAssetService = client.GetService(
        Services.V25.AssetSetAssetService);

    List<AssetSetAssetOperation> operations = new List<AssetSetAssetOperation>();
    foreach (string assetResourceName in assetResourceNames)
    {
        AssetSetAsset assetSetAsset = new AssetSetAsset()
        {
            Asset = assetResourceName,
            AssetSet = assetSetResourceName
        };

        // Creates an operation to add the link.
        AssetSetAssetOperation operation = new AssetSetAssetOperation()
        {
            Create = assetSetAsset
        };

        operations.Add(operation);
    }
    // Sends the mutate request.
    MutateAssetSetAssetsResponse response =
        assetSetAssetService.MutateAssetSetAssets(customerId.ToString(), operations);
    // Prints some information about the response.
    string resourceName = response.Results[0].ResourceName;
    Console.WriteLine($"Created AssetSetAsset link with resource name {resourceName}.");
}
      

PHP

        $operations = [];
        foreach ($assetResourceNames as $assetResourceName) {
            // Creates an asset set asset.
            $assetSetAsset = new AssetSetAsset(
                [
                'asset' => $assetResourceName,
                'asset_set' => $assetSetResourceName
                ]
            );

            // Creates an asset set asset operation and adds it to the list of operations.
            $assetSetAssetOperation = new AssetSetAssetOperation();
            $assetSetAssetOperation->setCreate($assetSetAsset);
            $operations[] = $assetSetAssetOperation;
        }

        // Issues a mutate request to add the asset set assets and prints its information.
        $assetSetAssetServiceClient = $googleAdsClient->getAssetSetAssetServiceClient();
        $response = $assetSetAssetServiceClient->mutateAssetSetAssets(
            MutateAssetSetAssetsRequest::build($customerId, $operations)
        );
        printf("Added %d asset set assets:%s", $response->getResults()->count(), PHP_EOL);
        foreach ($response->getResults() as $addedAssetSetAsset) {
            /**
 * @var AssetSetAsset $addedAssetSetAsset
*/
            printf(
                "Created an asset set asset link with resource name: '%s'.%s",
                $addedAssetSetAsset->getResourceName(),
                PHP_EOL
            );
        }
      

Python

def add_assets_to_asset_set(
    client: GoogleAdsClient,
    customer_id: str,
    asset_resource_names: List[str],
    asset_set_resource_name: str,
) -> None:
    """Adds assets to an asset set by creating an asset set asset link.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        asset_resource_names: a list of asset resource names.
        asset_set_resource_name: a resource name for an asset set.
    """
    operations: List[AssetSetAssetOperation] = []
    for resource_name in asset_resource_names:
        # Creates an asset set asset operation and adds it to the list of
        # operations.
        operation: AssetSetAssetOperation = client.get_type(
            "AssetSetAssetOperation"
        )
        asset_set_asset: AssetSetAsset = operation.create
        asset_set_asset.asset = resource_name
        asset_set_asset.asset_set = asset_set_resource_name
        operations.append(operation)

    # Issues a mutate request to add the asset set assets and prints its
    # information.
    asset_set_asset_service: AssetSetAssetServiceClient = client.get_service(
        "AssetSetAssetService"
    )
    response: MutateAssetSetAssetsResponse = (
        asset_set_asset_service.mutate_asset_set_assets(
            customer_id=customer_id, operations=operations
        )
    )

    print(f"Added {len(response.results)} asset set assets:")

    result: MutateAssetSetAssetResult
    for result in response.results:
        print(
            "\tCreated an asset set asset link with resource name "
            f"'{result.resource_name}'"
        )
      

Ruby

def add_assets_to_asset_set(client, asset_resource_names, asset_set_resource_name, customer_id)
  operations = asset_resource_names.map do |asset_resource_name|
    client.operation.create_resource.asset_set_asset do |asa|
      asa.asset = asset_resource_name
      asa.asset_set = asset_set_resource_name
    end
  end

  response = client.service.asset_set_asset.mutate_asset_set_assets(
    customer_id: customer_id,
    operations: operations,
  )
  resource_name = response.results.first.resource_name
  puts "Created asset set asset with resource name '#{resource_name}'"
end
      

Perl

my $operations = [];
foreach my $asset_resource_name (@$asset_resource_names) {
  my $asset_set_asset =
    Google::Ads::GoogleAds::V25::Resources::AssetSetAsset->new({
      asset    => $asset_resource_name,
      assetSet => $asset_set_resource_name
    });

  # Create an operation to add the link.
  my $operation =
    Google::Ads::GoogleAds::V25::Services::AssetSetAssetService::AssetSetAssetOperation
    ->new({
      create => $asset_set_asset
    });
  push @$operations, $operation;
}

# Send the mutate request.
my $response = $api_client->AssetSetAssetService()->mutate({
  customerId => $customer_id,
  operations => $operations
});

# Print some information about the response.
my $resource_name = $response->{results}[0]{resourceName};
printf "Created AssetSetAsset link with resource name '%s'.\n",
  $resource_name;
      

curl

Kaitkan AssetSet dengan kampanye

Setelah aset dikumpulkan dalam AssetSet, tautkan AssetSet ke kampanye menggunakan CampaignAssetSet. Untuk mengontrol cara kampanye menggunakan URL feed halaman Anda, konfigurasikan DynamicSearchAdsSetting.use_supplied_urls_only di Campaign (use_supplied_urls_only = true membatasi penargetan hanya ke URL feed halaman; false menggunakan indeks Google atas domain Anda dan URL feed halaman):

Java

// Creates a CampaignAssetSet representing the link between an AssetSet and a Campaign.
CampaignAssetSet campaignAssetSet =
    CampaignAssetSet.newBuilder()
        .setCampaign(ResourceNames.campaign(params.customerId, params.campaignId))
        .setAssetSet(assetSetResourceName)
        .build();
// Creates an operation to add the CampaignAssetSet.
CampaignAssetSetOperation operation =
    CampaignAssetSetOperation.newBuilder().setCreate(campaignAssetSet).build();
// Creates the service client.
try (CampaignAssetSetServiceClient client =
    googleAdsClient.getLatestVersion().createCampaignAssetSetServiceClient()) {
  // Issues the mutate request.
  MutateCampaignAssetSetsResponse response =
      client.mutateCampaignAssetSets(
          String.valueOf(params.customerId), ImmutableList.of(operation));
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created a CampaignAssetSet with resource name %s.%n", resourceName);
}
      

C#

/// <summary>
/// Links an AssetSet to a Campaign by creating a CampaignAssetSet.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
/// <param name="campaignId">ID of the campaign to which the asset is linked.</param>
/// <param name="assetSetResourceName">Resource name of the asset set.</param>
private void LinkAssetSetToCampaign(GoogleAdsClient client, long customerId,
    long campaignId, string assetSetResourceName)
{
    CampaignAssetSetServiceClient campaignAssetSetService = client.GetService(
        Services.V25.CampaignAssetSetService);

    // Creates a CampaignAssetSet representing the link between an AssetSet and a Campaign.
    CampaignAssetSet campaignAssetSet = new CampaignAssetSet()
    {
        Campaign = ResourceNames.Campaign(customerId, campaignId),
        AssetSet = assetSetResourceName,
    };

    // Creates an operation to add the CampaignAssetSet.
    CampaignAssetSetOperation operation = new CampaignAssetSetOperation()
    {
        Create = campaignAssetSet
    };
    // Issues the mutate request.
    MutateCampaignAssetSetsResponse response =
        campaignAssetSetService.MutateCampaignAssetSets(
            customerId.ToString(), new[] { operation });
    string resourceName = response.Results[0].ResourceName;
    Console.WriteLine($"Created a CampaignAssetSet with resource name {resourceName}.");
}
      

PHP

// Creates a campaign asset set representing the link between an asset set and a campaign.
$campaignAssetSet = new CampaignAssetSet(
    [
    'asset_set' => $assetSetResourceName,
    'campaign' => ResourceNames::forCampaign($customerId, $campaignId)
    ]
);

// Creates a campaign asset set operation.
$campaignAssetSetOperation = new CampaignAssetSetOperation();
$campaignAssetSetOperation->setCreate($campaignAssetSet);

// Issues a mutate request to add the campaign asset set and prints its information.
$campaignAssetSetServiceClient = $googleAdsClient->getCampaignAssetSetServiceClient();
$response = $campaignAssetSetServiceClient->mutateCampaignAssetSets(
    MutateCampaignAssetSetsRequest::build($customerId, [$campaignAssetSetOperation])
);
printf(
    "Created a campaign asset set with resource name: '%s'.%s",
    $response->getResults()[0]->getResourceName(),
    PHP_EOL
);
      

Python

def link_asset_set_to_campaign(
    client: GoogleAdsClient,
    customer_id: str,
    campaign_id: str,
    asset_set_resource_name: str,
) -> None:
    """Links the asset set to the campaign by creating a campaign asset set.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        campaign_id: the ID for a Campaign.
        asset_set_resource_name: a resource name for an asset set.
    """
    googleads_service: GoogleAdsServiceClient = client.get_service(
        "GoogleAdsService"
    )
    # Creates a campaign asset set representing the link between an asset set
    # and a campaign.
    operation: CampaignAssetSetOperation = client.get_type(
        "CampaignAssetSetOperation"
    )
    campaign_asset_set: CampaignAssetSet = operation.create
    campaign_asset_set.asset_set = asset_set_resource_name
    campaign_asset_set.campaign = googleads_service.campaign_path(
        customer_id, campaign_id
    )

    campaign_asset_set_service: CampaignAssetSetServiceClient = (
        client.get_service("CampaignAssetSetService")
    )
    response: MutateCampaignAssetSetsResponse = (
        campaign_asset_set_service.mutate_campaign_asset_sets(
            customer_id=customer_id, operations=[operation]
        )
    )

    resource_name: str = response.results[0].resource_name
    print(f"Created a campaign asset set with resource name: '{resource_name}'")
      

Ruby

def link_asset_set_to_campaign(client, asset_set_resource_name, customer_id, campaign_id)
  # Creates a CampaignAssetSet representing the link between an AssetSet and a Campaign.
  # Creates an operation to add the CampaignAssetSet.
  operation = client.operation.create_resource.campaign_asset_set do |cas|
    cas.campaign = client.path.campaign(customer_id, campaign_id)
    cas.asset_set = asset_set_resource_name
  end

  # Issues the mutate request.
  response = client.service.campaign_asset_set.mutate_campaign_asset_sets(
    customer_id: customer_id,
    operations: [operation],
  )
  resource_name = response.results.first.resource_name
  puts "Created a campaign asset set with resource name '#{resource_name}'"
end
      

Perl

# Create a CampaignAssetSet representing the link between an AssetSet and a Campaign.
my $campaign_asset_set =
  Google::Ads::GoogleAds::V25::Resources::CampaignAssetSet->new({
    campaign => Google::Ads::GoogleAds::V25::Utils::ResourceNames::campaign(
      $customer_id, $campaign_id
    ),
    assetSet => $asset_set_resource_name
  });

# Create an operation to add the CampaignAssetSet.
my $operation =
  Google::Ads::GoogleAds::V25::Services::CampaignAssetSetService::CampaignAssetSetOperation
  ->new({
    create => $campaign_asset_set
  });

# Issue the mutate request.
my $response = $api_client->CampaignAssetSetService()->mutate({
    customerId => $customer_id,
    operations => [$operation]});

# Print some information about the response.
my $resource_name = $response->{results}[0]{resourceName};
printf "Created a CampaignAssetSet with resource name '%s'.\n",
  $resource_name;
      

curl

Direkomendasikan: Menargetkan penyertaan URL menggunakan label kustom

Anda dapat secara opsional menggunakan label kustom (page_feed_asset.labels) untuk menargetkan dan mengajukan bid pada subkumpulan tertentu dari penyertaan URL Anda. Buat AdGroupCriterion dengan WebpageInfo (menetapkan criterion_name yang diperlukan) yang memfilter menggunakan kondisi yang operand-nya ditetapkan ke WebpageConditionOperand.CUSTOM_LABEL dan argument-nya ditetapkan ke string label target:

Java

String adGroupResourceName = ResourceNames.adGroup(params.customerId, params.adGroupId);

// Creates the webpage condition info that targets an advertiser's webpages based on the
// custom label specified by the dsaPageUrlLabel (e.g. "discounts").
WebpageConditionInfo webpageConditionInfo =
    WebpageConditionInfo.newBuilder()
        .setOperand(WebpageConditionOperand.CUSTOM_LABEL)
        .setArgument(dsaPageUrlLabel)
        .build();

// Creates the webpage info, or criterion for targeting webpages of an advertiser's website.
WebpageInfo webpageInfo =
    WebpageInfo.newBuilder()
        .setCriterionName("Test Criterion")
        .addAllConditions(ImmutableList.of(webpageConditionInfo))
        .build();

// Creates the ad group criterion.
AdGroupCriterion adGroupCriterion =
    AdGroupCriterion.newBuilder()
        .setAdGroup(adGroupResourceName)
        .setWebpage(webpageInfo)
        .setCpcBidMicros(1_500_000)
        .build();

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

// Creates the service client.
try (AdGroupCriterionServiceClient adGroupCriterionServiceClient =
    googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) {
  // Adds the ad group criterion.
  MutateAdGroupCriteriaResponse response =
      adGroupCriterionServiceClient.mutateAdGroupCriteria(
          Long.toString(params.customerId), ImmutableList.of(operation));

  // Displays the results.
  System.out.printf(
      "Created ad group criterion with resource name '%s'.%n",
      response.getResults(0).getResourceName());
}
      

C#

/// <summary>
/// Adds the DSA target.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
/// <param name="adGroupId">The ad group to which DSA label targeting is added.</param>
/// <param name="dsaPageUrlLabel">The DSA page URL label.</param>
private static void AddDsaTarget(
    GoogleAdsClient client, long customerId, long adGroupId, string dsaPageUrlLabel)
{
    AdGroupCriterionServiceClient adGroupCriterionService = client.GetService(
        Services.V25.AdGroupCriterionService);

    string adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId);

    // Creates the webpage condition info that targets an advertiser's webpages
    // based on the custom label specified by the dsaPageUrlLabel (e.g. "discounts").
    WebpageConditionInfo webpageConditionInfo = new WebpageConditionInfo()
    {
        Operand = WebpageConditionOperand.CustomLabel,
        Argument = dsaPageUrlLabel
    };

    // Creates the webpage info, or criterion for targeting webpages of an
    // advertiser's website.
    WebpageInfo webpageInfo = new WebpageInfo()
    {
        CriterionName = "Test Criterion",
        Conditions = { webpageConditionInfo }
    };

    // Creates the ad group criterion.
    AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
    {
        AdGroup = adGroupResourceName,
        Webpage = webpageInfo,
        CpcBidMicros = 1_500_000
    };

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

    // Adds the ad group criterion.
    MutateAdGroupCriteriaResponse response =
        adGroupCriterionService.MutateAdGroupCriteria(
            customerId.ToString(), new[] { operation });

    string resourceName = response.Results[0].ResourceName;
    // Displays the results.
    Console.WriteLine($"Created ad group criterion with resource " +
        $"name '{resourceName}'.");
}
      

PHP

// Creates the webpage condition info that targets an advertiser's webpages based on the
// custom label specified by the DSA page URL label (e.g. "discounts").
$webpageConditionInfo = new WebpageConditionInfo(
    [
    'operand' => WebpageConditionOperand::CUSTOM_LABEL,
    'argument' => $dsaPageUrlLabel
    ]
);

// Creates the webpage info, or criterion for targeting webpages of an advertiser's website.
$webpageInfo = new WebpageInfo(
    [
    'criterion_name' => 'Test Criterion',
    'conditions' => [$webpageConditionInfo]
    ]
);

// Creates the ad group criterion.
$adGroupCriterion = new AdGroupCriterion(
    [
    'ad_group' => ResourceNames::forAdGroup($customerId, $adGroupId),
    'webpage' => $webpageInfo,
    'cpc_bid_micros' => 1_500_000
    ]
);

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

// Issues a mutate request to add the ad group criterion and prints its information.
$adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient();
$response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
    MutateAdGroupCriteriaRequest::build($customerId, [$adGroupCriterionOperation])
);
printf(
    "Created ad group criterion with resource name '%s'.%s",
    $response->getResults()[0]->getResourceName(),
    PHP_EOL
);
      

Python

def add_dsa_target(
    client: GoogleAdsClient,
    customer_id: str,
    ad_group_id: str,
    dsa_page_url_label: str,
) -> None:
    """Creates an ad group criterion targeting the DSA label.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        ad_group_id: the ID for an Ad Group.
        dsa_page_url_label: the label for the DSA page URLs.
    """
    googleads_service: GoogleAdsServiceClient = client.get_service(
        "GoogleAdsService"
    )
    # Creates the ad group criterion.
    operation: AdGroupCriterionOperation = client.get_type(
        "AdGroupCriterionOperation"
    )
    criterion: AdGroupCriterion = operation.create
    criterion.ad_group = googleads_service.ad_group_path(
        customer_id, ad_group_id
    )
    criterion.cpc_bid_micros = 1500000
    # Creates the webpage info, or criterion for targeting webpages of an
    # advertiser's website.
    criterion.webpage.criterion_name = "Test Criterion"
    # Creates the webpage condition info that targets an advertiser's webpages
    # based on the custom label specified by the DSA page URL label
    # (e.g. "discounts").
    webpage_condition: WebpageConditionInfo = client.get_type(
        "WebpageConditionInfo"
    )
    webpage_condition.operand = (
        client.enums.WebpageConditionOperandEnum.CUSTOM_LABEL
    )
    webpage_condition.argument = dsa_page_url_label
    criterion.webpage.conditions.append(webpage_condition)

    # Issues a mutate request to add the ad group criterion and prints its
    # information.
    ad_group_criterion_service: AdGroupCriterionServiceClient = (
        client.get_service("AdGroupCriterionService")
    )
    response: MutateAdGroupCriteriaResponse = (
        ad_group_criterion_service.mutate_ad_group_criteria(
            customer_id=customer_id, operations=[operation]
        )
    )
    print(
        "Created ad group criterion with resource name: "
        f"'{response.results[0].resource_name}'"
    )
      

Ruby

def add_dsa_target(client, dsa_page_url_label, customer_id, ad_group_id)
  operation = client.operation.create_resource.ad_group_criterion do |agc|
    agc.ad_group = client.path.ad_group(customer_id, ad_group_id)
    agc.cpc_bid_micros = 1_500_000

    # Creates the webpage info, or criterion for targeting webpages of an
    # advertiser's website.
    agc.webpage = client.resource.webpage_info do |webpage|
      webpage.criterion_name = "Test Criterion"
      # Creates the webpage condition info that targets an advertiser's webpages
      # based on the custom label specified by the dsaPageUrlLabel
      # (e.g. "discounts").
      webpage.conditions << client.resource.webpage_condition_info do |wci|
        wci.operand = :CUSTOM_LABEL
        wci.argument = dsa_page_url_label
      end
    end
  end

  response = client.service.ad_group_criterion.mutate_ad_group_criteria(
    customer_id: customer_id,
    operations: [operation],
  )
  resource_name = response.results.first.resource_name
  puts "Created ad group criterion with resource name '#{resource_name}'"
end
      

Perl

my $ad_group_resource_name =
  Google::Ads::GoogleAds::V25::Utils::ResourceNames::ad_group($customer_id,
  $ad_group_id);

# Create the webpage condition info that targets an advertiser's webpages based
# on the custom label specified by the $dsa_page_url_label (e.g. "discounts").
my $webpage_condition_info =
  Google::Ads::GoogleAds::V25::Common::WebpageConditionInfo->new({
    operand  => CUSTOM_LABEL,
    argument => $dsa_page_url_label
  });

# Create the webpage info, or criterion for targeting webpages of an advertiser's website.
my $webpage_info = Google::Ads::GoogleAds::V25::Common::WebpageInfo->new({
    criterionName => "Test Criterion",
    conditions    => [$webpage_condition_info]});

# Create the ad group criterion.
my $ad_group_criterion =
  Google::Ads::GoogleAds::V25::Resources::AdGroupCriterion->new({
    adGroup      => $ad_group_resource_name,
    webpage      => $webpage_info,
    cpcBidMicros => 1_500_000
  });

# Create the operation.
my $operation =
  Google::Ads::GoogleAds::V25::Services::AdGroupCriterionService::AdGroupCriterionOperation
  ->new({
    create => $ad_group_criterion
  });

# Add the ad group criterion.
my $response = $api_client->AdGroupCriterionService()->mutate({
    customerId => $customer_id,
    operations => [$operation]});

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

curl