Creating a Shopping Ad Group

To serve ads for your Shopping campaign, you must create anAdGroup.

Standard Shopping campaigns support theSHOPPING_PRODUCT_ADSad group type. This is the default ad group type for Shopping campaigns, servingstandard product ads. It can be set by providing the ad grouptype field.

Standard Shopping campaigns can contain multiple ad groups, each containing atleast one ad.

This code example demonstrates how to create an ad group for a standard Shoppingcampaign. The example also sets a CPC bid to match the campaign's bid strategy,which is set toManualCpc.

Java

privateStringaddShoppingProductAdGroup(GoogleAdsClientgoogleAdsClient,longcustomerId,StringcampaignResourceName){// Creates an ad group.AdGroupadGroup=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.AdGroupOperationoperation=AdGroupOperation.newBuilder().setCreate(adGroup).build();// Issues a mutate request to add an ad group.try(AdGroupServiceClientadGroupServiceClient=googleAdsClient.getLatestVersion().createAdGroupServiceClient()){MutateAdGroupResultmutateAdGroupResult=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());returnmutateAdGroupResult.getResourceName();}}

C#

privatestringAddProductShoppingAdGroup(GoogleAdsClientclient,longcustomerId,stringcampaignResourceName){// Get the AdGroupService.AdGroupServiceClientadGroupService=client.GetService(Services.V20.AdGroupService);// Creates an ad group.AdGroupadGroup=newAdGroup(){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.AdGroupOperationoperation=newAdGroupOperation(){Create=adGroup};// Issues a mutate request to add an ad group.MutateAdGroupResultmutateAdGroupResult=adGroupService.MutateAdGroups(customerId.ToString(),newAdGroupOperation[]{operation}).Results[0];Console.WriteLine("Added a product shopping ad group with resource name: '{0}'.",mutateAdGroupResult.ResourceName);returnmutateAdGroupResult.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

defadd_shopping_product_ad_group(client,customer_id,campaign_resource_name):"""Creates a new shopping product ad group in the specified campaign."""ad_group_service=client.get_service("AdGroupService")# Create ad group.ad_group_operation=client.get_type("AdGroupOperation")ad_group=ad_group_operation.createad_group.name=f"Earth to Mars cruise{uuid.uuid4()}"ad_group.status=client.enums.AdGroupStatusEnum.ENABLEDad_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_ADSad_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=ad_group_response.results[0].resource_nameprint("Added a product shopping ad group with resource name "f"'{ad_group_resource_name}'.")returnad_group_resource_name

Ruby

defadd_shopping_product_ad_group(client,customer_id,campaign_name)operation=client.operation.create_resource.ad_groupdo|ad_group|ad_group.name="Earth to Mars cruise ##{(Time.new.to_f*1000).to_i}"ad_group.status=:ENABLEDad_group.campaign=campaign_namead_group.type=:SHOPPING_PRODUCT_ADSad_group.cpc_bid_micros=10_000_000endservice=client.service.ad_groupresponse=service.mutate_ad_groups(customer_id:customer_id,operations:[operation],)ad_group_name=response.results.first.resource_nameputs"Added a product shopping ad group with resource name#{ad_group_name}."ad_group_nameend

Perl

subadd_shopping_product_ad_group{my($api_client,$customer_id,$campaign_resource_name)=@_;# Create an ad group.my$ad_group=Google::Ads::GoogleAds::V20::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::V20::Enums::AdGroupStatusEnum::ENABLED});# Create an ad group operation.my$ad_group_operation=Google::Ads::GoogleAds::V20::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;}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-11 UTC.