ショッピング広告グループの作成
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
通常のショッピング キャンペーンでショッピングの商品広告を作成する手順は次のとおりです。
ShoppingProductAdInfo
オブジェクトを作成し、新しい Ad
オブジェクトの shopping_product_ad
フィールドとして設定します。
AdGroupAd
を作成し、ad
フィールドを以前に作成した Ad
オブジェクトに設定します。
次のサンプルコードは、通常のショッピング キャンペーンの SHOPPING_PRODUCT_AD
広告グループ広告を作成する方法を示しています。
Java
private String addShoppingProductAdGroupAd(
GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {
// Creates a new shopping product ad.
Ad ad =
Ad.newBuilder().setShoppingProductAd(ShoppingProductAdInfo.newBuilder().build()).build();
// Creates a new ad group ad and sets the shopping product ad to it.
AdGroupAd adGroupAd =
AdGroupAd.newBuilder()
// Sets the ad to the ad created above.
.setAd(ad)
.setStatus(AdGroupAdStatus.PAUSED)
// Sets the ad group.
.setAdGroup(adGroupResourceName)
.build();
// Creates an ad group ad operation.
AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();
// Issues a mutate request to add an ad group ad.
try (AdGroupAdServiceClient adGroupAdServiceClient =
googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {
MutateAdGroupAdResult mutateAdGroupAdResult =
adGroupAdServiceClient
.mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation))
.getResults(0);
System.out.printf(
"Added a product shopping ad group ad with resource name: '%s'%n",
mutateAdGroupAdResult.getResourceName());
return mutateAdGroupAdResult.getResourceName();
}
}
C#
private string AddProductShoppingAdGroupAd(GoogleAdsClient client, long customerId,
string adGroupResourceName)
{
// Get the AdGroupAdService.
AdGroupAdServiceClient adGroupAdService = client.GetService(
Services.V21.AdGroupAdService);
// Creates a new shopping product ad.
Ad ad = new Ad()
{
ShoppingProductAd = new ShoppingProductAdInfo()
{
}
};
// Creates a new ad group ad and sets the shopping product ad to it.
AdGroupAd adGroupAd = new AdGroupAd()
{
// Sets the ad to the ad created above.
Ad = ad,
Status = AdGroupAdStatus.Paused,
// Sets the ad group.
AdGroup = adGroupResourceName
};
// Creates an ad group ad operation.
AdGroupAdOperation operation = new AdGroupAdOperation()
{
Create = adGroupAd
};
// Issues a mutate request to add an ad group ad.
MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdService.MutateAdGroupAds(
customerId.ToString(), new AdGroupAdOperation[] { operation }).Results[0];
Console.WriteLine("Added a product shopping ad group ad with resource name: '{0}'.",
mutateAdGroupAdResult.ResourceName);
return mutateAdGroupAdResult.ResourceName;
}
PHP
private static function addShoppingProductAdGroupAd(
GoogleAdsClient $googleAdsClient,
int $customerId,
string $adGroupResourceName
) {
// Creates a new shopping product ad.
$ad = new Ad(['shopping_product_ad' => new ShoppingProductAdInfo()]);
// Creates a new ad group ad and sets the shopping product ad to it.
$adGroupAd = new AdGroupAd([
'ad' => $ad,
'status' => AdGroupAdStatus::PAUSED,
// Sets the ad group.
'ad_group' => $adGroupResourceName
]);
// Creates an ad group ad operation.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setCreate($adGroupAd);
// Issues a mutate request to add an ad group ad.
$adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
$response = $adGroupAdServiceClient->mutateAdGroupAds(
MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation])
);
/** @var AdGroupAd $addedAdGroupAd */
$addedAdGroupAd = $response->getResults()[0];
printf(
"Added a shopping product ad group ad with resource name '%s'.%s",
$addedAdGroupAd->getResourceName(),
PHP_EOL
);
}
Python
def add_shopping_product_ad_group_ad(
client: GoogleAdsClient,
customer_id: str,
ad_group_resource_name: str,
) -> str:
"""Creates a new shopping product ad group ad in the specified ad group."""
ad_group_ad_service: AdGroupAdServiceClient = client.get_service(
"AdGroupAdService"
)
# Creates a new ad group ad and sets the product ad to it.
ad_group_ad_operation: AdGroupAdOperation = client.get_type(
"AdGroupAdOperation"
)
ad_group_ad: AdGroupAd = ad_group_ad_operation.create
ad_group_ad.ad_group = ad_group_resource_name
ad_group_ad.status = client.enums.AdGroupAdStatusEnum.PAUSED
# The Ad object itself is not directly manipulated for Shopping Product Ads.
# Instead, we copy ShoppingProductAdInfo into the ad's shopping_product_ad field.
client.copy_from(
ad_group_ad.ad.shopping_product_ad,
client.get_type("ShoppingProductAdInfo"),
)
# 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]
)
ad_group_ad_resource_name: str = ad_group_ad_response.results[
0
].resource_name
print(
f"Created shopping product ad group ad '{ad_group_ad_resource_name}'."
)
Ruby
def add_shopping_product_ad_group_ad(client, customer_id, ad_group_name)
operation = client.operation.create_resource.ad_group_ad do |ad_group_ad|
ad_group_ad.ad_group = ad_group_name
ad_group_ad.status = :PAUSED
ad_group_ad.ad = client.resource.ad do |ad|
ad.shopping_product_ad = client.resource.shopping_product_ad_info
end
end
service = client.service.ad_group_ad
response = service.mutate_ad_group_ads(
customer_id: customer_id,
operations: [operation],
)
puts "Created shopping product ad group ad " \
"#{response.results.first.resource_name}"
end
Perl
sub add_shopping_product_ad_group_ad {
my ($api_client, $customer_id, $ad_group_resource_name) = @_;
# Create an ad group ad and set a shopping product ad to it.
my $ad_group_ad = Google::Ads::GoogleAds::V21::Resources::AdGroupAd->new({
# Set the ad group.
adGroup => $ad_group_resource_name,
# Set the ad to a new shopping product ad.
ad => Google::Ads::GoogleAds::V21::Resources::Ad->new({
shoppingProductAd =>
Google::Ads::GoogleAds::V21::Common::ShoppingProductAdInfo->new()}
),
status => Google::Ads::GoogleAds::V21::Enums::AdGroupAdStatusEnum::PAUSED
});
# Create an ad group ad operation.
my $ad_group_ad_operation =
Google::Ads::GoogleAds::V21::Services::AdGroupAdService::AdGroupAdOperation
->new({create => $ad_group_ad});
# Add the ad group ad.
my $ad_group_ad_resource_name = $api_client->AdGroupAdService()->mutate({
customerId => $customer_id,
operations => [$ad_group_ad_operation]})->{results}[0]{resourceName};
printf "Added a product shopping ad group ad with resource name: '%s'.\n",
$ad_group_ad_resource_name;
return $ad_group_ad_resource_name;
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-31 UTC。
[null,null,["最終更新日 2025-08-31 UTC。"],[[["\u003cp\u003eTo create a Shopping product ad, you need to create a \u003ccode\u003eShoppingProductAdInfo\u003c/code\u003e object and set it within a new \u003ccode\u003eAd\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eThis \u003ccode\u003eAd\u003c/code\u003e object is then used to create an \u003ccode\u003eAdGroupAd\u003c/code\u003e, linking the ad to a specific ad group within your campaign.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples demonstrate this process using the Google Ads API in various programming languages such as Java, C#, PHP, Python, Ruby, and Perl.\u003c/p\u003e\n"],["\u003cp\u003eThis process focuses on creating Shopping product ads specifically for standard Shopping campaigns within Google Ads.\u003c/p\u003e\n"]]],[],null,["# Creating a Shopping Ad Group Ad\n\nCreating a Shopping product ad for a standard Shopping campaign involves two\nsteps:\n\n1. Create a [`ShoppingProductAdInfo`](/google-ads/api/reference/rpc/v21/ShoppingProductAdInfo)\n object and set it as the\n [`shopping_product_ad`](/google-ads/api/reference/rpc/v21/Ad#shopping_product_ad)\n field of a new [`Ad`](/google-ads/api/reference/rpc/v21/Ad) object.\n\n2. Create an [`AdGroupAd`](/google-ads/api/reference/rpc/v21/AdGroupAd) and set the\n [`ad`](/google-ads/api/reference/rpc/v21/AdGroupAd#ad) field to the previously created `Ad`\n object.\n\nThis code example demonstrates how to create a\n[`SHOPPING_PRODUCT_AD`](/google-ads/api/reference/rpc/v21/AdTypeEnum.AdType#shopping_product_ad) ad\ngroup ad for a standard Shopping campaign.\n\n\n### Java\n\n```java\nprivate String addShoppingProductAdGroupAd(\n GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {\n // Creates a new shopping product ad.\n Ad ad =\n Ad.newBuilder().setShoppingProductAd(ShoppingProductAdInfo.newBuilder().build()).build();\n // Creates a new ad group ad and sets the shopping product ad to it.\n AdGroupAd adGroupAd =\n AdGroupAd.newBuilder()\n // Sets the ad to the ad created above.\n .setAd(ad)\n .setStatus(AdGroupAdStatus.PAUSED)\n // Sets the ad group.\n .setAdGroup(adGroupResourceName)\n .build();\n\n // Creates an ad group ad operation.\n AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();\n\n // Issues a mutate request to add an ad group ad.\n try (AdGroupAdServiceClient adGroupAdServiceClient =\n googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {\n MutateAdGroupAdResult mutateAdGroupAdResult =\n adGroupAdServiceClient\n .mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation))\n .getResults(0);\n System.out.printf(\n \"Added a product shopping ad group ad with resource name: '%s'%n\",\n mutateAdGroupAdResult.getResourceName());\n return mutateAdGroupAdResult.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#L326-L357\n \n```\n\n### C#\n\n```c#\nprivate string AddProductShoppingAdGroupAd(GoogleAdsClient client, long customerId,\n string adGroupResourceName)\n{\n // Get the AdGroupAdService.\n AdGroupAdServiceClient adGroupAdService = client.GetService(\n Services.V21.AdGroupAdService);\n\n // Creates a new shopping product ad.\n Ad ad = new Ad()\n {\n ShoppingProductAd = new ShoppingProductAdInfo()\n {\n }\n };\n\n // Creates a new ad group ad and sets the shopping product ad to it.\n AdGroupAd adGroupAd = new AdGroupAd()\n {\n // Sets the ad to the ad created above.\n Ad = ad,\n\n Status = AdGroupAdStatus.Paused,\n\n // Sets the ad group.\n AdGroup = adGroupResourceName\n };\n\n // Creates an ad group ad operation.\n AdGroupAdOperation operation = new AdGroupAdOperation()\n {\n Create = adGroupAd\n };\n\n // Issues a mutate request to add an ad group ad.\n MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdService.MutateAdGroupAds(\n customerId.ToString(), new AdGroupAdOperation[] { operation }).Results[0];\n Console.WriteLine(\"Added a product shopping ad group ad with resource name: '{0}'.\",\n mutateAdGroupAdResult.ResourceName);\n return mutateAdGroupAdResult.ResourceName;\n}https://github.com/googleads/google-ads-dotnet/blob/ada966e1983b655e82172b6c3e7d9b091b522377/Google.Ads.GoogleAds/examples/ShoppingAds/AddShoppingProductAd.cs#L324-L363\n \n```\n\n### PHP\n\n```php\nprivate static function addShoppingProductAdGroupAd(\n GoogleAdsClient $googleAdsClient,\n int $customerId,\n string $adGroupResourceName\n) {\n // Creates a new shopping product ad.\n $ad = new Ad(['shopping_product_ad' =\u003e new ShoppingProductAdInfo()]);\n\n // Creates a new ad group ad and sets the shopping product ad to it.\n $adGroupAd = new AdGroupAd([\n 'ad' =\u003e $ad,\n 'status' =\u003e AdGroupAdStatus::PAUSED,\n // Sets the ad group.\n 'ad_group' =\u003e $adGroupResourceName\n ]);\n\n // Creates an ad group ad operation.\n $adGroupAdOperation = new AdGroupAdOperation();\n $adGroupAdOperation-\u003esetCreate($adGroupAd);\n\n // Issues a mutate request to add an ad group ad.\n $adGroupAdServiceClient = $googleAdsClient-\u003egetAdGroupAdServiceClient();\n $response = $adGroupAdServiceClient-\u003emutateAdGroupAds(\n MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation])\n );\n\n /** @var AdGroupAd $addedAdGroupAd */\n $addedAdGroupAd = $response-\u003egetResults()[0];\n printf(\n \"Added a shopping product ad group ad with resource name '%s'.%s\",\n $addedAdGroupAd-\u003egetResourceName(),\n PHP_EOL\n );\n} \nhttps://github.com/googleads/google-ads-php/blob/be0249c30c27b4760387bec6682b82c9f4167761/examples/ShoppingAds/AddShoppingProductAd.php#L340-L373\n\n \n```\n\n### Python\n\n```python\ndef add_shopping_product_ad_group_ad(\n client: GoogleAdsClient,\n customer_id: str,\n ad_group_resource_name: str,\n) -\u003e str:\n \"\"\"Creates a new shopping product ad group ad in the specified ad group.\"\"\"\n ad_group_ad_service: AdGroupAdServiceClient = client.get_service(\n \"AdGroupAdService\"\n )\n\n # Creates a new ad group ad and sets the product ad to it.\n ad_group_ad_operation: AdGroupAdOperation = client.get_type(\n \"AdGroupAdOperation\"\n )\n ad_group_ad: AdGroupAd = ad_group_ad_operation.create\n ad_group_ad.ad_group = ad_group_resource_name\n ad_group_ad.status = client.enums.AdGroupAdStatusEnum.PAUSED\n # The Ad object itself is not directly manipulated for Shopping Product Ads.\n # Instead, we copy ShoppingProductAdInfo into the ad's shopping_product_ad field.\n client.copy_from(\n ad_group_ad.ad.shopping_product_ad,\n client.get_type(\"ShoppingProductAdInfo\"),\n )\n\n # Add the ad group ad.\n ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(\n customer_id=customer_id, operations=[ad_group_ad_operation]\n )\n\n ad_group_ad_resource_name: str = ad_group_ad_response.results[\n 0\n ].resource_name\n\n print(\n f\"Created shopping product ad group ad '{ad_group_ad_resource_name}'.\"\n )https://github.com/googleads/google-ads-python/blob/d0595698b8a7de6cc00684b467462601037c9db9/examples/shopping_ads/add_shopping_product_ad.py#L140-L175\n \n```\n\n### Ruby\n\n```ruby\ndef add_shopping_product_ad_group_ad(client, customer_id, ad_group_name)\n\n operation = client.operation.create_resource.ad_group_ad do |ad_group_ad|\n ad_group_ad.ad_group = ad_group_name\n ad_group_ad.status = :PAUSED\n ad_group_ad.ad = client.resource.ad do |ad|\n ad.shopping_product_ad = client.resource.shopping_product_ad_info\n end\n end\n\n service = client.service.ad_group_ad\n response = service.mutate_ad_group_ads(\n customer_id: customer_id,\n operations: [operation],\n )\n\n puts \"Created shopping product ad group ad \" \\\n \"#{response.results.first.resource_name}\"\nend \nhttps://github.com/googleads/google-ads-ruby/blob/2752563c7ffd15a4d2238116869f64aea3011cc3/examples/shopping_ads/add_shopping_product_ad.rb#L149-L167\n\n \n```\n\n### Perl\n\n```perl\nsub add_shopping_product_ad_group_ad {\n my ($api_client, $customer_id, $ad_group_resource_name) = @_;\n\n # Create an ad group ad and set a shopping product ad to it.\n my $ad_group_ad = Google::Ads::GoogleAds::V21::Resources::AdGroupAd-\u003enew({\n # Set the ad group.\n adGroup =\u003e $ad_group_resource_name,\n # Set the ad to a new shopping product ad.\n ad =\u003e Google::Ads::GoogleAds::V21::Resources::Ad-\u003enew({\n shoppingProductAd =\u003e\n Google::Ads::GoogleAds::V21::Common::ShoppingProductAdInfo-\u003enew()}\n ),\n status =\u003e Google::Ads::GoogleAds::V21::Enums::AdGroupAdStatusEnum::PAUSED\n });\n\n # Create an ad group ad operation.\n my $ad_group_ad_operation =\n Google::Ads::GoogleAds::V21::Services::AdGroupAdService::AdGroupAdOperation\n -\u003enew({create =\u003e $ad_group_ad});\n\n # Add the ad group ad.\n my $ad_group_ad_resource_name = $api_client-\u003eAdGroupAdService()-\u003emutate({\n customerId =\u003e $customer_id,\n operations =\u003e [$ad_group_ad_operation]})-\u003e{results}[0]{resourceName};\n\n printf \"Added a product shopping ad group ad with resource name: '%s'.\\n\",\n $ad_group_ad_resource_name;\n\n return $ad_group_ad_resource_name;\n}https://github.com/googleads/google-ads-perl/blob/9abffd69cd856633dfdcee5c636fe9cd0eb4b5ed/examples/shopping_ads/add_shopping_product_ad.pl#L236-L265\n \n```\n\n\u003cbr /\u003e"]]