برای نمایش تبلیغات برای کمپین «کارهایتان را انجام دهید»، باید یک 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.V22.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; }
پی اچ پی
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(); }