This guide provides a checklist of concepts and tasks for each of the three Performance Max business goals to help you build your campaign. To get started, select a business goal:
Performance Max for online sales with a product feed (retail)
Performance Max allows advertisers to access all Google Ads channels and inventory from a single, unified campaign. The steps to create a Performance Max campaign for retail are as follows. Click the links in each section for more information.
Performance Max concepts
Performance Max for online sales with a product feed helps you expand your reach and goals by offering the opportunity to serve on additional inventory.
When creating a Performance Max campaign, you can use a bulk mutate request to create the resources required to form a valid, serving campaign in a single request. Not all resources must be created in a single bulk mutate request. The following resources are required to create a valid, serving Performance Max campaign. Learn more in the Structure requests guide.
CampaignBudget
Campaign
AssetGroups
AssetGroupAssets
(if applicable)AssetGroupListingGroupFilters
Campaign and campaign budget
- The budget must have a
DAILY
budget period (learn more). - The budget cannot be shared.
Code example
Java
/** Creates a MutateOperation that creates a new CampaignBudget. */ private MutateOperation createCampaignBudgetOperation(long customerId) { CampaignBudget campaignBudget = CampaignBudget.newBuilder() .setName("Performance Max campaign budget #" + getPrintableDateTime()) // The budget period already defaults to DAILY. .setAmountMicros(50_000_000) .setDeliveryMethod(BudgetDeliveryMethod.STANDARD) // A Performance Max campaign cannot use a shared campaign budget. .setExplicitlyShared(false) // Set a temporary ID in the budget's resource name, so it can be referenced // by the campaign in later steps. .setResourceName(ResourceNames.campaignBudget(customerId, BUDGET_TEMPORARY_ID)) .build(); return MutateOperation.newBuilder() .setCampaignBudgetOperation( CampaignBudgetOperation.newBuilder().setCreate(campaignBudget).build()) .build(); }
C#
/// <summary> /// Creates a MutateOperation that creates a new CampaignBudget. /// /// A temporary ID will be assigned to this campaign budget so that it can be /// referenced by other objects being created in the same Mutate request. /// </summary> /// <param name="budgetResourceName">The temporary resource name of the budget to /// create.</param> /// <returns>A MutateOperation that creates a CampaignBudget.</returns> private MutateOperation CreateCampaignBudgetOperation(string budgetResourceName) { MutateOperation operation = new MutateOperation { CampaignBudgetOperation = new CampaignBudgetOperation { Create = new CampaignBudget { Name = "Performance Max campaign budget #" + ExampleUtilities.GetRandomString(), // The budget period already defaults to DAILY. AmountMicros = 50000000, DeliveryMethod = BudgetDeliveryMethod.Standard, // A Performance Max campaign cannot use a shared campaign budget. ExplicitlyShared = false, // Set a temporary ID in the budget's resource name so it can be referenced // by the campaign in later steps. ResourceName = budgetResourceName } } }; return operation; }
PHP
private static function createCampaignBudgetOperation(int $customerId): MutateOperation { // Creates a mutate operation that creates a campaign budget operation. return new MutateOperation([ 'campaign_budget_operation' => new CampaignBudgetOperation([ 'create' => new CampaignBudget([ // Sets a temporary ID in the budget's resource name so it can be referenced // by the campaign in later steps. 'resource_name' => ResourceNames::forCampaignBudget( $customerId, self::BUDGET_TEMPORARY_ID ), 'name' => 'Performance Max campaign budget #' . Helper::getPrintableDatetime(), // The budget period already defaults to DAILY. 'amount_micros' => 50000000, 'delivery_method' => BudgetDeliveryMethod::STANDARD, // A Performance Max campaign cannot use a shared campaign budget. 'explicitly_shared' => false ]) ]) ]); }
Python
def create_campaign_budget_operation( client, customer_id, ): """Creates a MutateOperation that creates a new CampaignBudget. A temporary ID will be assigned to this campaign budget so that it can be referenced by other objects being created in the same Mutate request. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. Returns: a MutateOperation that creates a CampaignBudget. """ mutate_operation = client.get_type("MutateOperation") campaign_budget_operation = mutate_operation.campaign_budget_operation campaign_budget = campaign_budget_operation.create campaign_budget.name = f"Performance Max campaign budget #{uuid4()}" # The budget period already defaults to DAILY. campaign_budget.amount_micros = 50000000 campaign_budget.delivery_method = ( client.enums.BudgetDeliveryMethodEnum.STANDARD ) # A Performance Max campaign cannot use a shared campaign budget. campaign_budget.explicitly_shared = False # Set a temporary ID in the budget's resource name so it can be referenced # by the campaign in later steps. campaign_budget.resource_name = client.get_service( "CampaignBudgetService" ).campaign_budget_path(customer_id, _BUDGET_TEMPORARY_ID) return mutate_operation
Ruby
# Creates a MutateOperation that creates a new CampaignBudget. # # A temporary ID will be assigned to this campaign budget so that it can be # referenced by other objects being created in the same Mutate request. def create_campaign_budget_operation(client, customer_id) client.operation.mutate do |m| m.campaign_budget_operation = client.operation.create_resource.campaign_budget do |cb| cb.name = "Performance Max campaign budget #{SecureRandom.uuid}" # The budget period already defaults to DAILY. cb.amount_micros = 50_000_000 cb.delivery_method = :STANDARD # A Performance Max campaign cannot use a shared campaign budget. cb.explicitly_shared = false # Set a temporary ID in the budget's resource name so it can be referenced # by the campaign in later steps. cb.resource_name = client.path.campaign_budget(customer_id, BUDGET_TEMPORARY_ID) end end end
Perl
sub create_campaign_budget_operation { my ($customer_id) = @_; # Create a mutate operation that creates a campaign budget operation. return Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ campaignBudgetOperation => Google::Ads::GoogleAds::V18::Services::CampaignBudgetService::CampaignBudgetOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::CampaignBudget->new( { # Set a temporary ID in the budget's resource name so it can be # referenced by the campaign in later steps. resourceName => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign_budget( $customer_id, BUDGET_TEMPORARY_ID ), name => "Performance Max campaign budget #" . uniqid(), # The budget period already defaults to DAILY. amountMicros => 50000000, deliveryMethod => STANDARD, # A Performance Max campaign cannot use a shared campaign budget. explicitlyShared => "false", })})}); }
Performance Max campaigns have an
AdvertisingChannelType
of PERFORMANCE_MAX
. No AdvertisingChannelSubType
should be set.
These are the only supported bidding strategies:
If you aren't tracking values and care about all of your conversions equally, use the
MaximizeConversions
bidding strategy. An optional target CPA (cost-per-action) can be set. Learn more.If you're tracking values with your conversions, set the
MaximizeConversionValue
bidding strategy. An optional target ROAS (return on ad spend) can be set. Learn more.
Code example
Java
/** Creates a MutateOperation that creates a new Performance Max campaign. */ private MutateOperation createPerformanceMaxCampaignOperation(long customerId) { Campaign performanceMaxCampaign = Campaign.newBuilder() .setName("Performance Max campaign #" + getPrintableDateTime()) // Sets the campaign status as PAUSED. The campaign is the only entity in // the mutate request that should have its status set. .setStatus(CampaignStatus.PAUSED) // All Performance Max campaigns have an advertising_channel_type of // PERFORMANCE_MAX. The advertising_channel_sub_type should not be set. .setAdvertisingChannelType(AdvertisingChannelType.PERFORMANCE_MAX) // Bidding strategy must be set directly on the campaign. // Setting a portfolio bidding strategy by resource name is not supported. // Max Conversion and Maximize Conversion Value are the only strategies // supported for Performance Max campaigns. // An optional ROAS (Return on Advertising Spend) can be set for // maximize_conversion_value. The ROAS value must be specified as a ratio in // the API. It is calculated by dividing "total value" by "total spend". // For more information on Maximize Conversion Value, see the support // article: http://support.google.com/google-ads/answer/7684216. // A targetRoas of 3.5 corresponds to a 350% return on ad spend. .setMaximizeConversionValue( MaximizeConversionValue.newBuilder().setTargetRoas(3.5).build()) // Sets the Final URL expansion opt out. This flag is specific to // Performance Max campaigns. If opted out (True), only the final URLs in // the asset group or URLs specified in the advertiser's Google Merchant // Center or business data feeds are targeted. // If opted in (False), the entire domain will be targeted. For best // results, set this value to false to opt in and allow URL expansions. You // can optionally add exclusions to limit traffic to parts of your website. .setUrlExpansionOptOut(false) // Assigns the resource name with a temporary ID. .setResourceName( ResourceNames.campaign(customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID)) // Sets the budget using the given budget resource name. .setCampaignBudget(ResourceNames.campaignBudget(customerId, BUDGET_TEMPORARY_ID)) // Optional fields. .setStartDate(new DateTime().plusDays(1).toString("yyyyMMdd")) .setEndDate(new DateTime().plusDays(365).toString("yyyyMMdd")) .build(); return MutateOperation.newBuilder() .setCampaignOperation( CampaignOperation.newBuilder().setCreate(performanceMaxCampaign).build()) .build(); }
C#
/// Creates a MutateOperation that creates a new Performance Max campaign. /// <param name="campaignResourceName">The campaign resource name.</param> /// <param name="campaignBudgetResourceName">The campaign budget resource name.</param> /// <returns>A MutateOperations that will create this new campaign.</returns> private MutateOperation CreatePerformanceMaxCampaignOperation( string campaignResourceName, string campaignBudgetResourceName) { MutateOperation operation = new MutateOperation() { CampaignOperation = new CampaignOperation() { Create = new Campaign() { Name = "Performance Max campaign #" + ExampleUtilities.GetRandomString(), // Set the campaign status as PAUSED. The campaign is the only entity in // the mutate request that should have its status set. Status = CampaignStatus.Paused, // All Performance Max campaigns have an AdvertisingChannelType of // PerformanceMax. The AdvertisingChannelSubType should not be set. AdvertisingChannelType = AdvertisingChannelType.PerformanceMax, // Bidding strategy must be set directly on the campaign. Setting a // portfolio bidding strategy by resource name is not supported. Max // Conversion and Maximize Conversion Value are the only strategies // supported for Performance Max campaigns. BiddingStrategyType is // read-only and cannot be set by the API. An optional ROAS (Return on // Advertising Spend) can be set to enable the MaximizeConversionValue // bidding strategy. The ROAS value must be specified as a ratio in the API. // It is calculated by dividing "total value" by "total spend". // // For more information on Maximize Conversion Value, see the support // article: // http://support.google.com/google-ads/answer/7684216. // // A target_roas of 3.5 corresponds to a 350% return on ad spend. MaximizeConversionValue = new MaximizeConversionValue() { TargetRoas = 3.5 }, // Set the Final URL expansion opt out. This flag is specific to // Performance Max campaigns. If opted out (True), only the final URLs in // the asset group or URLs specified in the advertiser's Google Merchant // Center or business data feeds are targeted. // If opted in (False), the entire domain will be targeted. For best // results, set this value to false to opt in and allow URL expansions. You // can optionally add exclusions to limit traffic to parts of your website. UrlExpansionOptOut = false, // Use the temporary resource name created earlier ResourceName = campaignResourceName, // Set the budget using the given budget resource name. CampaignBudget = campaignBudgetResourceName, // Optional fields StartDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"), EndDate = DateTime.Now.AddDays(365).ToString("yyyyMMdd") } } }; return operation; }
PHP
private static function createPerformanceMaxCampaignOperation(int $customerId): MutateOperation { // Creates a mutate operation that creates a campaign operation. return new MutateOperation([ 'campaign_operation' => new CampaignOperation([ 'create' => new Campaign([ 'name' => 'Performance Max campaign #' . Helper::getPrintableDatetime(), // Assigns the resource name with a temporary ID. 'resource_name' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), // Sets the budget using the given budget resource name. 'campaign_budget' => ResourceNames::forCampaignBudget( $customerId, self::BUDGET_TEMPORARY_ID ), // The campaign is the only entity in the mutate request that should have its // status set. // Recommendation: Set the campaign to PAUSED when creating it to prevent // the ads from immediately serving. 'status' => CampaignStatus::PAUSED, // All Performance Max campaigns have an advertising_channel_type of // PERFORMANCE_MAX. The advertising_channel_sub_type should not be set. 'advertising_channel_type' => AdvertisingChannelType::PERFORMANCE_MAX, // Bidding strategy must be set directly on the campaign. // Setting a portfolio bidding strategy by resource name is not supported. // Max Conversion and Maximize Conversion Value are the only strategies // supported for Performance Max campaigns. // An optional ROAS (Return on Advertising Spend) can be set for // maximize_conversion_value. The ROAS value must be specified as a ratio in // the API. It is calculated by dividing "total value" by "total spend". // For more information on Maximize Conversion Value, see the support // article: http://support.google.com/google-ads/answer/7684216. // A target_roas of 3.5 corresponds to a 350% return on ad spend. 'maximize_conversion_value' => new MaximizeConversionValue([ 'target_roas' => 3.5 ]), // Sets the Final URL expansion opt out. This flag is specific to // Performance Max campaigns. If opted out (true), only the final URLs in // the asset group or URLs specified in the advertiser's Google Merchant // Center or business data feeds are targeted. // If opted in (false), the entire domain will be targeted. For best // results, set this value to false to opt in and allow URL expansions. You // can optionally add exclusions to limit traffic to parts of your website. 'url_expansion_opt_out' => false, // Optional fields. 'start_date' => date('Ymd', strtotime('+1 day')), 'end_date' => date('Ymd', strtotime('+365 days')) ]) ]) ]); }
Python
def create_performance_max_campaign_operation( client, customer_id, ): """Creates a MutateOperation that creates a new Performance Max campaign. A temporary ID will be assigned to this campaign so that it can be referenced by other objects being created in the same Mutate request. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. Returns: a MutateOperation that creates a campaign. """ mutate_operation = client.get_type("MutateOperation") campaign = mutate_operation.campaign_operation.create campaign.name = f"Performance Max campaign #{uuid4()}" # Set the campaign status as PAUSED. The campaign is the only entity in # the mutate request that should have its status set. campaign.status = client.enums.CampaignStatusEnum.PAUSED # All Performance Max campaigns have an advertising_channel_type of # PERFORMANCE_MAX. The advertising_channel_sub_type should not be set. campaign.advertising_channel_type = ( client.enums.AdvertisingChannelTypeEnum.PERFORMANCE_MAX ) # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Max Conversion and Maximize Conversion Value are the only strategies # supported for Performance Max campaigns. # An optional ROAS (Return on Advertising Spend) can be set for # maximize_conversion_value. The ROAS value must be specified as a ratio in # the API. It is calculated by dividing "total value" by "total spend". # For more information on Maximize Conversion Value, see the support # article: http://support.google.com/google-ads/answer/7684216. # A target_roas of 3.5 corresponds to a 350% return on ad spend. campaign.bidding_strategy_type = ( client.enums.BiddingStrategyTypeEnum.MAXIMIZE_CONVERSION_VALUE ) campaign.maximize_conversion_value.target_roas = 3.5 # Set the Final URL expansion opt out. This flag is specific to # Performance Max campaigns. If opted out (True), only the final URLs in # the asset group or URLs specified in the advertiser's Google Merchant # Center or business data feeds are targeted. # If opted in (False), the entire domain will be targeted. For best # results, set this value to false to opt in and allow URL expansions. You # can optionally add exclusions to limit traffic to parts of your website. campaign.url_expansion_opt_out = False # Assign the resource name with a temporary ID. campaign_service = client.get_service("CampaignService") campaign.resource_name = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) # Set the budget using the given budget resource name. campaign.campaign_budget = campaign_service.campaign_budget_path( customer_id, _BUDGET_TEMPORARY_ID ) # Optional fields campaign.start_date = (datetime.now() + timedelta(1)).strftime("%Y%m%d") campaign.end_date = (datetime.now() + timedelta(365)).strftime("%Y%m%d") return mutate_operation
Ruby
# Creates a MutateOperation that creates a new Performance Max campaign. # # A temporary ID will be assigned to this campaign so that it can # be referenced by other objects being created in the same Mutate request. def create_performance_max_campaign_operation(client, customer_id) client.operation.mutate do |m| m.campaign_operation = client.operation.create_resource.campaign do |c| c.name = "Performance Max campaign #{SecureRandom.uuid}" # Set the campaign status as PAUSED. The campaign is the only entity in # the mutate request that should have its status set. c.status = :PAUSED # All Performance Max campaigns have an advertising_channel_type of # PERFORMANCE_MAX. The advertising_channel_sub_type should not be set. c.advertising_channel_type = :PERFORMANCE_MAX # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Max Conversion and Maximize Conversion Value are the only strategies # supported for Performance Max campaigns. # An optional ROAS (Return on Advertising Spend) can be set for # maximize_conversion_value. The ROAS value must be specified as a ratio in # the API. It is calculated by dividing "total value" by "total spend". # For more information on Maximize Conversion Value, see the support # article: http://support.google.com/google-ads/answer/7684216. # A target_roas of 3.5 corresponds to a 350% return on ad spend. c.bidding_strategy_type = :MAXIMIZE_CONVERSION_VALUE c.maximize_conversion_value = client.resource.maximize_conversion_value do |mcv| mcv.target_roas = 3.5 end # Set the Final URL expansion opt out. This flag is specific to # Performance Max campaigns. If opted out (true), only the final URLs in # the asset group or URLs specified in the advertiser's Google Merchant # Center or business data feeds are targeted. # If opted in (false), the entire domain will be targeted. For best # results, set this value to false to opt in and allow URL expansions. You # can optionally add exclusions to limit traffic to parts of your website. c.url_expansion_opt_out = false # Assign the resource name with a temporary ID. c.resource_name = client.path.campaign(customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) # Set the budget using the given budget resource name. c.campaign_budget = client.path.campaign_budget(customer_id, BUDGET_TEMPORARY_ID) # Optional fields c.start_date = DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d') c.end_date = DateTime.parse(Date.today.next_year.to_s).strftime('%Y%m%d') end end end
Perl
sub create_performance_max_campaign_operation { my ($customer_id) = @_; # Create a mutate operation that creates a campaign operation. return Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ campaignOperation => Google::Ads::GoogleAds::V18::Services::CampaignService::CampaignOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::Campaign->new({ # Assign the resource name with a temporary ID. resourceName => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), name => "Performance Max campaign #" . uniqid(), # Set the budget using the given budget resource name. campaignBudget => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign_budget( $customer_id, BUDGET_TEMPORARY_ID ), # Set the campaign status as PAUSED. The campaign is the only entity in # the mutate request that should have its status set. status => Google::Ads::GoogleAds::V18::Enums::CampaignStatusEnum::PAUSED, # All Performance Max campaigns have an advertisingChannelType of # PERFORMANCE_MAX. The advertisingChannelSubType should not be set. advertisingChannelType => PERFORMANCE_MAX, # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Max Conversion and Maximize Conversion Value are the only strategies # supported for Performance Max campaigns. # An optional ROAS (Return on Advertising Spend) can be set for # maximizeConversionValue. The ROAS value must be specified as a ratio in # the API. It is calculated by dividing "total value" by "total spend". # For more information on Maximize Conversion Value, see the support # article: http://support.google.com/google-ads/answer/7684216. # A targetRoas of 3.5 corresponds to a 350% return on ad spend. maximizeConversionValue => Google::Ads::GoogleAds::V18::Common::MaximizeConversionValue-> new({ targetRoas => 3.5 } ), # Set the final URL expansion opt out. This flag is specific to # Performance Max campaigns. If opted out (true), only the final URLs in # the asset group or URLs specified in the advertiser's Google Merchant # Center or business data feeds are targeted. # If opted in (false), the entire domain will be targeted. For best # results, set this value to false to opt in and allow URL expansions. You # can optionally add exclusions to limit traffic to parts of your website. urlExpansionOptOut => "false", # Optional fields. startDate => strftime("%Y%m%d", localtime(time + 60 * 60 * 24)), endDate => strftime("%Y%m%d", localtime(time + 60 * 60 * 24 * 365)), })})}); }
If conversion goals are not explicitly set for the campaign, it defaults to using customer-level conversion goals. However, you can override customer conversion goals to set campaign-specific conversion goals (learn more).
Code example
Java
/** Retrieves the list of customer conversion goals. */ private static List<CustomerConversionGoal> getCustomerConversionGoals( GoogleAdsClient googleAdsClient, long customerId) { String query = "SELECT customer_conversion_goal.category, customer_conversion_goal.origin " + "FROM customer_conversion_goal"; List<CustomerConversionGoal> customerConversionGoals = new ArrayList<>(); try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) { // The number of conversion goals is typically less than 50, so we use // GoogleAdsService.search instead of search_stream. SearchPagedResponse response = googleAdsServiceClient.search(Long.toString(customerId), query); for (GoogleAdsRow googleAdsRow : response.iterateAll()) { customerConversionGoals.add(googleAdsRow.getCustomerConversionGoal()); } } return customerConversionGoals; } /** Creates a list of MutateOperations that override customer conversion goals. */ private static List<MutateOperation> createConversionGoalOperations( long customerId, List<CustomerConversionGoal> customerConversionGoals) { List<MutateOperation> mutateOperations = new ArrayList<>(); // To override the customer conversion goals, we will change the // biddability of each of the customer conversion goals so that only // the desired conversion goal is biddable in this campaign. for (CustomerConversionGoal customerConversionGoal : customerConversionGoals) { ConversionActionCategory category = customerConversionGoal.getCategory(); ConversionOrigin origin = customerConversionGoal.getOrigin(); String campaignConversionGoalResourceName = ResourceNames.campaignConversionGoal( customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, category, origin); CampaignConversionGoal.Builder campaignConversionGoalBuilder = CampaignConversionGoal.newBuilder().setResourceName(campaignConversionGoalResourceName); // Change the biddability for the campaign conversion goal. // Set biddability to True for the desired (category, origin). // Set biddability to False for all other conversion goals. // Note: // 1- It is assumed that this Conversion Action // (category=PURCHASE, origin=WEBSITE) exists in this account. // 2- More than one goal can be biddable if desired. This example // shows only one. if (category == ConversionActionCategory.PURCHASE && origin == ConversionOrigin.WEBSITE) { campaignConversionGoalBuilder.setBiddable(true); } else { campaignConversionGoalBuilder.setBiddable(false); } CampaignConversionGoal campaignConversionGoal = campaignConversionGoalBuilder.build(); CampaignConversionGoalOperation campaignConversionGoalOperation = CampaignConversionGoalOperation.newBuilder() .setUpdate(campaignConversionGoal) .setUpdateMask(FieldMasks.allSetFieldsOf(campaignConversionGoal)) .build(); mutateOperations.add( MutateOperation.newBuilder() .setCampaignConversionGoalOperation(campaignConversionGoalOperation) .build()); } return mutateOperations; }
C#
/// <summary> /// Creates a MutateOperation that links an asset to an asset group. /// </summary> /// <param name="fieldType">The field type of the asset to be linked.</param> /// <param name="assetGroupResourceName">The resource name of the asset group /// to link the asset to.</param> /// <param name="assetResourceName">The resource name of the text asset to be /// linked.</param> /// <returns>A MutateOperation that links an asset to an asset group.</returns> private MutateOperation CreateLinkAssetOperation( AssetFieldType fieldType, string assetGroupResourceName, string assetResourceName) => new MutateOperation() { AssetGroupAssetOperation = new AssetGroupAssetOperation() { Create = new AssetGroupAsset() { FieldType = fieldType, AssetGroup = assetGroupResourceName, Asset = assetResourceName } } };
PHP
private static function getCustomerConversionGoals( GoogleAdsClient $googleAdsClient, int $customerId ): array { $customerConversionGoals = []; $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient(); // Creates a query that retrieves all customer conversion goals. $query = 'SELECT customer_conversion_goal.category, customer_conversion_goal.origin ' . 'FROM customer_conversion_goal'; // The number of conversion goals is typically less than 50 so we use a search request // instead of search stream. $response = $googleAdsServiceClient->search(SearchGoogleAdsRequest::build($customerId, $query)); // Iterates over all rows in all pages and builds the list of conversion goals. foreach ($response->iterateAllElements() as $googleAdsRow) { /** @var GoogleAdsRow $googleAdsRow */ $customerConversionGoals[] = [ 'category' => $googleAdsRow->getCustomerConversionGoal()->getCategory(), 'origin' => $googleAdsRow->getCustomerConversionGoal()->getOrigin() ]; } return $customerConversionGoals; } /** * Creates a list of MutateOperations that override customer conversion goals. * * @param int $customerId the customer ID * @param array $customerConversionGoals the list of customer conversion goals that will be * overridden * @return MutateOperation[] a list of MutateOperations that update campaign conversion goals */ private static function createConversionGoalOperations( int $customerId, array $customerConversionGoals ): array { $operations = []; // To override the customer conversion goals, we will change the biddability of each of the // customer conversion goals so that only the desired conversion goal is biddable in this // campaign. foreach ($customerConversionGoals as $customerConversionGoal) { $campaignConversionGoal = new CampaignConversionGoal([ 'resource_name' => ResourceNames::forCampaignConversionGoal( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, ConversionActionCategory::name($customerConversionGoal['category']), ConversionOrigin::name($customerConversionGoal['origin']) ) ]); // Changes the biddability for the campaign conversion goal. // Sets biddability to true for the desired (category, origin). // Sets biddability to false for all other conversion goals. // Note: // 1- It is assumed that this Conversion Action // (category=PURCHASE, origin=WEBSITE) exists in this account. // 2- More than one goal can be biddable if desired. This example // shows only one. if ( $customerConversionGoal["category"] === ConversionActionCategory::PURCHASE && $customerConversionGoal["origin"] === ConversionOrigin::WEBSITE ) { $campaignConversionGoal->setBiddable(true); } else { $campaignConversionGoal->setBiddable(false); } $operations[] = new MutateOperation([ 'campaign_conversion_goal_operation' => new CampaignConversionGoalOperation([ 'update' => $campaignConversionGoal, // Sets the update mask on the operation. Here the update mask will be a list // of all the fields that were set on the update object. 'update_mask' => FieldMasks::allSetFieldsOf($campaignConversionGoal) ]) ]); } return $operations; }
Python
def get_customer_conversion_goals(client, customer_id): """Retrieves the list of customer conversion goals. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. Returns: a list of dicts containing the category and origin of customer conversion goals. """ ga_service = client.get_service("GoogleAdsService") customer_conversion_goals = [] query = """ SELECT customer_conversion_goal.category, customer_conversion_goal.origin FROM customer_conversion_goal """ # The number of conversion goals is typically less than 50 so we use # GoogleAdsService.search instead of search_stream. search_request = client.get_type("SearchGoogleAdsRequest") search_request.customer_id = customer_id search_request.query = query results = ga_service.search(request=search_request) # Iterate over the results and build the list of conversion goals. for row in results: customer_conversion_goals.append( { "category": row.customer_conversion_goal.category, "origin": row.customer_conversion_goal.origin, } ) return customer_conversion_goals def create_conversion_goal_operations( client, customer_id, customer_conversion_goals, ): """Creates a list of MutateOperations that override customer conversion goals. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. customer_conversion_goals: the list of customer conversion goals that will be overridden. Returns: MutateOperations that update campaign conversion goals. """ campaign_conversion_goal_service = client.get_service( "CampaignConversionGoalService" ) operations = [] # To override the customer conversion goals, we will change the # biddability of each of the customer conversion goals so that only # the desired conversion goal is biddable in this campaign. for customer_conversion_goal in customer_conversion_goals: mutate_operation = client.get_type("MutateOperation") campaign_conversion_goal = ( mutate_operation.campaign_conversion_goal_operation.update ) campaign_conversion_goal.resource_name = ( campaign_conversion_goal_service.campaign_conversion_goal_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, customer_conversion_goal["category"].name, customer_conversion_goal["origin"].name, ) ) # Change the biddability for the campaign conversion goal. # Set biddability to True for the desired (category, origin). # Set biddability to False for all other conversion goals. # Note: # 1- It is assumed that this Conversion Action # (category=PURCHASE, origin=WEBSITE) exists in this account. # 2- More than one goal can be biddable if desired. This example # shows only one. if ( customer_conversion_goal["category"] == client.enums.ConversionActionCategoryEnum.PURCHASE and customer_conversion_goal["origin"] == client.enums.ConversionOriginEnum.WEBSITE ): biddable = True else: biddable = False campaign_conversion_goal.biddable = biddable field_mask = protobuf_helpers.field_mask( None, campaign_conversion_goal._pb ) client.copy_from( mutate_operation.campaign_conversion_goal_operation.update_mask, field_mask, ) operations.append(mutate_operation) return operations
Ruby
def _get_customer_conversion_goals(client, customer_id) query = <<~EOD SELECT customer_conversion_goal.category, customer_conversion_goal.origin FROM customer_conversion_goal EOD customer_conversion_goals = [] ga_service = client.service.google_ads # The number of conversion goals is typically less than 50 so we use # GoogleAdsService.search instead of search_stream. response = ga_service.search( customer_id: customer_id, query: query, ) # Iterate over the results and build the list of conversion goals. response.each do |row| customer_conversion_goals << { "category" => row.customer_conversion_goal.category, "origin" => row.customer_conversion_goal.origin } end customer_conversion_goals end def create_conversion_goal_operations(client, customer_id, customer_conversion_goals) campaign_conversion_goal_service = client.service.campaign_conversion_goal operations = [] # To override the customer conversion goals, we will change the # biddability of each of the customer conversion goals so that only # the desired conversion goal is biddable in this campaign. customer_conversion_goals.each do |customer_conversion_goal| operations << client.operation.mutate do |m| m.campaign_conversion_goal_operation = client.operation.campaign_conversion_goal do |op| op.update = client.resource.campaign_conversion_goal do |ccg| ccg.resource_name = client.path.campaign_conversion_goal( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, customer_conversion_goal["category"].to_s, customer_conversion_goal["origin"].to_s) # Change the biddability for the campaign conversion goal. # Set biddability to True for the desired (category, origin). # Set biddability to False for all other conversion goals. # Note: # 1- It is assumed that this Conversion Action # (category=PURCHASE, origin=WEBSITE) exists in this account. # 2- More than one goal can be biddable if desired. This example # shows only one. ccg.biddable = (customer_conversion_goal["category"] == :PURCHASE && customer_conversion_goal["origin"] == :WEBSITE) end op.update_mask = Google::Ads::GoogleAds::FieldMaskUtil.all_set_fields_of(op.update) end end end operations end
Perl
sub get_customer_conversion_goals { my ($api_client, $customer_id) = @_; my $customer_conversion_goals = []; # Create a query that retrieves all customer conversion goals. my $query = "SELECT customer_conversion_goal.category, customer_conversion_goal.origin " . "FROM customer_conversion_goal"; # The number of conversion goals is typically less than 50 so we use # GoogleAdsService->search() method instead of search_stream(). my $search_response = $api_client->GoogleAdsService()->search({ customerId => $customer_id, query => $query }); # Iterate over the results and build the list of conversion goals. foreach my $google_ads_row (@{$search_response->{results}}) { push @$customer_conversion_goals, { category => $google_ads_row->{customerConversionGoal}{category}, origin => $google_ads_row->{customerConversionGoal}{origin}}; } return $customer_conversion_goals; } # Creates a list of MutateOperations that override customer conversion goals. sub create_conversion_goal_operations { my ($customer_id, $customer_conversion_goals) = @_; my $operations = []; # To override the customer conversion goals, we will change the biddability of # each of the customer conversion goals so that only the desired conversion goal # is biddable in this campaign. foreach my $customer_conversion_goal (@$customer_conversion_goals) { my $campaign_conversion_goal = Google::Ads::GoogleAds::V18::Resources::CampaignConversionGoal->new({ resourceName => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign_conversion_goal( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID, $customer_conversion_goal->{category}, $customer_conversion_goal->{origin})}); # Change the biddability for the campaign conversion goal. # Set biddability to true for the desired (category, origin). # Set biddability to false for all other conversion goals. # Note: # 1- It is assumed that this Conversion Action # (category=PURCHASE, origin=WEBSITE) exists in this account. # 2- More than one goal can be biddable if desired. This example # shows only one. if ( $customer_conversion_goal->{category} eq PURCHASE && $customer_conversion_goal->{origin} eq WEBSITE) { $campaign_conversion_goal->{biddable} = "true"; } else { $campaign_conversion_goal->{biddable} = "false"; } push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ campaignConversionGoalOperation => Google::Ads::GoogleAds::V18::Services::CampaignConversionGoalService::CampaignConversionGoalOperation ->new({ update => $campaign_conversion_goal, # Set the update mask on the operation. Here the update mask will be # a list of all the fields that were set on the update object. updateMask => all_set_fields_of($campaign_conversion_goal)})}); } return $operations; }
Performance Max campaigns support the following types of criteria:
AD_SCHEDULE
(learn more)BRAND
LANGUAGE
(learn more)LOCATION
(learn more)LOCATION_GROUP
(learn more)WEBPAGE
Code example
Java
/** Creates a list of MutateOperations that create new campaign criteria. */ private List<MutateOperation> createCampaignCriterionOperations(long customerId) { String campaignResourceName = ResourceNames.campaign(customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID); List<CampaignCriterion> campaignCriteria = new ArrayList<>(); // Sets the LOCATION campaign criteria. // Targets all of New York City except Brooklyn. // Location IDs are listed here: // https://developers.google.com/google-ads/api/reference/data/geotargets // and they can also be retrieved using the GeoTargetConstantService as shown // here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting // // We will add one positive location target for New York City (ID=1023191) // and one negative location target for Brooklyn (ID=1022762). // First, adds the positive (negative = False) for New York City. campaignCriteria.add( CampaignCriterion.newBuilder() .setCampaign(campaignResourceName) .setLocation( LocationInfo.newBuilder() .setGeoTargetConstant(ResourceNames.geoTargetConstant(1023191)) .build()) .setNegative(false) .build()); // Next adds the negative target for Brooklyn. campaignCriteria.add( CampaignCriterion.newBuilder() .setCampaign(campaignResourceName) .setLocation( LocationInfo.newBuilder() .setGeoTargetConstant(ResourceNames.geoTargetConstant(1022762)) .build()) .setNegative(true) .build()); // Sets the LANGUAGE campaign criterion. campaignCriteria.add( CampaignCriterion.newBuilder() .setCampaign(campaignResourceName) // Sets the language. // For a list of all language codes, see: // https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7 .setLanguage( LanguageInfo.newBuilder() .setLanguageConstant(ResourceNames.languageConstant(1000)) // English .build()) .build()); // Returns a list of mutate operations with one operation per criterion. return campaignCriteria.stream() .map( criterion -> MutateOperation.newBuilder() .setCampaignCriterionOperation( CampaignCriterionOperation.newBuilder().setCreate(criterion).build()) .build()) .collect(Collectors.toList()); }
C#
/// <summary> /// Creates a list of MutateOperations that create new campaign criteria. /// </summary> /// <param name="campaignResourceName">The campaign resource name.</param> /// <returns>A list of MutateOperations that create new campaign criteria.</returns> private List<MutateOperation> CreateCampaignCriterionOperations( string campaignResourceName) { List<MutateOperation> operations = new List<MutateOperation>(); // Set the LOCATION campaign criteria. // Target all of New York City except Brooklyn. // Location IDs are listed here: // https://developers.google.com/google-ads/api/reference/data/geotargets // and they can also be retrieved using the GeoTargetConstantService as shown // here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting // // We will add one positive location target for New York City (ID=1023191) // and one negative location target for Brooklyn (ID=1022762). // First, add the positive (negative = False) for New York City. MutateOperation operation1 = new MutateOperation() { CampaignCriterionOperation = new CampaignCriterionOperation() { Create = new CampaignCriterion() { Campaign = campaignResourceName, Location = new LocationInfo() { GeoTargetConstant = ResourceNames.GeoTargetConstant(1023191) }, Negative = false } } }; operations.Add(operation1); // Next add the negative target for Brooklyn. MutateOperation operation2 = new MutateOperation() { CampaignCriterionOperation = new CampaignCriterionOperation() { Create = new CampaignCriterion() { Campaign = campaignResourceName, Location = new LocationInfo() { GeoTargetConstant = ResourceNames.GeoTargetConstant(1022762) }, Negative = true } } }; operations.Add(operation2); // Set the LANGUAGE campaign criterion. MutateOperation operation3 = new MutateOperation() { CampaignCriterionOperation = new CampaignCriterionOperation() { Create = new CampaignCriterion() { Campaign = campaignResourceName, // Set the language. // For a list of all language codes, see: // https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7 Language = new LanguageInfo() { LanguageConstant = ResourceNames.LanguageConstant(1000) // English }, } } }; operations.Add(operation3); return operations; }
PHP
private static function createCampaignCriterionOperations(int $customerId): array { $operations = []; // Set the LOCATION campaign criteria. // Target all of New York City except Brooklyn. // Location IDs are listed here: // https://developers.google.com/google-ads/api/reference/data/geotargets // and they can also be retrieved using the GeoTargetConstantService as shown // here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting // // We will add one positive location target for New York City (ID=1023191) // and one negative location target for Brooklyn (ID=1022762). // First, adds the positive (negative = false) for New York City. $operations[] = new MutateOperation([ 'campaign_criterion_operation' => new CampaignCriterionOperation([ 'create' => new CampaignCriterion([ 'campaign' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), 'location' => new LocationInfo([ 'geo_target_constant' => ResourceNames::forGeoTargetConstant(1023191) ]), 'negative' => false ]) ]) ]); // Next adds the negative target for Brooklyn. $operations[] = new MutateOperation([ 'campaign_criterion_operation' => new CampaignCriterionOperation([ 'create' => new CampaignCriterion([ 'campaign' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), 'location' => new LocationInfo([ 'geo_target_constant' => ResourceNames::forGeoTargetConstant(1022762) ]), 'negative' => true ]) ]) ]); // Sets the LANGUAGE campaign criterion. $operations[] = new MutateOperation([ 'campaign_criterion_operation' => new CampaignCriterionOperation([ 'create' => new CampaignCriterion([ 'campaign' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), // Set the language. // For a list of all language codes, see: // https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7 'language' => new LanguageInfo([ 'language_constant' => ResourceNames::forLanguageConstant(1000) // English ]) ]) ]) ]); return $operations; }
Python
def create_campaign_criterion_operations( client, customer_id, ): """Creates a list of MutateOperations that create new campaign criteria. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. Returns: a list of MutateOperations that create new campaign criteria. """ campaign_service = client.get_service("CampaignService") geo_target_constant_service = client.get_service("GeoTargetConstantService") googleads_service = client.get_service("GoogleAdsService") operations = [] # Set the LOCATION campaign criteria. # Target all of New York City except Brooklyn. # Location IDs are listed here: # https://developers.google.com/google-ads/api/reference/data/geotargets # and they can also be retrieved using the GeoTargetConstantService as shown # here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting # # We will add one positive location target for New York City (ID=1023191) # and one negative location target for Brooklyn (ID=1022762). # First, add the positive (negative = False) for New York City. mutate_operation = client.get_type("MutateOperation") campaign_criterion = mutate_operation.campaign_criterion_operation.create campaign_criterion.campaign = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) campaign_criterion.location.geo_target_constant = ( geo_target_constant_service.geo_target_constant_path("1023191") ) campaign_criterion.negative = False operations.append(mutate_operation) # Next add the negative target for Brooklyn. mutate_operation = client.get_type("MutateOperation") campaign_criterion = mutate_operation.campaign_criterion_operation.create campaign_criterion.campaign = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) campaign_criterion.location.geo_target_constant = ( geo_target_constant_service.geo_target_constant_path("1022762") ) campaign_criterion.negative = True operations.append(mutate_operation) # Set the LANGUAGE campaign criterion. mutate_operation = client.get_type("MutateOperation") campaign_criterion = mutate_operation.campaign_criterion_operation.create campaign_criterion.campaign = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) # Set the language. # For a list of all language codes, see: # https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7 campaign_criterion.language.language_constant = ( googleads_service.language_constant_path("1000") ) # English operations.append(mutate_operation) return operations
Ruby
# Creates a list of MutateOperations that create new campaign criteria. def create_campaign_criterion_operations(client, customer_id) operations = [] # Set the LOCATION campaign criteria. # Target all of New York City except Brooklyn. # Location IDs are listed here: # https://developers.google.com/google-ads/api/reference/data/geotargets # and they can also be retrieved using the GeoTargetConstantService as shown # here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting # # We will add one positive location target for New York City (ID=1023191) # and one negative location target for Brooklyn (ID=1022762). # First, add the positive (negative = false) for New York City. operations << client.operation.mutate do |m| m.campaign_criterion_operation = client.operation.create_resource.campaign_criterion do |cc| cc.campaign = client.path.campaign( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) cc.location = client.resource.location_info do |li| li.geo_target_constant = client.path.geo_target_constant("1023191") end cc.negative = false end end # Next add the negative target for Brooklyn. operations << client.operation.mutate do |m| m.campaign_criterion_operation = client.operation.create_resource.campaign_criterion do |cc| cc.campaign = client.path.campaign( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) cc.location = client.resource.location_info do |li| li.geo_target_constant = client.path.geo_target_constant("1022762") end cc.negative = true end end # Set the LANGUAGE campaign criterion. operations << client.operation.mutate do |m| m.campaign_criterion_operation = client.operation.create_resource.campaign_criterion do |cc| cc.campaign = client.path.campaign( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) # Set the language. # For a list of all language codes, see: # https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7 cc.language = client.resource.language_info do |li| li.language_constant = client.path.language_constant("1000") # English end end end operations end
Perl
sub create_campaign_criterion_operations { my ($customer_id) = @_; my $operations = []; # Set the LOCATION campaign criteria. # Target all of New York City except Brooklyn. # Location IDs are listed here: # https://developers.google.com/google-ads/api/reference/data/geotargets # and they can also be retrieved using the GeoTargetConstantService as shown # here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting. # # We will add one positive location target for New York City (ID=1023191) # and one negative location target for Brooklyn (ID=1022762). # First, add the positive (negative = false) for New York City. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ campaignCriterionOperation => Google::Ads::GoogleAds::V18::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::CampaignCriterion->new({ campaign => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), location => Google::Ads::GoogleAds::V18::Common::LocationInfo->new({ geoTargetConstant => Google::Ads::GoogleAds::V18::Utils::ResourceNames::geo_target_constant( 1023191)} ), negative => "false" })})}); # Next add the negative target for Brooklyn. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ campaignCriterionOperation => Google::Ads::GoogleAds::V18::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::CampaignCriterion->new({ campaign => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), location => Google::Ads::GoogleAds::V18::Common::LocationInfo->new({ geoTargetConstant => Google::Ads::GoogleAds::V18::Utils::ResourceNames::geo_target_constant( 1022762)} ), negative => "true" })})}); # Set the LANGUAGE campaign criterion. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ campaignCriterionOperation => Google::Ads::GoogleAds::V18::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::CampaignCriterion->new({ campaign => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), # Set the language. # For a list of all language codes, see: # https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7. language => Google::Ads::GoogleAds::V18::Common::LanguageInfo->new({ languageConstant => Google::Ads::GoogleAds::V18::Utils::ResourceNames::language_constant( 1000) # English })})})}); return $operations; }
Assets, asset groups, and product targeting
Assets are not required for Performance Max for retail campaigns since Google automatically creates assets from the product listings included in the associated Merchant Center account. However, we recommend adding assets for better campaign performance.
Code example
Java
/** Creates multiple text assets and returns the list of resource names. */ private List<String> createMultipleTextAssets( GoogleAdsClient googleAdsClient, long customerId, List<String> texts) { List<MutateOperation> mutateOperations = new ArrayList<>(); for (String text : texts) { Asset asset = Asset.newBuilder().setTextAsset(TextAsset.newBuilder().setText(text)).build(); AssetOperation assetOperation = AssetOperation.newBuilder().setCreate(asset).build(); mutateOperations.add(MutateOperation.newBuilder().setAssetOperation(assetOperation).build()); } List<String> assetResourceNames = new ArrayList<>(); // Creates the service client. try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) { // Sends the operations in a single Mutate request. MutateGoogleAdsResponse response = googleAdsServiceClient.mutate(Long.toString(customerId), mutateOperations); for (MutateOperationResponse result : response.getMutateOperationResponsesList()) { if (result.hasAssetResult()) { assetResourceNames.add(result.getAssetResult().getResourceName()); } } printResponseDetails(response); } return assetResourceNames; }
C#
/// <summary> /// Creates multiple text assets and returns the list of resource names. /// </summary> /// <param name="client">The Google Ads Client.</param> /// <param name="customerId">The customer's ID.</param> /// <param name="texts">The texts to add.</param> /// <returns>A list of asset resource names.</returns> private List<string> CreateMultipleTextAssets( GoogleAdsClient client, long customerId, string[] texts) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsServiceClient = client.GetService(Services.V18.GoogleAdsService); MutateGoogleAdsRequest request = new MutateGoogleAdsRequest() { CustomerId = customerId.ToString() }; foreach (string text in texts) { request.MutateOperations.Add( new MutateOperation() { AssetOperation = new AssetOperation() { Create = new Asset() { TextAsset = new TextAsset() { Text = text } } } } ); } // Send the operations in a single Mutate request. MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request); List<string> assetResourceNames = new List<string>(); foreach (MutateOperationResponse operationResponse in response.MutateOperationResponses) { MutateAssetResult assetResult = operationResponse.AssetResult; assetResourceNames.Add(assetResult.ResourceName); } PrintResponseDetails(response); return assetResourceNames; }
PHP
private static function createMultipleTextAssets( GoogleAdsClient $googleAdsClient, int $customerId, array $texts ): array { // Here again, we use the GoogleAdService to create multiple text assets in a single // request. $operations = []; foreach ($texts as $text) { // Creates a mutate operation for a text asset. $operations[] = new MutateOperation([ 'asset_operation' => new AssetOperation([ 'create' => new Asset(['text_asset' => new TextAsset(['text' => $text])]) ]) ]); } // Issues a mutate request to add all assets. $googleAdsService = $googleAdsClient->getGoogleAdsServiceClient(); /** @var MutateGoogleAdsResponse $mutateGoogleAdsResponse */ $mutateGoogleAdsResponse = $googleAdsService->mutate(MutateGoogleAdsRequest::build($customerId, $operations)); $assetResourceNames = []; foreach ($mutateGoogleAdsResponse->getMutateOperationResponses() as $response) { /** @var MutateOperationResponse $response */ $assetResourceNames[] = $response->getAssetResult()->getResourceName(); } self::printResponseDetails($mutateGoogleAdsResponse); return $assetResourceNames; }
Python
def create_multiple_text_assets(client, customer_id, texts): """Creates multiple text assets and returns the list of resource names. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. texts: a list of strings, each of which will be used to create a text asset. Returns: asset_resource_names: a list of asset resource names. """ # Here again we use the GoogleAdService to create multiple text # assets in a single request. googleads_service = client.get_service("GoogleAdsService") operations = [] for text in texts: mutate_operation = client.get_type("MutateOperation") asset = mutate_operation.asset_operation.create asset.text_asset.text = text operations.append(mutate_operation) # Send the operations in a single Mutate request. response = googleads_service.mutate( customer_id=customer_id, mutate_operations=operations, ) asset_resource_names = [] for result in response.mutate_operation_responses: if result._pb.HasField("asset_result"): asset_resource_names.append(result.asset_result.resource_name) print_response_details(response) return asset_resource_names
Ruby
# Creates multiple text assets and returns the list of resource names. def create_multiple_text_assets(client, customer_id, texts) operations = texts.map do |text| client.operation.mutate do |m| m.asset_operation = client.operation.create_resource.asset do |asset| asset.text_asset = client.resource.text_asset do |text_asset| text_asset.text = text end end end end # Send the operations in a single Mutate request. response = client.service.google_ads.mutate( customer_id: customer_id, mutate_operations: operations, ) asset_resource_names = [] response.mutate_operation_responses.each do |result| if result.asset_result asset_resource_names.append(result.asset_result.resource_name) end end print_response_details(response) asset_resource_names end
Perl
sub create_multiple_text_assets { my ($api_client, $customer_id, $texts) = @_; # Here again we use the GoogleAdService to create multiple text assets in a # single request. my $operations = []; foreach my $text (@$texts) { # Create a mutate operation for a text asset. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ assetOperation => Google::Ads::GoogleAds::V18::Services::AssetService::AssetOperation-> new({ create => Google::Ads::GoogleAds::V18::Resources::Asset->new({ textAsset => Google::Ads::GoogleAds::V18::Common::TextAsset->new({ text => $text })})})}); } # Issue a mutate request to add all assets. my $mutate_google_ads_response = $api_client->GoogleAdsService()->mutate({ customerId => $customer_id, mutateOperations => $operations }); my $asset_resource_names = []; foreach my $response (@{$mutate_google_ads_response->{mutateOperationResponses}}) { push @$asset_resource_names, $response->{assetResult}{resourceName}; } print_response_details($mutate_google_ads_response); return $asset_resource_names; }
An asset group is a collection of assets centered on a theme or related to a target audience. The asset group is used to assemble all of your ads and build an inventory for all applicable ad formats for your advertising objective. Learn more about asset groups.
Asset groups contain one or more final URLs. At least one final URL is required. Use the URL that is most relevant to the conversion path for the given asset group and campaign objectives.
Code example
Java
/** Creates a list of MutateOperations that create a new AssetGroup. */ private List<MutateOperation> createAssetGroupOperations( long customerId, String assetGroupResourceName, List<String> headlineAssetResourceNames, List<String> descriptionAssetResourceNames) throws IOException { List<MutateOperation> mutateOperations = new ArrayList<>(); String campaignResourceName = ResourceNames.campaign(customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID); // Creates the AssetGroup. AssetGroup assetGroup = AssetGroup.newBuilder() .setName("Performance Max asset group #" + getPrintableDateTime()) .setCampaign(campaignResourceName) .addFinalUrls("http://www.example.com") .addFinalMobileUrls("http://www.example.com") .setStatus(AssetGroupStatus.PAUSED) .setResourceName(assetGroupResourceName) .build(); AssetGroupOperation assetGroupOperation = AssetGroupOperation.newBuilder().setCreate(assetGroup).build(); mutateOperations.add( MutateOperation.newBuilder().setAssetGroupOperation(assetGroupOperation).build()); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // the resource name of the AssetGroup // the resource name of the Asset // the field_type of the Asset in this AssetGroup. // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups // Links the previously created multiple text assets. // Links the headline assets. for (String resourceName : headlineAssetResourceNames) { AssetGroupAsset assetGroupAsset = AssetGroupAsset.newBuilder() .setFieldType(AssetFieldType.HEADLINE) .setAssetGroup(assetGroupResourceName) .setAsset(resourceName) .build(); AssetGroupAssetOperation assetGroupAssetOperation = AssetGroupAssetOperation.newBuilder().setCreate(assetGroupAsset).build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupAssetOperation(assetGroupAssetOperation) .build()); } // Links the description assets. for (String resourceName : descriptionAssetResourceNames) { AssetGroupAsset assetGroupAsset = AssetGroupAsset.newBuilder() .setFieldType(AssetFieldType.DESCRIPTION) .setAssetGroup(assetGroupResourceName) .setAsset(resourceName) .build(); AssetGroupAssetOperation assetGroupAssetOperation = AssetGroupAssetOperation.newBuilder().setCreate(assetGroupAsset).build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupAssetOperation(assetGroupAssetOperation) .build()); } // Creates and links the long headline text asset. List<MutateOperation> createAndLinkTextAssetOperations = createAndLinkTextAsset(customerId, "Travel the World", AssetFieldType.LONG_HEADLINE); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the business name text asset. createAndLinkTextAssetOperations = createAndLinkTextAsset(customerId, "Interplanetary Cruises", AssetFieldType.BUSINESS_NAME); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the image assets. // Creates and links the Logo Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/bjYi", AssetFieldType.LOGO, "Marketing Logo"); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the Marketing Image Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/Eit5", AssetFieldType.MARKETING_IMAGE, "Marketing Image"); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the Square Marketing Image Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/bjYi", AssetFieldType.SQUARE_MARKETING_IMAGE, "Square Marketing Image"); mutateOperations.addAll(createAndLinkTextAssetOperations); return mutateOperations; }
C#
/// <summary> /// Creates a list of MutateOperations that create a new asset_group. /// </summary> /// <param name="campaignResourceName">The campaign resource name.</param> /// <param name="assetGroupResourceName">The asset group resource name.</param> /// <param name="headlineAssetResourceNames">The headline asset resource names.</param> /// <param name="descriptionAssetResourceNames">The description asset resource /// names.</param> /// <param name="resourceNameGenerator">A generator for unique temporary ID's.</param> /// <param name="config">The Google Ads config.</param> /// <returns>A list of MutateOperations that create the new asset group.</returns> private List<MutateOperation> CreateAssetGroupOperations( string campaignResourceName, string assetGroupResourceName, List<string> headlineAssetResourceNames, List<string> descriptionAssetResourceNames, AssetGroupAssetTemporaryResourceNameGenerator resourceNameGenerator, GoogleAdsConfig config) { List<MutateOperation> operations = new List<MutateOperation>(); // Create the AssetGroup operations.Add( new MutateOperation() { AssetGroupOperation = new AssetGroupOperation() { Create = new AssetGroup() { Name = "Performance Max asset group #" + ExampleUtilities.GetRandomString(), Campaign = campaignResourceName, FinalUrls = { "http://www.example.com" }, FinalMobileUrls = { "http://www.example.com" }, Status = AssetGroupStatus.Paused, ResourceName = assetGroupResourceName } } } ); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // the resource name of the AssetGroup // the resource name of the Asset // the field_type of the Asset in this AssetGroup. // // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups // Link the previously created multiple text assets. // Link the headline assets. foreach (string resourceName in headlineAssetResourceNames) { operations.Add( new MutateOperation() { AssetGroupAssetOperation = new AssetGroupAssetOperation() { Create = new AssetGroupAsset() { FieldType = AssetFieldType.Headline, AssetGroup = assetGroupResourceName, Asset = resourceName } } } ); } // Link the description assets. foreach (string resourceName in descriptionAssetResourceNames) { operations.Add( new MutateOperation() { AssetGroupAssetOperation = new AssetGroupAssetOperation() { Create = new AssetGroupAsset() { FieldType = AssetFieldType.Description, AssetGroup = assetGroupResourceName, Asset = resourceName } } } ); } // Create and link the long headline text asset. operations.AddRange( CreateAndLinkTextAsset( assetGroupResourceName, resourceNameGenerator.Next(), "Travel the World", AssetFieldType.LongHeadline ) ); // Create and link the business name text asset. operations.AddRange( CreateAndLinkTextAsset( assetGroupResourceName, resourceNameGenerator.Next(), "Interplanetary Cruises", AssetFieldType.BusinessName ) ); // Create and link the image assets. // Create and link the Logo Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/bjYi", AssetFieldType.Logo, "Marketing Logo", config ) ); // Create and link the Marketing Image Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/Eit5", AssetFieldType.MarketingImage, "Marketing Image", config ) ); // Create and link the Square Marketing Image Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/bjYi", AssetFieldType.SquareMarketingImage, "Square Marketing Image", config ) ); return operations; }
PHP
private static function createAssetGroupOperations( int $customerId, array $headlineAssetResourceNames, array $descriptionAssetResourceNames ): array { $operations = []; // Creates a new mutate operation that creates an asset group operation. $operations[] = new MutateOperation([ 'asset_group_operation' => new AssetGroupOperation([ 'create' => new AssetGroup([ 'resource_name' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'name' => 'Performance Max asset group #' . Helper::getPrintableDatetime(), 'campaign' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), 'final_urls' => ['http://www.example.com'], 'final_mobile_urls' => ['http://www.example.com'], 'status' => AssetGroupStatus::PAUSED ]) ]) ]); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // - the resource name of the AssetGroup // - the resource name of the Asset // - the field_type of the Asset in this AssetGroup // // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups. // Links the previously created multiple text assets. // Links the headline assets. foreach ($headlineAssetResourceNames as $resourceName) { $operations[] = new MutateOperation([ 'asset_group_asset_operation' => new AssetGroupAssetOperation([ 'create' => new AssetGroupAsset([ 'asset' => $resourceName, 'asset_group' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'field_type' => AssetFieldType::HEADLINE ]) ]) ]); } // Links the description assets. foreach ($descriptionAssetResourceNames as $resourceName) { $operations[] = new MutateOperation([ 'asset_group_asset_operation' => new AssetGroupAssetOperation([ 'create' => new AssetGroupAsset([ 'asset' => $resourceName, 'asset_group' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'field_type' => AssetFieldType::DESCRIPTION ]) ]) ]); } // Creates and links the long headline text asset. $operations = array_merge($operations, self::createAndLinkTextAsset( $customerId, 'Travel the World', AssetFieldType::LONG_HEADLINE )); // Creates and links the business name text asset. $operations = array_merge($operations, self::createAndLinkTextAsset( $customerId, 'Interplanetary Cruises', AssetFieldType::BUSINESS_NAME )); // Creates and links the image assets. // Creates and links the Logo Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/bjYi', AssetFieldType::LOGO, 'Marketing Logo' )); // Creates and links the Marketing Image Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/Eit5', AssetFieldType::MARKETING_IMAGE, 'Marketing Image' )); // Creates and links the Square Marketing Image Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/bjYi', AssetFieldType::SQUARE_MARKETING_IMAGE, 'Square Marketing Image' )); return $operations; }
Python
def create_asset_group_operation( client, customer_id, headline_asset_resource_names, description_asset_resource_names, ): """Creates a list of MutateOperations that create a new asset_group. A temporary ID will be assigned to this asset group so that it can be referenced by other objects being created in the same Mutate request. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. headline_asset_resource_names: a list of headline resource names. description_asset_resource_names: a list of description resource names. Returns: MutateOperations that create a new asset group and related assets. """ asset_group_service = client.get_service("AssetGroupService") campaign_service = client.get_service("CampaignService") operations = [] # Create the AssetGroup mutate_operation = client.get_type("MutateOperation") asset_group = mutate_operation.asset_group_operation.create asset_group.name = f"Performance Max asset group #{uuid4()}" asset_group.campaign = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) asset_group.final_urls.append("http://www.example.com") asset_group.final_mobile_urls.append("http://www.example.com") asset_group.status = client.enums.AssetGroupStatusEnum.PAUSED asset_group.resource_name = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) operations.append(mutate_operation) # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # the resource name of the AssetGroup # the resource name of the Asset # the field_type of the Asset in this AssetGroup. # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups # Link the previously created multiple text assets. # Link the headline assets. for resource_name in headline_asset_resource_names: mutate_operation = client.get_type("MutateOperation") asset_group_asset = mutate_operation.asset_group_asset_operation.create asset_group_asset.field_type = client.enums.AssetFieldTypeEnum.HEADLINE asset_group_asset.asset_group = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) asset_group_asset.asset = resource_name operations.append(mutate_operation) # Link the description assets. for resource_name in description_asset_resource_names: mutate_operation = client.get_type("MutateOperation") asset_group_asset = mutate_operation.asset_group_asset_operation.create asset_group_asset.field_type = ( client.enums.AssetFieldTypeEnum.DESCRIPTION ) asset_group_asset.asset_group = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) asset_group_asset.asset = resource_name operations.append(mutate_operation) # Create and link the long headline text asset. mutate_operations = create_and_link_text_asset( client, customer_id, "Travel the World", client.enums.AssetFieldTypeEnum.LONG_HEADLINE, ) operations.extend(mutate_operations) # Create and link the business name text asset. mutate_operations = create_and_link_text_asset( client, customer_id, "Interplanetary Cruises", client.enums.AssetFieldTypeEnum.BUSINESS_NAME, ) operations.extend(mutate_operations) # Create and link the image assets. # Create and link the Logo Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", client.enums.AssetFieldTypeEnum.LOGO, "Marketing Logo", ) operations.extend(mutate_operations) # Create and link the Marketing Image Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/Eit5", client.enums.AssetFieldTypeEnum.MARKETING_IMAGE, "Marketing Image", ) operations.extend(mutate_operations) # Create and link the Square Marketing Image Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", client.enums.AssetFieldTypeEnum.SQUARE_MARKETING_IMAGE, "Square Marketing Image", ) operations.extend(mutate_operations) return operations
Ruby
# Creates a list of MutateOperations that create a new asset_group. # # A temporary ID will be assigned to this asset group so that it can # be referenced by other objects being created in the same Mutate request. def create_asset_group_operation( client, customer_id, headline_asset_resource_names, description_asset_resource_names) operations = [] # Create the AssetGroup operations << client.operation.mutate do |m| m.asset_group_operation = client.operation.create_resource.asset_group do |ag| ag.name = "Performance Max asset group #{SecureRandom.uuid}" ag.campaign = client.path.campaign( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) ag.final_urls << "http://www.example.com" ag.final_mobile_urls << "http://www.example.com" ag.status = :PAUSED ag.resource_name = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) end end # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets # # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # the resource name of the AssetGroup # the resource name of the Asset # the field_type of the Asset in this AssetGroup. # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups # Link the previously created multiple text assets. # Link the headline assets. headline_asset_resource_names.each do |resource_name| operations << client.operation.mutate do |m| m.asset_group_asset_operation = client.operation.create_resource .asset_group_asset do |aga| aga.field_type = :HEADLINE aga.asset_group = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) aga.asset = resource_name end end end # Link the description assets. description_asset_resource_names.each do |resource_name| operations << client.operation.mutate do |m| m.asset_group_asset_operation = client.operation.create_resource .asset_group_asset do |aga| aga.field_type = :DESCRIPTION aga.asset_group = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) aga.asset = resource_name end end end # Create and link the long headline text asset. operations += create_and_link_text_asset( client, customer_id, "Travel the World", :LONG_HEADLINE) # Create and link the business name text asset. operations += create_and_link_text_asset( client, customer_id, "Interplanetary Cruises", :BUSINESS_NAME) # Create and link the image assets. # Create and link the Logo Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", :LOGO, "Marketing Logo") # Create and link the Marketing Image Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/Eit5", :MARKETING_IMAGE, "Marketing Image") # Create and link the Square Marketing Image Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", :SQUARE_MARKETING_IMAGE, "Square Marketing Image") operations end
Perl
sub create_asset_group_operations { my ( $customer_id, $headline_asset_resource_names, $description_asset_resource_names ) = @_; my $operations = []; # Create a mutate operation that creates an asset group operation. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ assetGroupOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupService::AssetGroupOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroup->new({ resourceName => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), name => "Performance Max asset group #" . uniqid(), campaign => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), finalUrls => ["http://www.example.com"], finalMobileUrls => ["http://www.example.com"], status => Google::Ads::GoogleAds::V18::Enums::AssetGroupStatusEnum::PAUSED })})}); # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets. # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # - the resource name of the AssetGroup # - the resource name of the Asset # - the fieldType of the Asset in this AssetGroup # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups. # Link the previously created multiple text assets. # Link the headline assets. foreach my $resource_name (@$headline_asset_resource_names) { push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ assetGroupAssetOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupAssetService::AssetGroupAssetOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroupAsset->new({ asset => $resource_name, assetGroup => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), fieldType => HEADLINE })})}); } # Link the description assets. foreach my $resource_name (@$description_asset_resource_names) { push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ assetGroupAssetOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupAssetService::AssetGroupAssetOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroupAsset->new({ asset => $resource_name, assetGroup => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), fieldType => DESCRIPTION })})}); } # Create and link the long headline text asset. push @$operations, @{create_and_link_text_asset($customer_id, "Travel the World", LONG_HEADLINE)}; # Create and link the business name text asset. push @$operations, @{ create_and_link_text_asset($customer_id, "Interplanetary Cruises", BUSINESS_NAME)}; # Create and link the image assets. # Create and link the logo asset. push @$operations, @{ create_and_link_image_asset($customer_id, "https://gaagl.page.link/bjYi", LOGO, "Marketing Logo")}; # Create and link the marketing image asset. push @$operations, @{ create_and_link_image_asset( $customer_id, "https://gaagl.page.link/Eit5", MARKETING_IMAGE, "Marketing Image" )}; # Create and link the square marketing image asset. push @$operations, @{ create_and_link_image_asset( $customer_id, "https://gaagl.page.link/bjYi", SQUARE_MARKETING_IMAGE, "Square Marketing Image" )}; return $operations; }
A common approach for creating asset groups in Performance Max for retail campaigns is to organize asset groups by product or product group (more detail below).
An AssetGroup
is linked to an
Asset
by creating a new
AssetGroupAsset
and providing the following:
- Resource name of the
AssetGroup
- Resource name of the
Asset
AssetFieldType
of theAsset
in theAssetGroup
Code example
Java
/** Creates a list of MutateOperations that create a new AssetGroup. */ private List<MutateOperation> createAssetGroupOperations( long customerId, String assetGroupResourceName, List<String> headlineAssetResourceNames, List<String> descriptionAssetResourceNames) throws IOException { List<MutateOperation> mutateOperations = new ArrayList<>(); String campaignResourceName = ResourceNames.campaign(customerId, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID); // Creates the AssetGroup. AssetGroup assetGroup = AssetGroup.newBuilder() .setName("Performance Max asset group #" + getPrintableDateTime()) .setCampaign(campaignResourceName) .addFinalUrls("http://www.example.com") .addFinalMobileUrls("http://www.example.com") .setStatus(AssetGroupStatus.PAUSED) .setResourceName(assetGroupResourceName) .build(); AssetGroupOperation assetGroupOperation = AssetGroupOperation.newBuilder().setCreate(assetGroup).build(); mutateOperations.add( MutateOperation.newBuilder().setAssetGroupOperation(assetGroupOperation).build()); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // the resource name of the AssetGroup // the resource name of the Asset // the field_type of the Asset in this AssetGroup. // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups // Links the previously created multiple text assets. // Links the headline assets. for (String resourceName : headlineAssetResourceNames) { AssetGroupAsset assetGroupAsset = AssetGroupAsset.newBuilder() .setFieldType(AssetFieldType.HEADLINE) .setAssetGroup(assetGroupResourceName) .setAsset(resourceName) .build(); AssetGroupAssetOperation assetGroupAssetOperation = AssetGroupAssetOperation.newBuilder().setCreate(assetGroupAsset).build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupAssetOperation(assetGroupAssetOperation) .build()); } // Links the description assets. for (String resourceName : descriptionAssetResourceNames) { AssetGroupAsset assetGroupAsset = AssetGroupAsset.newBuilder() .setFieldType(AssetFieldType.DESCRIPTION) .setAssetGroup(assetGroupResourceName) .setAsset(resourceName) .build(); AssetGroupAssetOperation assetGroupAssetOperation = AssetGroupAssetOperation.newBuilder().setCreate(assetGroupAsset).build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupAssetOperation(assetGroupAssetOperation) .build()); } // Creates and links the long headline text asset. List<MutateOperation> createAndLinkTextAssetOperations = createAndLinkTextAsset(customerId, "Travel the World", AssetFieldType.LONG_HEADLINE); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the business name text asset. createAndLinkTextAssetOperations = createAndLinkTextAsset(customerId, "Interplanetary Cruises", AssetFieldType.BUSINESS_NAME); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the image assets. // Creates and links the Logo Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/bjYi", AssetFieldType.LOGO, "Marketing Logo"); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the Marketing Image Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/Eit5", AssetFieldType.MARKETING_IMAGE, "Marketing Image"); mutateOperations.addAll(createAndLinkTextAssetOperations); // Creates and links the Square Marketing Image Asset. createAndLinkTextAssetOperations = createAndLinkImageAsset( customerId, "https://gaagl.page.link/bjYi", AssetFieldType.SQUARE_MARKETING_IMAGE, "Square Marketing Image"); mutateOperations.addAll(createAndLinkTextAssetOperations); return mutateOperations; }
C#
/// <summary> /// Creates a list of MutateOperations that create a new asset_group. /// </summary> /// <param name="campaignResourceName">The campaign resource name.</param> /// <param name="assetGroupResourceName">The asset group resource name.</param> /// <param name="headlineAssetResourceNames">The headline asset resource names.</param> /// <param name="descriptionAssetResourceNames">The description asset resource /// names.</param> /// <param name="resourceNameGenerator">A generator for unique temporary ID's.</param> /// <param name="config">The Google Ads config.</param> /// <returns>A list of MutateOperations that create the new asset group.</returns> private List<MutateOperation> CreateAssetGroupOperations( string campaignResourceName, string assetGroupResourceName, List<string> headlineAssetResourceNames, List<string> descriptionAssetResourceNames, AssetGroupAssetTemporaryResourceNameGenerator resourceNameGenerator, GoogleAdsConfig config) { List<MutateOperation> operations = new List<MutateOperation>(); // Create the AssetGroup operations.Add( new MutateOperation() { AssetGroupOperation = new AssetGroupOperation() { Create = new AssetGroup() { Name = "Performance Max asset group #" + ExampleUtilities.GetRandomString(), Campaign = campaignResourceName, FinalUrls = { "http://www.example.com" }, FinalMobileUrls = { "http://www.example.com" }, Status = AssetGroupStatus.Paused, ResourceName = assetGroupResourceName } } } ); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // the resource name of the AssetGroup // the resource name of the Asset // the field_type of the Asset in this AssetGroup. // // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups // Link the previously created multiple text assets. // Link the headline assets. foreach (string resourceName in headlineAssetResourceNames) { operations.Add( new MutateOperation() { AssetGroupAssetOperation = new AssetGroupAssetOperation() { Create = new AssetGroupAsset() { FieldType = AssetFieldType.Headline, AssetGroup = assetGroupResourceName, Asset = resourceName } } } ); } // Link the description assets. foreach (string resourceName in descriptionAssetResourceNames) { operations.Add( new MutateOperation() { AssetGroupAssetOperation = new AssetGroupAssetOperation() { Create = new AssetGroupAsset() { FieldType = AssetFieldType.Description, AssetGroup = assetGroupResourceName, Asset = resourceName } } } ); } // Create and link the long headline text asset. operations.AddRange( CreateAndLinkTextAsset( assetGroupResourceName, resourceNameGenerator.Next(), "Travel the World", AssetFieldType.LongHeadline ) ); // Create and link the business name text asset. operations.AddRange( CreateAndLinkTextAsset( assetGroupResourceName, resourceNameGenerator.Next(), "Interplanetary Cruises", AssetFieldType.BusinessName ) ); // Create and link the image assets. // Create and link the Logo Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/bjYi", AssetFieldType.Logo, "Marketing Logo", config ) ); // Create and link the Marketing Image Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/Eit5", AssetFieldType.MarketingImage, "Marketing Image", config ) ); // Create and link the Square Marketing Image Asset. operations.AddRange( CreateAndLinkImageAsset( assetGroupResourceName, resourceNameGenerator.Next(), "https://gaagl.page.link/bjYi", AssetFieldType.SquareMarketingImage, "Square Marketing Image", config ) ); return operations; }
PHP
private static function createAssetGroupOperations( int $customerId, array $headlineAssetResourceNames, array $descriptionAssetResourceNames ): array { $operations = []; // Creates a new mutate operation that creates an asset group operation. $operations[] = new MutateOperation([ 'asset_group_operation' => new AssetGroupOperation([ 'create' => new AssetGroup([ 'resource_name' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'name' => 'Performance Max asset group #' . Helper::getPrintableDatetime(), 'campaign' => ResourceNames::forCampaign( $customerId, self::PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), 'final_urls' => ['http://www.example.com'], 'final_mobile_urls' => ['http://www.example.com'], 'status' => AssetGroupStatus::PAUSED ]) ]) ]); // For the list of required assets for a Performance Max campaign, see // https://developers.google.com/google-ads/api/docs/performance-max/assets // An AssetGroup is linked to an Asset by creating a new AssetGroupAsset // and providing: // - the resource name of the AssetGroup // - the resource name of the Asset // - the field_type of the Asset in this AssetGroup // // To learn more about AssetGroups, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups. // Links the previously created multiple text assets. // Links the headline assets. foreach ($headlineAssetResourceNames as $resourceName) { $operations[] = new MutateOperation([ 'asset_group_asset_operation' => new AssetGroupAssetOperation([ 'create' => new AssetGroupAsset([ 'asset' => $resourceName, 'asset_group' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'field_type' => AssetFieldType::HEADLINE ]) ]) ]); } // Links the description assets. foreach ($descriptionAssetResourceNames as $resourceName) { $operations[] = new MutateOperation([ 'asset_group_asset_operation' => new AssetGroupAssetOperation([ 'create' => new AssetGroupAsset([ 'asset' => $resourceName, 'asset_group' => ResourceNames::forAssetGroup( $customerId, self::ASSET_GROUP_TEMPORARY_ID ), 'field_type' => AssetFieldType::DESCRIPTION ]) ]) ]); } // Creates and links the long headline text asset. $operations = array_merge($operations, self::createAndLinkTextAsset( $customerId, 'Travel the World', AssetFieldType::LONG_HEADLINE )); // Creates and links the business name text asset. $operations = array_merge($operations, self::createAndLinkTextAsset( $customerId, 'Interplanetary Cruises', AssetFieldType::BUSINESS_NAME )); // Creates and links the image assets. // Creates and links the Logo Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/bjYi', AssetFieldType::LOGO, 'Marketing Logo' )); // Creates and links the Marketing Image Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/Eit5', AssetFieldType::MARKETING_IMAGE, 'Marketing Image' )); // Creates and links the Square Marketing Image Asset. $operations = array_merge($operations, self::createAndLinkImageAsset( $customerId, 'https://gaagl.page.link/bjYi', AssetFieldType::SQUARE_MARKETING_IMAGE, 'Square Marketing Image' )); return $operations; }
Python
def create_asset_group_operation( client, customer_id, headline_asset_resource_names, description_asset_resource_names, ): """Creates a list of MutateOperations that create a new asset_group. A temporary ID will be assigned to this asset group so that it can be referenced by other objects being created in the same Mutate request. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. headline_asset_resource_names: a list of headline resource names. description_asset_resource_names: a list of description resource names. Returns: MutateOperations that create a new asset group and related assets. """ asset_group_service = client.get_service("AssetGroupService") campaign_service = client.get_service("CampaignService") operations = [] # Create the AssetGroup mutate_operation = client.get_type("MutateOperation") asset_group = mutate_operation.asset_group_operation.create asset_group.name = f"Performance Max asset group #{uuid4()}" asset_group.campaign = campaign_service.campaign_path( customer_id, _PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ) asset_group.final_urls.append("http://www.example.com") asset_group.final_mobile_urls.append("http://www.example.com") asset_group.status = client.enums.AssetGroupStatusEnum.PAUSED asset_group.resource_name = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) operations.append(mutate_operation) # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # the resource name of the AssetGroup # the resource name of the Asset # the field_type of the Asset in this AssetGroup. # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups # Link the previously created multiple text assets. # Link the headline assets. for resource_name in headline_asset_resource_names: mutate_operation = client.get_type("MutateOperation") asset_group_asset = mutate_operation.asset_group_asset_operation.create asset_group_asset.field_type = client.enums.AssetFieldTypeEnum.HEADLINE asset_group_asset.asset_group = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) asset_group_asset.asset = resource_name operations.append(mutate_operation) # Link the description assets. for resource_name in description_asset_resource_names: mutate_operation = client.get_type("MutateOperation") asset_group_asset = mutate_operation.asset_group_asset_operation.create asset_group_asset.field_type = ( client.enums.AssetFieldTypeEnum.DESCRIPTION ) asset_group_asset.asset_group = asset_group_service.asset_group_path( customer_id, _ASSET_GROUP_TEMPORARY_ID, ) asset_group_asset.asset = resource_name operations.append(mutate_operation) # Create and link the long headline text asset. mutate_operations = create_and_link_text_asset( client, customer_id, "Travel the World", client.enums.AssetFieldTypeEnum.LONG_HEADLINE, ) operations.extend(mutate_operations) # Create and link the business name text asset. mutate_operations = create_and_link_text_asset( client, customer_id, "Interplanetary Cruises", client.enums.AssetFieldTypeEnum.BUSINESS_NAME, ) operations.extend(mutate_operations) # Create and link the image assets. # Create and link the Logo Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", client.enums.AssetFieldTypeEnum.LOGO, "Marketing Logo", ) operations.extend(mutate_operations) # Create and link the Marketing Image Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/Eit5", client.enums.AssetFieldTypeEnum.MARKETING_IMAGE, "Marketing Image", ) operations.extend(mutate_operations) # Create and link the Square Marketing Image Asset. mutate_operations = create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", client.enums.AssetFieldTypeEnum.SQUARE_MARKETING_IMAGE, "Square Marketing Image", ) operations.extend(mutate_operations) return operations
Ruby
# Creates a list of MutateOperations that create a new asset_group. # # A temporary ID will be assigned to this asset group so that it can # be referenced by other objects being created in the same Mutate request. def create_asset_group_operation( client, customer_id, headline_asset_resource_names, description_asset_resource_names) operations = [] # Create the AssetGroup operations << client.operation.mutate do |m| m.asset_group_operation = client.operation.create_resource.asset_group do |ag| ag.name = "Performance Max asset group #{SecureRandom.uuid}" ag.campaign = client.path.campaign( customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID) ag.final_urls << "http://www.example.com" ag.final_mobile_urls << "http://www.example.com" ag.status = :PAUSED ag.resource_name = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) end end # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets # # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # the resource name of the AssetGroup # the resource name of the Asset # the field_type of the Asset in this AssetGroup. # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups # Link the previously created multiple text assets. # Link the headline assets. headline_asset_resource_names.each do |resource_name| operations << client.operation.mutate do |m| m.asset_group_asset_operation = client.operation.create_resource .asset_group_asset do |aga| aga.field_type = :HEADLINE aga.asset_group = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) aga.asset = resource_name end end end # Link the description assets. description_asset_resource_names.each do |resource_name| operations << client.operation.mutate do |m| m.asset_group_asset_operation = client.operation.create_resource .asset_group_asset do |aga| aga.field_type = :DESCRIPTION aga.asset_group = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID) aga.asset = resource_name end end end # Create and link the long headline text asset. operations += create_and_link_text_asset( client, customer_id, "Travel the World", :LONG_HEADLINE) # Create and link the business name text asset. operations += create_and_link_text_asset( client, customer_id, "Interplanetary Cruises", :BUSINESS_NAME) # Create and link the image assets. # Create and link the Logo Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", :LOGO, "Marketing Logo") # Create and link the Marketing Image Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/Eit5", :MARKETING_IMAGE, "Marketing Image") # Create and link the Square Marketing Image Asset. operations += create_and_link_image_asset( client, customer_id, "https://gaagl.page.link/bjYi", :SQUARE_MARKETING_IMAGE, "Square Marketing Image") operations end
Perl
sub create_asset_group_operations { my ( $customer_id, $headline_asset_resource_names, $description_asset_resource_names ) = @_; my $operations = []; # Create a mutate operation that creates an asset group operation. push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ assetGroupOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupService::AssetGroupOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroup->new({ resourceName => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), name => "Performance Max asset group #" . uniqid(), campaign => Google::Ads::GoogleAds::V18::Utils::ResourceNames::campaign( $customer_id, PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ), finalUrls => ["http://www.example.com"], finalMobileUrls => ["http://www.example.com"], status => Google::Ads::GoogleAds::V18::Enums::AssetGroupStatusEnum::PAUSED })})}); # For the list of required assets for a Performance Max campaign, see # https://developers.google.com/google-ads/api/docs/performance-max/assets. # An AssetGroup is linked to an Asset by creating a new AssetGroupAsset # and providing: # - the resource name of the AssetGroup # - the resource name of the Asset # - the fieldType of the Asset in this AssetGroup # # To learn more about AssetGroups, see # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups. # Link the previously created multiple text assets. # Link the headline assets. foreach my $resource_name (@$headline_asset_resource_names) { push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ assetGroupAssetOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupAssetService::AssetGroupAssetOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroupAsset->new({ asset => $resource_name, assetGroup => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), fieldType => HEADLINE })})}); } # Link the description assets. foreach my $resource_name (@$description_asset_resource_names) { push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation ->new({ assetGroupAssetOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupAssetService::AssetGroupAssetOperation ->new({ create => Google::Ads::GoogleAds::V18::Resources::AssetGroupAsset->new({ asset => $resource_name, assetGroup => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), fieldType => DESCRIPTION })})}); } # Create and link the long headline text asset. push @$operations, @{create_and_link_text_asset($customer_id, "Travel the World", LONG_HEADLINE)}; # Create and link the business name text asset. push @$operations, @{ create_and_link_text_asset($customer_id, "Interplanetary Cruises", BUSINESS_NAME)}; # Create and link the image assets. # Create and link the logo asset. push @$operations, @{ create_and_link_image_asset($customer_id, "https://gaagl.page.link/bjYi", LOGO, "Marketing Logo")}; # Create and link the marketing image asset. push @$operations, @{ create_and_link_image_asset( $customer_id, "https://gaagl.page.link/Eit5", MARKETING_IMAGE, "Marketing Image" )}; # Create and link the square marketing image asset. push @$operations, @{ create_and_link_image_asset( $customer_id, "https://gaagl.page.link/bjYi", SQUARE_MARKETING_IMAGE, "Square Marketing Image" )}; return $operations; }
In Performance Max for retail campaigns, an
AssetGroupListingGroupFilter
lets you partition your products into groups, which are referred to as
listing groups in the web
interface. You can group using multiple dimensions to form a product partition
tree, which lets you include or exclude products from a given asset group.
Code example
Java
/** * Runs the example. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param assetGroupId the asset group id for the Performance Max campaign. * @param replaceExistingTree option to remove existing product tree from the passed in asset * group. * @throws GoogleAdsException if an API request failed with one or more service errors. */ private void runExample( GoogleAdsClient googleAdsClient, long customerId, long assetGroupId, boolean replaceExistingTree) throws Exception { String assetGroupResourceName = ResourceNames.assetGroup(customerId, assetGroupId); List<MutateOperation> operations = new ArrayList<>(); if (replaceExistingTree) { List<AssetGroupListingGroupFilter> existingListingGroupFilters = getAllExistingListingGroupFilterAssetsInAssetGroup( googleAdsClient, customerId, assetGroupResourceName); if (!existingListingGroupFilters.isEmpty()) { // A special factory object that ensures the creation of remove operations in the // correct order (child listing group filters must be removed before their parents). AssetGroupListingGroupFilterRemoveOperationFactory removeOperationFactory = new AssetGroupListingGroupFilterRemoveOperationFactory(existingListingGroupFilters); operations.addAll(removeOperationFactory.removeAll()); } } // Uses a factory to create all the MutateOperations that manipulate a specific // AssetGroup for a specific customer. The operations returned by the factory's methods // are used to construct a new tree of filters. These filters can have parent-child // relationships, and also include a special root that includes all children. // // When creating these filters, temporary IDs are used to create the hierarchy between // each of the nodes in the tree, beginning with the root listing group filter. // // The factory created below is specific to a customerId and assetGroupId. AssetGroupListingGroupFilterCreateOperationFactory createOperationFactory = new AssetGroupListingGroupFilterCreateOperationFactory( customerId, assetGroupId, TEMPORARY_ID_LISTING_GROUP_ROOT); // Creates the operation to add the root node of the tree. operations.add(createOperationFactory.createRoot()); // Creates an operation to add a leaf node for new products. ListingGroupFilterDimension newProductDimension = ListingGroupFilterDimension.newBuilder() .setProductCondition( ProductCondition.newBuilder() .setCondition(ListingGroupFilterProductCondition.NEW) .build()) .build(); operations.add( createOperationFactory.createUnit( TEMPORARY_ID_LISTING_GROUP_ROOT, createOperationFactory.nextId(), newProductDimension)); // Creates an operation to add a leaf node for used products. ListingGroupFilterDimension usedProductDimension = ListingGroupFilterDimension.newBuilder() .setProductCondition( ProductCondition.newBuilder() .setCondition(ListingGroupFilterProductCondition.USED) .build()) .build(); operations.add( createOperationFactory.createUnit( TEMPORARY_ID_LISTING_GROUP_ROOT, createOperationFactory.nextId(), usedProductDimension)); // This represents the ID of the "other" category in the ProductCondition subdivision. This ID // is saved because the node with this ID will be further partitioned, and this ID will serve as // the parent ID for subsequent child nodes of the "other" category. long otherSubdivisionId = createOperationFactory.nextId(); // Creates an operation to add a subdivision node for other products in the ProductCondition // subdivision. ListingGroupFilterDimension otherProductDimension = ListingGroupFilterDimension.newBuilder() .setProductCondition(ProductCondition.newBuilder().build()) .build(); operations.add( // Calls createSubdivision because this listing group will have children. createOperationFactory.createSubdivision( TEMPORARY_ID_LISTING_GROUP_ROOT, otherSubdivisionId, otherProductDimension)); // Creates an operation to add a leaf node for products with the brand "CoolBrand". ListingGroupFilterDimension coolBrandProductDimension = ListingGroupFilterDimension.newBuilder() .setProductBrand(ProductBrand.newBuilder().setValue("CoolBrand").build()) .build(); operations.add( createOperationFactory.createUnit( otherSubdivisionId, createOperationFactory.nextId(), coolBrandProductDimension)); // Creates an operation to add a leaf node for products with the brand "CheapBrand". ListingGroupFilterDimension cheapBrandProductDimension = ListingGroupFilterDimension.newBuilder() .setProductBrand(ProductBrand.newBuilder().setValue("CheapBrand").build()) .build(); operations.add( createOperationFactory.createUnit( otherSubdivisionId, createOperationFactory.nextId(), cheapBrandProductDimension)); // Creates an operation to add a leaf node for other products in the ProductBrand subdivision. ListingGroupFilterDimension otherBrandProductDimension = ListingGroupFilterDimension.newBuilder() .setProductBrand(ProductBrand.newBuilder().build()) .build(); operations.add( createOperationFactory.createUnit( otherSubdivisionId, createOperationFactory.nextId(), otherBrandProductDimension)); try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) { MutateGoogleAdsRequest request = MutateGoogleAdsRequest.newBuilder() .setCustomerId(Long.toString(customerId)) .addAllMutateOperations(operations) .build(); MutateGoogleAdsResponse response = googleAdsServiceClient.mutate(request); printResponseDetails(request, response); } }
C#
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="assetGroupId">The asset group id for the Performance Max campaign.</param> /// <param name="replaceExistingTree">Option to remove existing product tree /// from the passed in asset group.</param> public void Run( GoogleAdsClient client, long customerId, long assetGroupId, bool replaceExistingTree) { GoogleAdsServiceClient googleAdsServiceClient = client.GetService(Services.V18.GoogleAdsService); string assetGroupResourceName = ResourceNames.AssetGroup(customerId, assetGroupId); // We use a factory to create all the MutateOperations that manipulate a specific // AssetGroup for a specific customer. The operations returned by the factory's methods // are used to optionally remove all AssetGroupListingGroupFilters from the tree, and // then to construct a new tree of filters. These filters can have a parent-child // relationship, and also include a special root that includes all children. // // When creating these filters, we use temporary IDs to create the hierarchy between // the root listing group filter, and the subdivisions and leave nodes beneath that. // // The factory specific to a customerId and assetGroupId is created below. AssetGroupListingGroupFilterCreateOperationFactory createOperationFactory = new AssetGroupListingGroupFilterCreateOperationFactory( customerId, assetGroupId, TEMPORARY_ID_LISTING_GROUP_ROOT ); MutateGoogleAdsRequest request = new MutateGoogleAdsRequest { CustomerId = customerId.ToString() }; if (replaceExistingTree) { List<AssetGroupListingGroupFilter> existingListingGroupFilters = GetAllExistingListingGroupFilterAssetsInAssetGroup( client, customerId, assetGroupResourceName ); if (existingListingGroupFilters.Count > 0) { // A special factory object that ensures the creation of remove operations in the // correct order (child listing group filters must be removed before their parents). AssetGroupListingGroupFilterRemoveOperationFactory removeOperationFactory = new AssetGroupListingGroupFilterRemoveOperationFactory( existingListingGroupFilters ); request.MutateOperations.AddRange(removeOperationFactory.RemoveAll()); } } request.MutateOperations.Add(createOperationFactory.CreateRoot()); request.MutateOperations.Add( createOperationFactory.CreateUnit( TEMPORARY_ID_LISTING_GROUP_ROOT, createOperationFactory.NextId(), new ListingGroupFilterDimension() { ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition() { Condition = ListingGroupFilterProductCondition.New } } ) ); request.MutateOperations.Add( createOperationFactory.CreateUnit( TEMPORARY_ID_LISTING_GROUP_ROOT, createOperationFactory.NextId(), new ListingGroupFilterDimension() { ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition() { Condition = ListingGroupFilterProductCondition.Used } } ) ); // We save this ID because create child nodes underneath it. long subdivisionIdConditionOther = createOperationFactory.NextId(); request.MutateOperations.Add( // We're calling CreateSubdivision because this listing group will have children. createOperationFactory.CreateSubdivision( TEMPORARY_ID_LISTING_GROUP_ROOT, subdivisionIdConditionOther, new ListingGroupFilterDimension() { // All sibling nodes must have the same dimension type. We use an empty // ProductCondition to indicate that this is an "Other" partition. ProductCondition = new ListingGroupFilterDimension.Types.ProductCondition() } ) ); request.MutateOperations.Add( createOperationFactory.CreateUnit( subdivisionIdConditionOther, createOperationFactory.NextId(), new ListingGroupFilterDimension() { ProductBrand = new ProductBrand() { Value = "CoolBrand" } } ) ); request.MutateOperations.Add( createOperationFactory.CreateUnit( subdivisionIdConditionOther, createOperationFactory.NextId(), new ListingGroupFilterDimension() { ProductBrand = new ProductBrand() { Value = "CheapBrand" } } ) ); request.MutateOperations.Add( createOperationFactory.CreateUnit( subdivisionIdConditionOther, createOperationFactory.NextId(), new ListingGroupFilterDimension() { ProductBrand = new ProductBrand() } ) ); MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request); PrintResponseDetails(request, response); }
PHP
/** * Runs the example. * * @param GoogleAdsClient $googleAdsClient the Google Ads API client * @param int $customerId the customer ID * @param int $assetGroupId the asset group ID * @param bool $replaceExistingTree true if it should replace the existing listing group * tree on the asset group */ public static function runExample( GoogleAdsClient $googleAdsClient, int $customerId, int $assetGroupId, bool $replaceExistingTree ) { // We create all the mutate operations that manipulate a specific asset group for a specific // customer. The operations are used to optionally remove all asset group listing group // filters from the tree, and then to construct a new tree of filters. These filters can // have a parent-child relationship, and also include a special root that includes all // children. // // When creating these filters, we use temporary IDs to create the hierarchy between // the root listing group filter, and the subdivisions and leave nodes beneath that. $mutateOperations = []; if ($replaceExistingTree === true) { $existingListingGroupFilters = self::getAllExistingListingGroupFilterAssetsInAssetGroup( $googleAdsClient, $customerId, ResourceNames::forAssetGroup($customerId, $assetGroupId) ); if (count($existingListingGroupFilters) > 0) { $mutateOperations = array_merge( $mutateOperations, // Ensures the creation of remove operations in the correct order (child listing // group filters must be removed before their parents). self::createMutateOperationsForRemovingListingGroupFiltersTree( $existingListingGroupFilters ) ); } } $mutateOperations[] = self::createMutateOperationForRoot( $customerId, $assetGroupId, self::LISTING_GROUP_ROOT_TEMPORARY_ID ); // The temporary ID to be used for creating subdivisions and units. static $tempId = self::LISTING_GROUP_ROOT_TEMPORARY_ID - 1; $mutateOperations[] = self::createMutateOperationForUnit( $customerId, $assetGroupId, $tempId--, self::LISTING_GROUP_ROOT_TEMPORARY_ID, new ListingGroupFilterDimension([ 'product_condition' => new ProductCondition([ 'condition' => ListingGroupFilterProductCondition::PBNEW ]) ]) ); $mutateOperations[] = self::createMutateOperationForUnit( $customerId, $assetGroupId, $tempId--, self::LISTING_GROUP_ROOT_TEMPORARY_ID, new ListingGroupFilterDimension([ 'product_condition' => new ProductCondition([ 'condition' => ListingGroupFilterProductCondition::USED ]) ]) ); // We save this ID to create child nodes underneath it. $conditionOtherSubdivisionId = $tempId--; // We're calling createMutateOperationForSubdivision() because this listing group will // have children. $mutateOperations[] = self::createMutateOperationForSubdivision( $customerId, $assetGroupId, $conditionOtherSubdivisionId, self::LISTING_GROUP_ROOT_TEMPORARY_ID, new ListingGroupFilterDimension([ // All sibling nodes must have the same dimension type. We use an empty // ProductCondition to indicate that this is an "Other" partition. 'product_condition' => new ProductCondition() ]) ); $mutateOperations[] = self::createMutateOperationForUnit( $customerId, $assetGroupId, $tempId--, $conditionOtherSubdivisionId, new ListingGroupFilterDimension( ['product_brand' => new ProductBrand(['value' => 'CoolBrand'])] ) ); $mutateOperations[] = self::createMutateOperationForUnit( $customerId, $assetGroupId, $tempId--, $conditionOtherSubdivisionId, new ListingGroupFilterDimension([ 'product_brand' => new ProductBrand(['value' => 'CheapBrand']) ]) ); $mutateOperations[] = self::createMutateOperationForUnit( $customerId, $assetGroupId, $tempId--, $conditionOtherSubdivisionId, // All other product brands. new ListingGroupFilterDimension(['product_brand' => new ProductBrand()]) ); // Issues a mutate request to create everything and prints its information. $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient(); $response = $googleAdsServiceClient->mutate( MutateGoogleAdsRequest::build($customerId, $mutateOperations) ); self::printResponseDetails($mutateOperations, $response); }
Python
def main(client, customer_id, asset_group_id, replace_existing_tree): """The main method that creates all necessary entities for the example. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. asset_group_id: the asset group id for the Performance Max campaign. replace_existing_tree: option to remove existing product tree from the passed in asset group. """ googleads_service = client.get_service("GoogleAdsService") asset_group_resource_name = googleads_service.asset_group_path( customer_id, asset_group_id ) operations = [] if replace_existing_tree: # Retrieve a list of existing AssetGroupListingGroupFilters existing_listing_group_filters = ( get_all_existing_listing_group_filter_assets_in_asset_group( client, customer_id, asset_group_resource_name ) ) # If present, create MutateOperations to remove each # AssetGroupListingGroupFilter and add them to the list of operations. if existing_listing_group_filters: remove_operation_factory = ( AssetGroupListingGroupFilterRemoveOperationFactory( client, existing_listing_group_filters ) ) operations.extend(remove_operation_factory.remove_all()) create_operation_factory = ( AssetGroupListingGroupFilterCreateOperationFactory( client, customer_id, asset_group_id, _TEMPORARY_ID_LISTING_GROUP_ROOT, ) ) operations.append(create_operation_factory.create_root()) new_dimension = client.get_type("ListingGroupFilterDimension") new_dimension.product_condition.condition = ( client.enums.ListingGroupFilterProductConditionEnum.NEW ) operations.append( create_operation_factory.create_unit( _TEMPORARY_ID_LISTING_GROUP_ROOT, create_operation_factory.next_id(), new_dimension, ) ) used_dimension = client.get_type("ListingGroupFilterDimension") used_dimension.product_condition.condition = ( client.enums.ListingGroupFilterProductConditionEnum.USED ) operations.append( create_operation_factory.create_unit( _TEMPORARY_ID_LISTING_GROUP_ROOT, create_operation_factory.next_id(), used_dimension, ) ) # We save this ID because create child nodes underneath it. subdivision_id_condition_other = create_operation_factory.next_id() # All sibling nodes must have the same dimension type. We use an empty # product_condition to indicate that this is an "Other" partition. other_dimension = client.get_type("ListingGroupFilterDimension") # This triggers the presence of the product_condition field without # specifying any field values. This is important in order to tell the API # that this is an "other" node. other_dimension.product_condition._pb.SetInParent() # We're calling create_subdivision because this listing group will have # children. operations.append( create_operation_factory.create_subdivision( _TEMPORARY_ID_LISTING_GROUP_ROOT, subdivision_id_condition_other, other_dimension, ) ) cool_dimension = client.get_type("ListingGroupFilterDimension") cool_dimension.product_brand.value = "CoolBrand" operations.append( create_operation_factory.create_unit( subdivision_id_condition_other, create_operation_factory.next_id(), cool_dimension, ) ) cheap_dimension = client.get_type("ListingGroupFilterDimension") cheap_dimension.product_brand.value = "CheapBrand" operations.append( create_operation_factory.create_unit( subdivision_id_condition_other, create_operation_factory.next_id(), cheap_dimension, ) ) empty_dimension = client.get_type("ListingGroupFilterDimension") # This triggers the presence of the product_brand field without specifying # any field values. This is important in order to tell the API # that this is an "other" node. empty_dimension.product_brand._pb.SetInParent() operations.append( create_operation_factory.create_unit( subdivision_id_condition_other, create_operation_factory.next_id(), empty_dimension, ) ) response = googleads_service.mutate( customer_id=customer_id, mutate_operations=operations ) print_response_details(operations, response)
Ruby
def add_performance_max_product_listing_group_tree( customer_id, asset_group_id, replace_existing_tree) # GoogleAdsClient will read a config file from # ENV['HOME']/google_ads_config.rb when called without parameters client = Google::Ads::GoogleAds::GoogleAdsClient.new asset_group_resource_name = client.path.asset_group( customer_id, asset_group_id, ) # We use a factory to create all the MutateOperations that manipulate a # specific AssetGroup for a specific customer. The operations returned by the # factory's methods are used to optionally remove all # AssetGroupListingGroupFilters from the tree, and then to construct a new # tree of filters. These filters can have a parent-child relationship, and # also include a special root that includes all children. # # When creating these filters, we use temporary IDs to create the hierarchy # between the root listing group filter, and the subdivisions and leave nodes # beneath that. # # The factory specific to a customerId and assetGroupId is created below. create_operation_factory = AssetGroupListingGroupFilterCreateOperationFactory.new( customer_id, asset_group_id, TEMPORARY_ID_LISTING_GROUP_ROOT, ) operations = [] if replace_existing_tree existing_listing_group_filters = get_existing_listing_group_filters_in_asset_group( client, customer_id, asset_group_resource_name, ) if existing_listing_group_filters.length > 0 # A special factory object that ensures the creation of remove operations # in the correct order (child listing group filters must be removed # before their parents). remove_operation_factory = AssetGroupListingGroupFilterRemoveOperationFactory.new( existing_listing_group_filters ) operations += remove_operation_factory.remove_all(client) end end operations << create_operation_factory.create_root(client) operations << create_operation_factory.create_unit( client, TEMPORARY_ID_LISTING_GROUP_ROOT, create_operation_factory.next_id, client.resource.listing_group_filter_dimension do |dimension| dimension.product_condition = client.resource.product_condition do |condition| condition.condition = :NEW end end, ) operations << create_operation_factory.create_unit( client, TEMPORARY_ID_LISTING_GROUP_ROOT, create_operation_factory.next_id, client.resource.listing_group_filter_dimension do |dimension| dimension.product_condition = client.resource.product_condition do |condition| condition.condition = :USED end end, ) # We save this ID because we create child nodes underneath it. subdivision_id_condition_other = create_operation_factory.next_id operations << create_operation_factory.create_subdivision( client, TEMPORARY_ID_LISTING_GROUP_ROOT, subdivision_id_condition_other, client.resource.listing_group_filter_dimension do |dimension| dimension.product_condition = client.resource.product_condition do |condition| # All sibling nodes must have the same dimension type. We use an empty # ProductCondition to indicate that this is an "Other" partition. end end, ) operations << create_operation_factory.create_unit( client, subdivision_id_condition_other, create_operation_factory.next_id, client.resource.listing_group_filter_dimension do |dimension| dimension.product_brand = client.resource.product_brand do |brand| brand.value = 'CoolBrand' end end, ) operations << create_operation_factory.create_unit( client, subdivision_id_condition_other, create_operation_factory.next_id, client.resource.listing_group_filter_dimension do |dimension| dimension.product_brand = client.resource.product_brand do |brand| brand.value = 'CheapBrand' end end, ) operations << create_operation_factory.create_unit( client, subdivision_id_condition_other, create_operation_factory.next_id, client.resource.listing_group_filter_dimension do |dimension| dimension.product_brand = client.resource.product_brand do |brand| end end, ) response = client.service.google_ads.mutate( customer_id: customer_id, mutate_operations: operations, ) print_response_details(operations, response) end
Perl
sub add_performance_max_product_listing_group_tree { my ($api_client, $customer_id, $asset_group_id, $replace_existing_tree) = @_; # We create all the mutate operations that manipulate a specific asset group for # a specific customer. The operations are used to optionally remove all asset # group listing group filters from the tree, and then to construct a new tree # of filters. These filters can have a parent-child relationship, and also include # a special root that includes all children. # # When creating these filters, we use temporary IDs to create the hierarchy between # the root listing group filter, and the subdivisions and leave nodes beneath that. my $mutate_operations = []; if (defined $replace_existing_tree) { my $existing_listing_group_filters = get_all_existing_listing_group_filter_assets_in_asset_group( $api_client, $customer_id, Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, $asset_group_id )); if (scalar @$existing_listing_group_filters > 0) { push @$mutate_operations, # Ensure the creation of remove operations in the correct order (child # listing group filters must be removed before their parents). @{ create_mutate_operations_for_removing_listing_group_filters_tree( $existing_listing_group_filters)}; } } push @$mutate_operations, create_mutate_operation_for_root($customer_id, $asset_group_id, LISTING_GROUP_ROOT_TEMPORARY_ID); # The temporary ID to be used for creating subdivisions and units. my $temp_id = LISTING_GROUP_ROOT_TEMPORARY_ID - 1; push @$mutate_operations, create_mutate_operation_for_unit( $customer_id, $asset_group_id, $temp_id--, LISTING_GROUP_ROOT_TEMPORARY_ID, Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ productCondition => Google::Ads::GoogleAds::V18::Resources::ProductCondition->new({ condition => NEW })})); push @$mutate_operations, create_mutate_operation_for_unit( $customer_id, $asset_group_id, $temp_id--, LISTING_GROUP_ROOT_TEMPORARY_ID, Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ productCondition => Google::Ads::GoogleAds::V18::Resources::ProductCondition->new({ condition => USED })})); # We save this ID to create child nodes underneath it. my $condition_other_subdivision_id = $temp_id--; # We're calling create_mutate_operation_for_subdivision() because this listing # group will have children. push @$mutate_operations, create_mutate_operation_for_subdivision( $customer_id, $asset_group_id, $condition_other_subdivision_id, LISTING_GROUP_ROOT_TEMPORARY_ID, Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ # All sibling nodes must have the same dimension type. We use an empty # ProductCondition to indicate that this is an "Other" partition. productCondition => Google::Ads::GoogleAds::V18::Resources::ProductCondition->new({})})); push @$mutate_operations, create_mutate_operation_for_unit( $customer_id, $asset_group_id, $temp_id--, $condition_other_subdivision_id, Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ productBrand => Google::Ads::GoogleAds::V18::Resources::ProductBrand->new({ value => "CoolBrand" })})); push @$mutate_operations, create_mutate_operation_for_unit( $customer_id, $asset_group_id, $temp_id--, $condition_other_subdivision_id, Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ productBrand => Google::Ads::GoogleAds::V18::Resources::ProductBrand->new({ value => "CheapBrand" })})); push @$mutate_operations, create_mutate_operation_for_unit( $customer_id, $asset_group_id, $temp_id--, $condition_other_subdivision_id, # All other product brands. Google::Ads::GoogleAds::V18::Resources::ListingGroupFilterDimension->new({ productBrand => Google::Ads::GoogleAds::V18::Resources::ProductBrand->new({})})); # Issue a mutate request to create everything and print its information. my $response = $api_client->GoogleAdsService()->mutate({ customerId => $customer_id, mutateOperations => $mutate_operations }); print_response_details($mutate_operations, $response); return 1; }
An AssetGroupSignal
is a signal that you can
provide to Google to optimize ad serving at the asset group level. There are two
types of hints that you can provide to Google:
audience
: A reusable collection of focused segments, demographic targeting, and exclusionssearch_theme
: Information about what your customers are searching for and which topics lead to conversions for your business that you can provide to Google AI
Audience signal code example
Java
AssetGroupSignal audienceSignal = AssetGroupSignal.newBuilder() .setAssetGroup(assetGroupResourceName) .setAudience( AudienceInfo.newBuilder() .setAudience(ResourceNames.audience(customerId, audienceId))) .build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupSignalOperation( AssetGroupSignalOperation.newBuilder().setCreate(audienceSignal)) .build());
C#
operations.Add( new MutateOperation() { AssetGroupSignalOperation = new AssetGroupSignalOperation() { Create = new AssetGroupSignal() { AssetGroup = assetGroupResourceName, Audience = new AudienceInfo() { Audience = ResourceNames.Audience(customerId, audienceId.Value) } } } } );
PHP
private static function createAssetGroupSignalOperations( int $customerId, string $assetGroupResourceName, ?int $audienceId ): array { $operations = []; if (is_null($audienceId)) { return $operations; } $operations[] = new MutateOperation([ 'asset_group_signal_operation' => new AssetGroupSignalOperation([ // To learn more about Audience Signals, see // https://developers.google.com/google-ads/api/docs/performance-max/asset-groups#audience_signals. 'create' => new AssetGroupSignal([ 'asset_group' => $assetGroupResourceName, 'audience' => new AudienceInfo([ 'audience' => ResourceNames::forAudience($customerId, $audienceId) ]) ]) ]) ]); return $operations; }
Python
mutate_operation = client.get_type("MutateOperation") operation = mutate_operation.asset_group_signal_operation.create operation.asset_group = asset_group_resource_name operation.audience.audience = googleads_service.audience_path( customer_id, audience_id ) operations.append(mutate_operation)
Ruby
# Create a list of MutateOperations that create AssetGroupSignals. def create_asset_group_signal_operations(client, customer_id, audience_id) operations = [] return operations if audience_id.nil? operations << client.operation.mutate do |m| m.asset_group_signal_operation = client.operation.create_resource. asset_group_signal do |ags| ags.asset_group = client.path.asset_group( customer_id, ASSET_GROUP_TEMPORARY_ID, ) ags.audience = client.resource.audience_info do |ai| ai.audience = client.path.audience(customer_id, audience_id) end end end operations end
Perl
sub create_asset_group_signal_operations { my ($customer_id, $audience_id) = @_; my $operations = []; return $operations if not defined $audience_id; push @$operations, Google::Ads::GoogleAds::V18::Services::GoogleAdsService::MutateOperation-> new({ assetGroupSignalOperation => Google::Ads::GoogleAds::V18::Services::AssetGroupSignalService::AssetGroupSignalOperation ->new({ # To learn more about Audience Signals, see: # https://developers.google.com/google-ads/api/docs/performance-max/asset-groups#audience_signals create => Google::Ads::GoogleAds::V18::Resources::AssetGroupSignal->new({ assetGroup => Google::Ads::GoogleAds::V18::Utils::ResourceNames::asset_group( $customer_id, ASSET_GROUP_TEMPORARY_ID ), audience => Google::Ads::GoogleAds::V18::Common::AudienceInfo->new({ audience => Google::Ads::GoogleAds::V18::Utils::ResourceNames::audience( $customer_id, $audience_id )})})})}); return $operations; }
Search theme signal code example
Java
AssetGroupSignal searchThemeSignal = AssetGroupSignal.newBuilder() .setAssetGroup(assetGroupResourceName) .setSearchTheme(SearchThemeInfo.newBuilder().setText("travel").build()) .build(); mutateOperations.add( MutateOperation.newBuilder() .setAssetGroupSignalOperation( AssetGroupSignalOperation.newBuilder().setCreate(searchThemeSignal)) .build());
C#
This example is not yet available in C#; you can take a look at the other languages.
PHP
This example is not yet available in PHP; you can take a look at the other languages.
Python
mutate_operation = client.get_type("MutateOperation") operation = mutate_operation.asset_group_signal_operation.create operation.asset_group = asset_group_resource_name operation.search_theme.text = "travel" operations.append(mutate_operation)
Ruby
This example is not yet available in Ruby; you can take a look at the other languages.
Perl
This example is not yet available in Perl; you can take a look at the other languages.
Only some ValueTrack parameters are supported for Performance Max campaigns (learn more).
Optimization with recommendations
Performance Max recommendations categories: