建立購物廣告群組
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要放送購物廣告活動的廣告,您必須建立AdGroup
。
標準購物廣告活動支援SHOPPING_PRODUCT_ADS
廣告群組類型。這是購物廣告活動的預設廣告群組類型,會放送標準產品廣告。只要提供廣告群組 type
欄位,即可設定這項功能。
標準購物廣告活動可包含多個廣告群組,每個廣告群組至少要有一則廣告。
這個程式碼範例示範如何為標準購物廣告活動建立廣告群組。範例也會設定單次點擊出價,以符合廣告活動的出價策略,
該策略設為 ManualCpc
。
Java
private String addShoppingProductAdGroup(
GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {
// Creates an ad group.
AdGroup adGroup =
AdGroup.newBuilder()
.setName("Earth to Mars Cruises #" + getPrintableDateTime())
.setCampaign(campaignResourceName)
// Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for
// ad groups that contain shopping product ads.
.setType(AdGroupType.SHOPPING_PRODUCT_ADS)
.setCpcBidMicros(1_000_000L)
.setStatus(AdGroupStatus.ENABLED)
.build();
// Creates an ad group operation.
AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();
// Issues a mutate request to add an ad group.
try (AdGroupServiceClient adGroupServiceClient =
googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {
MutateAdGroupResult mutateAdGroupResult =
adGroupServiceClient
.mutateAdGroups(Long.toString(customerId), Collections.singletonList(operation))
.getResults(0);
System.out.printf(
"Added a product shopping ad group with resource name: '%s'%n",
mutateAdGroupResult.getResourceName());
return mutateAdGroupResult.getResourceName();
}
}
C#
private string AddProductShoppingAdGroup(GoogleAdsClient client, long customerId,
string campaignResourceName)
{
// Get the AdGroupService.
AdGroupServiceClient adGroupService = client.GetService(Services.V21.AdGroupService);
// Creates an ad group.
AdGroup adGroup = new AdGroup()
{
Name = "Earth to Mars Cruises #" + ExampleUtilities.GetRandomString(),
Campaign = campaignResourceName,
// Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible
// for ad groups that contain shopping product ads.
Type = AdGroupType.ShoppingProductAds,
CpcBidMicros = 1_000_000L,
Status = AdGroupStatus.Enabled
};
// Creates an ad group operation.
AdGroupOperation operation = new AdGroupOperation()
{
Create = adGroup
};
// Issues a mutate request to add an ad group.
MutateAdGroupResult mutateAdGroupResult =
adGroupService
.MutateAdGroups(customerId.ToString(), new AdGroupOperation[] { operation })
.Results[0];
Console.WriteLine("Added a product shopping ad group with resource name: '{0}'.",
mutateAdGroupResult.ResourceName);
return mutateAdGroupResult.ResourceName;
}
PHP
private static function addShoppingProductAdGroup(
GoogleAdsClient $googleAdsClient,
int $customerId,
string $campaignResourceName
) {
// Creates an ad group.
$adGroup = new AdGroup([
'name' => 'Earth to Mars Cruise #' . Helper::getPrintableDatetime(),
// Sets the campaign.
'campaign' => $campaignResourceName,
// Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for
// ad groups that contain shopping product ads.
'type' => AdGroupType::SHOPPING_PRODUCT_ADS,
'cpc_bid_micros' => 10000000,
'status' => AdGroupStatus::ENABLED
]);
// Creates an ad group operation.
$adGroupOperation = new AdGroupOperation();
$adGroupOperation->setCreate($adGroup);
// Issues a mutate request to add an ad group.
$adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient();
$response = $adGroupServiceClient->mutateAdGroups(
MutateAdGroupsRequest::build($customerId, [$adGroupOperation])
);
/** @var AdGroup $addedAdGroup */
$addedAdGroup = $response->getResults()[0];
printf(
"Added a shopping product ad group with resource name '%s'.%s",
$addedAdGroup->getResourceName(),
PHP_EOL
);
return $addedAdGroup->getResourceName();
}
Python
def add_shopping_product_ad_group(
client: GoogleAdsClient,
customer_id: str,
campaign_resource_name: str,
) -> str:
"""Creates a new shopping product ad group in the specified campaign."""
ad_group_service: AdGroupServiceClient = client.get_service(
"AdGroupService"
)
# Create ad group.
ad_group_operation: AdGroupOperation = client.get_type("AdGroupOperation")
ad_group: AdGroup = ad_group_operation.create
ad_group.name = f"Earth to Mars cruise {uuid.uuid4()}"
ad_group.status = client.enums.AdGroupStatusEnum.ENABLED
ad_group.campaign = campaign_resource_name
# Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value
# possible for ad groups that contain shopping product ads.
ad_group.type_ = client.enums.AdGroupTypeEnum.SHOPPING_PRODUCT_ADS
ad_group.cpc_bid_micros = 10000000
# 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: str = ad_group_response.results[0].resource_name
print(
"Added a product shopping ad group with resource name "
f"'{ad_group_resource_name}'."
)
return ad_group_resource_name
小茹
def add_shopping_product_ad_group(client, customer_id, campaign_name)
operation = client.operation.create_resource.ad_group do |ad_group|
ad_group.name = "Earth to Mars cruise ##{(Time.new.to_f * 1000).to_i}"
ad_group.status = :ENABLED
ad_group.campaign = campaign_name
ad_group.type = :SHOPPING_PRODUCT_ADS
ad_group.cpc_bid_micros = 10_000_000
end
service = client.service.ad_group
response = service.mutate_ad_groups(
customer_id: customer_id,
operations: [operation],
)
ad_group_name = response.results.first.resource_name
puts "Added a product shopping ad group with resource name #{ad_group_name}."
ad_group_name
end
Perl
sub add_shopping_product_ad_group {
my ($api_client, $customer_id, $campaign_resource_name) = @_;
# Create an ad group.
my $ad_group = Google::Ads::GoogleAds::V21::Resources::AdGroup->new({
name => "Earth to Mars Cruises #" . uniqid(),
campaign => $campaign_resource_name,
# Set the ad group type to SHOPPING_PRODUCT_ADS. This is the only value
# possible for ad groups that contain shopping product ads.
type => SHOPPING_PRODUCT_ADS,
cpcBidMicros => 1000000,
status => Google::Ads::GoogleAds::V21::Enums::AdGroupStatusEnum::ENABLED
});
# Create an ad group operation.
my $ad_group_operation =
Google::Ads::GoogleAds::V21::Services::AdGroupService::AdGroupOperation->
new({create => $ad_group});
# Add the ad group.
my $ad_group_resource_name = $api_client->AdGroupService()->mutate({
customerId => $customer_id,
operations => [$ad_group_operation]})->{results}[0]{resourceName};
printf "Added a product shopping ad group with resource name: '%s'.\n",
$ad_group_resource_name;
return $ad_group_resource_name;
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eTo display ads for Shopping campaigns, you need to create an \u003ccode\u003eAdGroup\u003c/code\u003e with the type set to \u003ccode\u003eSHOPPING_PRODUCT_ADS\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eStandard Shopping campaigns can have multiple ad groups, each containing at least one ad.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples demonstrate how to create an ad group for a Standard Shopping campaign, including setting a CPC bid.\u003c/p\u003e\n"]]],[],null,["# Creating a Shopping Ad Group\n\nTo serve ads for your Shopping campaign, you must create an\n[`AdGroup`](/google-ads/api/reference/rpc/v21/AdGroup).\n\nStandard Shopping campaigns support the\n[`SHOPPING_PRODUCT_ADS`](/google-ads/api/reference/rpc/v21/AdGroupTypeEnum.AdGroupType#shopping_product_ads)\nad group type. This is the default ad group type for Shopping campaigns, serving\nstandard product ads. It can be set by providing the ad group\n[`type`](/google-ads/api/reference/rpc/v21/AdGroup#type) field.\n\nStandard Shopping campaigns can contain multiple ad groups, each containing at\nleast one ad.\n\nThis code example demonstrates how to create an ad group for a standard Shopping\ncampaign. The example also sets a CPC bid to match the campaign's bid strategy,\nwhich is set to [`ManualCpc`](/google-ads/api/reference/rpc/v21/ManualCpc).\n\n\n### Java\n\n```java\nprivate String addShoppingProductAdGroup(\n GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {\n // Creates an ad group.\n AdGroup adGroup =\n AdGroup.newBuilder()\n .setName(\"Earth to Mars Cruises #\" + getPrintableDateTime())\n .setCampaign(campaignResourceName)\n // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for\n // ad groups that contain shopping product ads.\n .setType(AdGroupType.SHOPPING_PRODUCT_ADS)\n .setCpcBidMicros(1_000_000L)\n .setStatus(AdGroupStatus.ENABLED)\n .build();\n\n // Creates an ad group operation.\n AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();\n\n // Issues a mutate request to add an ad group.\n try (AdGroupServiceClient adGroupServiceClient =\n googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {\n MutateAdGroupResult mutateAdGroupResult =\n adGroupServiceClient\n .mutateAdGroups(Long.toString(customerId), Collections.singletonList(operation))\n .getResults(0);\n System.out.printf(\n \"Added a product shopping ad group with resource name: '%s'%n\",\n mutateAdGroupResult.getResourceName());\n return mutateAdGroupResult.getResourceName();\n }\n}\nhttps://github.com/googleads/google-ads-java/blob/3c3c1041c2a0ab81553e3b2a79876256649397ed/google-ads-examples/src/main/java/com/google/ads/googleads/examples/shoppingads/AddShoppingProductAd.java#L282-L312\n \n```\n\n### C#\n\n```c#\nprivate string AddProductShoppingAdGroup(GoogleAdsClient client, long customerId,\n string campaignResourceName)\n{\n // Get the AdGroupService.\n AdGroupServiceClient adGroupService = client.GetService(Services.V21.AdGroupService);\n\n // Creates an ad group.\n AdGroup adGroup = new AdGroup()\n {\n Name = \"Earth to Mars Cruises #\" + ExampleUtilities.GetRandomString(),\n Campaign = campaignResourceName,\n // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible\n // for ad groups that contain shopping product ads.\n Type = AdGroupType.ShoppingProductAds,\n CpcBidMicros = 1_000_000L,\n Status = AdGroupStatus.Enabled\n };\n\n // Creates an ad group operation.\n AdGroupOperation operation = new AdGroupOperation()\n {\n Create = adGroup\n };\n\n // Issues a mutate request to add an ad group.\n MutateAdGroupResult mutateAdGroupResult =\n adGroupService\n .MutateAdGroups(customerId.ToString(), new AdGroupOperation[] { operation })\n .Results[0];\n Console.WriteLine(\"Added a product shopping ad group with resource name: '{0}'.\",\n mutateAdGroupResult.ResourceName);\n return mutateAdGroupResult.ResourceName;\n}https://github.com/googleads/google-ads-dotnet/blob/ada966e1983b655e82172b6c3e7d9b091b522377/Google.Ads.GoogleAds/examples/ShoppingAds/AddShoppingProductAd.cs#L278-L310\n \n```\n\n### PHP\n\n```php\nprivate static function addShoppingProductAdGroup(\n GoogleAdsClient $googleAdsClient,\n int $customerId,\n string $campaignResourceName\n) {\n // Creates an ad group.\n $adGroup = new AdGroup([\n 'name' =\u003e 'Earth to Mars Cruise #' . Helper::getPrintableDatetime(),\n // Sets the campaign.\n 'campaign' =\u003e $campaignResourceName,\n // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for\n // ad groups that contain shopping product ads.\n 'type' =\u003e AdGroupType::SHOPPING_PRODUCT_ADS,\n 'cpc_bid_micros' =\u003e 10000000,\n 'status' =\u003e AdGroupStatus::ENABLED\n ]);\n\n // Creates an ad group operation.\n $adGroupOperation = new AdGroupOperation();\n $adGroupOperation-\u003esetCreate($adGroup);\n\n // Issues a mutate request to add an ad group.\n $adGroupServiceClient = $googleAdsClient-\u003egetAdGroupServiceClient();\n $response = $adGroupServiceClient-\u003emutateAdGroups(\n MutateAdGroupsRequest::build($customerId, [$adGroupOperation])\n );\n\n /** @var AdGroup $addedAdGroup */\n $addedAdGroup = $response-\u003egetResults()[0];\n printf(\n \"Added a shopping product ad group with resource name '%s'.%s\",\n $addedAdGroup-\u003egetResourceName(),\n PHP_EOL\n );\n\n return $addedAdGroup-\u003egetResourceName();\n} \nhttps://github.com/googleads/google-ads-php/blob/be0249c30c27b4760387bec6682b82c9f4167761/examples/ShoppingAds/AddShoppingProductAd.php#L292-L328\n\n \n```\n\n### Python\n\n```python\ndef add_shopping_product_ad_group(\n client: GoogleAdsClient,\n customer_id: str,\n campaign_resource_name: str,\n) -\u003e str:\n \"\"\"Creates a new shopping product ad group in the specified campaign.\"\"\"\n ad_group_service: AdGroupServiceClient = client.get_service(\n \"AdGroupService\"\n )\n\n # Create ad group.\n ad_group_operation: AdGroupOperation = client.get_type(\"AdGroupOperation\")\n ad_group: AdGroup = ad_group_operation.create\n ad_group.name = f\"Earth to Mars cruise {uuid.uuid4()}\"\n ad_group.status = client.enums.AdGroupStatusEnum.ENABLED\n ad_group.campaign = campaign_resource_name\n # Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value\n # possible for ad groups that contain shopping product ads.\n ad_group.type_ = client.enums.AdGroupTypeEnum.SHOPPING_PRODUCT_ADS\n ad_group.cpc_bid_micros = 10000000\n\n # Add the ad group.\n ad_group_response = ad_group_service.mutate_ad_groups(\n customer_id=customer_id, operations=[ad_group_operation]\n )\n\n ad_group_resource_name: str = ad_group_response.results[0].resource_name\n\n print(\n \"Added a product shopping ad group with resource name \"\n f\"'{ad_group_resource_name}'.\"\n )\n\n return ad_group_resource_name \nhttps://github.com/googleads/google-ads-python/blob/d0595698b8a7de6cc00684b467462601037c9db9/examples/shopping_ads/add_shopping_product_ad.py#L180-L213\n \n```\n\n### Ruby\n\n```ruby\ndef add_shopping_product_ad_group(client, customer_id, campaign_name)\n operation = client.operation.create_resource.ad_group do |ad_group|\n ad_group.name = \"Earth to Mars cruise ##{(Time.new.to_f * 1000).to_i}\"\n ad_group.status = :ENABLED\n ad_group.campaign = campaign_name\n ad_group.type = :SHOPPING_PRODUCT_ADS\n ad_group.cpc_bid_micros = 10_000_000\n end\n\n service = client.service.ad_group\n response = service.mutate_ad_groups(\n customer_id: customer_id,\n operations: [operation],\n )\n\n ad_group_name = response.results.first.resource_name\n\n puts \"Added a product shopping ad group with resource name #{ad_group_name}.\"\n\n ad_group_name\nend \nhttps://github.com/googleads/google-ads-ruby/blob/2752563c7ffd15a4d2238116869f64aea3011cc3/examples/shopping_ads/add_shopping_product_ad.rb#L125-L145\n\n \n```\n\n### Perl\n\n```perl\nsub add_shopping_product_ad_group {\n my ($api_client, $customer_id, $campaign_resource_name) = @_;\n\n # Create an ad group.\n my $ad_group = Google::Ads::GoogleAds::V21::Resources::AdGroup-\u003enew({\n name =\u003e \"Earth to Mars Cruises #\" . uniqid(),\n campaign =\u003e $campaign_resource_name,\n # Set the ad group type to SHOPPING_PRODUCT_ADS. This is the only value\n # possible for ad groups that contain shopping product ads.\n type =\u003e SHOPPING_PRODUCT_ADS,\n cpcBidMicros =\u003e 1000000,\n status =\u003e Google::Ads::GoogleAds::V21::Enums::AdGroupStatusEnum::ENABLED\n });\n\n # Create an ad group operation.\n my $ad_group_operation =\n Google::Ads::GoogleAds::V21::Services::AdGroupService::AdGroupOperation-\u003e\n new({create =\u003e $ad_group});\n\n # Add the ad group.\n my $ad_group_resource_name = $api_client-\u003eAdGroupService()-\u003emutate({\n customerId =\u003e $customer_id,\n operations =\u003e [$ad_group_operation]})-\u003e{results}[0]{resourceName};\n\n printf \"Added a product shopping ad group with resource name: '%s'.\\n\",\n $ad_group_resource_name;\n\n return $ad_group_resource_name;\n}https://github.com/googleads/google-ads-perl/blob/9abffd69cd856633dfdcee5c636fe9cd0eb4b5ed/examples/shopping_ads/add_shopping_product_ad.pl#L203-L231\n \n```\n\n\u003cbr /\u003e"]]