یک گروه تبلیغاتی چیزهایی که باید انجام شود ایجاد کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای ارائه تبلیغات برای کمپین چیزهایی که باید انجام دهید، باید یک AdGroup
با حداقل یک تبلیغ در گروه تبلیغاتی ایجاد کنید. همانطور که بعدا نشان داده شد، یک کمپین فقط از یک گروه تبلیغاتی از نوع TRAVEL_ADS
پشتیبانی می کند که می توانید آن را در قسمت type
تنظیم کنید.
جاوا
private String addAdGroup(
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 TRAVEL_ADS. This cannot be set to other types.
.setType(AdGroupType.TRAVEL_ADS)
.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 an ad group with resource name: '%s'%n", mutateAdGroupResult.getResourceName());
return mutateAdGroupResult.getResourceName();
}
}
سی شارپ
private static string CreateAdGroup(GoogleAdsClient client, long customerId,
string campaign)
{
// Get the AdGroupService.
AdGroupServiceClient adGroupService = client.GetService(Services.V21.AdGroupService);
// Create the ad group.
AdGroup adGroup = new AdGroup()
{
Name = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
Status = AdGroupStatus.Enabled,
Campaign = campaign,
Type = AdGroupType.TravelAds
};
MutateAdGroupsResponse response = adGroupService.MutateAdGroups(
customerId.ToString(), new AdGroupOperation[] { new AdGroupOperation() {
Create = adGroup
}}
);
string adGroupResourceName = response.Results[0].ResourceName;
Console.WriteLine("Ad group with resource name = '{0}' was added.", adGroupResourceName);
return adGroupResourceName;
}
PHP
private static function addAdGroup(
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 TRAVEL_ADS. This cannot be set to other types.
'type' => AdGroupType::TRAVEL_ADS,
'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 an ad group with resource name '%s'.%s",
$addedAdGroup->getResourceName(),
PHP_EOL
);
return $addedAdGroup->getResourceName();
}
پایتون
def add_ad_group(
client: GoogleAdsClient, customer_id: str, campaign_resource_name: str
) -> str:
"""Creates a new ad group in the specified Things to do campaign.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
campaign_resource_name: the resource name of campaign that a new ad
group will belong to.
Returns:
The resource name of the newly created ad group.
"""
# Creates an ad group operation.
operation: AdGroupOperation = client.get_type("AdGroupOperation")
# Creates an ad group.
ad_group: AdGroup = operation.create
ad_group.name = f"Earth to Mars cruise #{get_printable_datetime()}"
# Sets the campaign.
ad_group.campaign = campaign_resource_name
# Sets the ad group type to TRAVEL_ADS. This is the only value allowed
# for this field on an ad group for a Things to do campaign.
ad_group.type_ = client.enums.AdGroupTypeEnum.TRAVEL_ADS
ad_group.status = client.enums.AdGroupStatusEnum.ENABLED
# Issues a mutate request to add an ad group.
ad_group_service: AdGroupServiceClient = client.get_service(
"AdGroupService"
)
ad_group_response: MutateAdGroupsResponse = (
ad_group_service.mutate_ad_groups(
customer_id=customer_id, operations=[operation]
)
)
resource_name: str = ad_group_response.results[0].resource_name
print(f"Added an ad group with resource name: '{resource_name}'.")
return resource_name
روبی
def add_ad_group(client, customer_id, campaign_resource)
# Create an ad group.
ad_group_operation = client.operation.create_resource.ad_group do |ag|
ag.name = generate_random_name_field("Earth to Mars Cruise")
# Set the campaign.
ag.campaign = campaign_resource
# Set the ad group type to TRAVEL_ADS.
# This cannot be set to other types.
ag.type = :TRAVEL_ADS
ag.status = :ENABLED
end
# Issue a mutate request to add the ad group.
ad_group_service = client.service.ad_group
response = ad_group_service.mutate_ad_groups(
customer_id: customer_id,
operations: [ad_group_operation]
)
# Fetch the new ad group's resource name.
ad_group_resource = response.results.first.resource_name
puts "Added an ad group with resource name '#{ad_group_resource}'."
ad_group_resource
end
پرل
sub add_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 Cruise #" . uniqid(),
# Set the campaign.
campaign => $campaign_resource_name,
# Set the ad group type to TRAVEL_ADS.
# This cannot be set to other types.
type => TRAVEL_ADS,
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 an ad group with resource name: '%s'.\n",
$ad_group_resource_name;
return $ad_group_resource_name;
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eTo run Things to do campaign ads, you need to create an \u003ccode\u003eAdGroup\u003c/code\u003e containing at least one ad.\u003c/p\u003e\n"],["\u003cp\u003eThings to do campaigns exclusively support ad groups of the \u003ccode\u003eTRAVEL_ADS\u003c/code\u003e type, which must be specified in the \u003ccode\u003etype\u003c/code\u003e field.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets demonstrate how to create an ad group with the \u003ccode\u003eTRAVEL_ADS\u003c/code\u003e type using the Google Ads API in various programming languages.\u003c/p\u003e\n"]]],[],null,["# Create a Things to do ad group\n\nTo serve ads for your Things to do campaign, you must create an\n[`AdGroup`](/google-ads/api/reference/rpc/v21/AdGroup) with at least one ad in the ad group. As\nshown later, a campaign supports only an ad group of the\n[`TRAVEL_ADS`](/google-ads/api/reference/rpc/v21/AdGroupTypeEnum.AdGroupType#travel_ads) type,\nwhich you can set in the [`type`](/google-ads/api/reference/rpc/v21/AdGroup#type) field.\n\n\n### Java\n\n```java\nprivate String addAdGroup(\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 TRAVEL_ADS. This cannot be set to other types.\n .setType(AdGroupType.TRAVEL_ADS)\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 an ad group with resource name: '%s'%n\", mutateAdGroupResult.getResourceName());\n return mutateAdGroupResult.getResourceName();\n }\n}https://github.com/googleads/google-ads-java/blob/3c3c1041c2a0ab81553e3b2a79876256649397ed/google-ads-examples/src/main/java/com/google/ads/googleads/examples/travel/AddThingsToDoAd.java#L252-L278\n \n```\n\n### C#\n\n```c#\nprivate static string CreateAdGroup(GoogleAdsClient client, long customerId,\n string campaign)\n{\n // Get the AdGroupService.\n AdGroupServiceClient adGroupService = client.GetService(Services.V21.AdGroupService);\n\n // Create the ad group.\n AdGroup adGroup = new AdGroup()\n {\n Name = $\"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}\",\n Status = AdGroupStatus.Enabled,\n Campaign = campaign,\n Type = AdGroupType.TravelAds\n };\n\n MutateAdGroupsResponse response = adGroupService.MutateAdGroups(\n customerId.ToString(), new AdGroupOperation[] { new AdGroupOperation() {\n Create = adGroup\n }}\n );\n\n string adGroupResourceName = response.Results[0].ResourceName;\n Console.WriteLine(\"Ad group with resource name = '{0}' was added.\", adGroupResourceName);\n\n return adGroupResourceName;\n}https://github.com/googleads/google-ads-dotnet/blob/ada966e1983b655e82172b6c3e7d9b091b522377/Google.Ads.GoogleAds/examples/Travel/AddThingsToDoAd.cs#L209-L234\n \n```\n\n### PHP\n\n```php\nprivate static function addAdGroup(\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 TRAVEL_ADS. This cannot be set to other types.\n 'type' =\u003e AdGroupType::TRAVEL_ADS,\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 an 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/Travel/AddThingsToDoAd.php#L268-L302\n\n \n```\n\n### Python\n\n```python\ndef add_ad_group(\n client: GoogleAdsClient, customer_id: str, campaign_resource_name: str\n) -\u003e str:\n \"\"\"Creates a new ad group in the specified Things to do campaign.\n\n Args:\n client: an initialized GoogleAdsClient instance.\n customer_id: a client customer ID.\n campaign_resource_name: the resource name of campaign that a new ad\n group will belong to.\n\n Returns:\n The resource name of the newly created ad group.\n \"\"\"\n # Creates an ad group operation.\n operation: AdGroupOperation = client.get_type(\"AdGroupOperation\")\n # Creates an ad group.\n ad_group: AdGroup = operation.create\n ad_group.name = f\"Earth to Mars cruise #{get_printable_datetime()}\"\n # Sets the campaign.\n ad_group.campaign = campaign_resource_name\n # Sets the ad group type to TRAVEL_ADS. This is the only value allowed\n # for this field on an ad group for a Things to do campaign.\n ad_group.type_ = client.enums.AdGroupTypeEnum.TRAVEL_ADS\n ad_group.status = client.enums.AdGroupStatusEnum.ENABLED\n\n # Issues a mutate request to add an ad group.\n ad_group_service: AdGroupServiceClient = client.get_service(\n \"AdGroupService\"\n )\n ad_group_response: MutateAdGroupsResponse = (\n ad_group_service.mutate_ad_groups(\n customer_id=customer_id, operations=[operation]\n )\n )\n\n resource_name: str = ad_group_response.results[0].resource_name\n print(f\"Added an ad group with resource name: '{resource_name}'.\")\n return resource_name \nhttps://github.com/googleads/google-ads-python/blob/d0595698b8a7de6cc00684b467462601037c9db9/examples/travel/add_things_to_do_ad.py#L215-L253\n \n```\n\n### Ruby\n\n```ruby\ndef add_ad_group(client, customer_id, campaign_resource)\n # Create an ad group.\n ad_group_operation = client.operation.create_resource.ad_group do |ag|\n ag.name = generate_random_name_field(\"Earth to Mars Cruise\")\n\n # Set the campaign.\n ag.campaign = campaign_resource\n\n # Set the ad group type to TRAVEL_ADS.\n # This cannot be set to other types.\n ag.type = :TRAVEL_ADS\n ag.status = :ENABLED\n end\n\n # Issue a mutate request to add the ad group.\n ad_group_service = client.service.ad_group\n response = ad_group_service.mutate_ad_groups(\n customer_id: customer_id,\n operations: [ad_group_operation]\n )\n\n # Fetch the new ad group's resource name.\n ad_group_resource = response.results.first.resource_name\n\n puts \"Added an ad group with resource name '#{ad_group_resource}'.\"\n\n ad_group_resource\nend \nhttps://github.com/googleads/google-ads-ruby/blob/2752563c7ffd15a4d2238116869f64aea3011cc3/examples/travel/add_things_to_do_ad.rb#L141-L168\n\n \n```\n\n### Perl\n\n```perl\nsub add_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 Cruise #\" . uniqid(),\n # Set the campaign.\n campaign =\u003e $campaign_resource_name,\n # Set the ad group type to TRAVEL_ADS.\n # This cannot be set to other types.\n type =\u003e TRAVEL_ADS,\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 an 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/travel/add_things_to_do_ad.pl#L178-L206\n \n```\n\n\u003cbr /\u003e"]]