3333import com .google .ads .googleads .v10 .enums .CampaignStatusEnum .CampaignStatus ;
3434import com .google .ads .googleads .v10 .enums .ConversionActionCategoryEnum .ConversionActionCategory ;
3535import com .google .ads .googleads .v10 .enums .ConversionOriginEnum .ConversionOrigin ;
36+ import com .google .ads .googleads .v10 .enums .ListingGroupFilterTypeEnum .ListingGroupFilterType ;
37+ import com .google .ads .googleads .v10 .enums .ListingGroupFilterVerticalEnum .ListingGroupFilterVertical ;
3638import com .google .ads .googleads .v10 .errors .GoogleAdsError ;
3739import com .google .ads .googleads .v10 .errors .GoogleAdsException ;
3840import com .google .ads .googleads .v10 .resources .Asset ;
3941import com .google .ads .googleads .v10 .resources .AssetGroup ;
4042import com .google .ads .googleads .v10 .resources .AssetGroupAsset ;
43+ import com .google .ads .googleads .v10 .resources .AssetGroupListingGroupFilter ;
4144import com .google .ads .googleads .v10 .resources .Campaign ;
4245import com .google .ads .googleads .v10 .resources .Campaign .ShoppingSetting ;
4346import com .google .ads .googleads .v10 .resources .CampaignBudget ;
4447import com .google .ads .googleads .v10 .resources .CampaignConversionGoal ;
4548import com .google .ads .googleads .v10 .resources .CampaignCriterion ;
4649import com .google .ads .googleads .v10 .resources .CustomerConversionGoal ;
4750import com .google .ads .googleads .v10 .services .AssetGroupAssetOperation ;
51+ import com .google .ads .googleads .v10 .services .AssetGroupListingGroupFilterOperation ;
4852import com .google .ads .googleads .v10 .services .AssetGroupOperation ;
4953import com .google .ads .googleads .v10 .services .AssetOperation ;
5054import com .google .ads .googleads .v10 .services .CampaignBudgetOperation ;
@@ -124,8 +128,11 @@ private static class AddPerformanceMaxRetailCampaignParams extends CodeSamplePar
124128
125129 @ Parameter (
126130 names = ArgumentNames .FINAL_URL ,
127- description = "The final URL for the asset group of the campaign." )
128- private String finalUrl = "http://www.example.com" ;
131+ required = true ,
132+ description =
133+ "The final url for the generated ads. Must have the same domain as the Merchant Center"
134+ + " account." )
135+ private String finalUrl ;
129136 }
130137
131138 public static void main (String [] args ) throws IOException {
@@ -136,10 +143,10 @@ public static void main(String[] args) throws IOException {
136143 // into the code here. See the parameter class definition above for descriptions.
137144 params .customerId = Long .parseLong ("INSERT_CUSTOMER_ID_HERE" );
138145 params .merchantCenterAccountId = Long .parseLong ("INSERT_MERCHANT_CENTER_ACCOUNT_ID_HERE" );
146+ params .finalUrl = "INSERT_FINAL_URL_HERE" ;
139147
140- // Optionally set custom values for the parameters below .
148+ // Optionally set the country code .
141149 // params.countryCode = "INSERT_COUNTRY_CODE_HERE";
142- // params.finalUrl = "INSERT_FINAL_URL_HERE";
143150 }
144151
145152 GoogleAdsClient googleAdsClient = null ;
@@ -228,10 +235,18 @@ private void runExample(
228235 mutateOperations .add (
229236 createPerformanceMaxCampaignOperation (customerId , merchantCenterAccountId , countryCode ));
230237 mutateOperations .addAll (createCampaignCriterionOperations (customerId ));
238+ String assetGroupResourceName = ResourceNames .assetGroup (customerId , ASSET_GROUP_TEMPORARY_ID );
231239 mutateOperations .addAll (
232240 createAssetGroupOperations (
233- customerId , headlineAssetResourceNames , descriptionAssetResourceNames , finalUrl ));
241+ customerId ,
242+ assetGroupResourceName ,
243+ headlineAssetResourceNames ,
244+ descriptionAssetResourceNames ,
245+ finalUrl ));
234246 mutateOperations .addAll (createConversionGoalOperations (customerId , customerConversionGoals ));
247+ // Retail Performance Max campaigns require listing groups, which are created via the
248+ // AssetGroupListingGroupFilter resource.
249+ mutateOperations .add (createAssetGroupListingGroupFilterOperation (assetGroupResourceName ));
235250
236251 try (GoogleAdsServiceClient googleAdsServiceClient =
237252 googleAdsClient .getLatestVersion ().createGoogleAdsServiceClient ()) {
@@ -297,13 +312,17 @@ private MutateOperation createPerformanceMaxCampaignOperation(
297312 .setSalesCountry (countryCode )
298313 .build ())
299314 // Sets the Final URL expansion opt out. This flag is specific to
300- // Performance Max campaigns. If opted out (True ), only the final URLs in
315+ // Performance Max campaigns. If opted out (true ), only the final URLs in
301316 // the asset group or URLs specified in the advertiser's Google Merchant
302317 // Center or business data feeds are targeted.
303- // If opted in (False), the entire domain will be targeted. For best
318+ //
319+ // If opted in (false), the entire domain will be targeted. For best
304320 // results, set this value to false to opt in and allow URL expansions. You
305321 // can optionally add exclusions to limit traffic to parts of your website.
306- .setUrlExpansionOptOut (false )
322+ //
323+ // Sets to true for this Retail campaign so the final URLs will be limited to those
324+ // explicitly surfaced via Google Merchant Center.
325+ .setUrlExpansionOptOut (true )
307326 // Assigns the resource name with a temporary ID.
308327 .setResourceName (
309328 ResourceNames .campaign (customerId , PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID ))
@@ -413,14 +432,14 @@ private List<String> createMultipleTextAssets(
413432 /** Creates a list of MutateOperations that create a new AssetGroup. */
414433 private List <MutateOperation > createAssetGroupOperations (
415434 long customerId ,
435+ String assetGroupResourceName ,
416436 List <String > headlineAssetResourceNames ,
417437 List <String > descriptionAssetResourceNames ,
418438 String finalUrl )
419439 throws IOException {
420440 List <MutateOperation > mutateOperations = new ArrayList <>();
421441 String campaignResourceName =
422442 ResourceNames .campaign (customerId , PERFORMANCE_MAX_CAMPAIGN_TEMPORARY_ID );
423- String assetGroupResourceName = ResourceNames .assetGroup (customerId , ASSET_GROUP_TEMPORARY_ID );
424443 // Creates the AssetGroup.
425444 AssetGroup assetGroup =
426445 AssetGroup .newBuilder ()
@@ -483,40 +502,46 @@ private List<MutateOperation> createAssetGroupOperations(
483502 }
484503
485504 // Creates and links the long headline text asset.
486- List < MutateOperation > createAndLinkTextAssetOperations =
487- createAndLinkTextAsset (customerId , "Travel the World" , AssetFieldType . LONG_HEADLINE );
488- mutateOperations . addAll ( createAndLinkTextAssetOperations );
505+ mutateOperations . addAll (
506+ createAndLinkTextAsset (
507+ customerId , assetGroupResourceName , "Travel the World" , AssetFieldType . LONG_HEADLINE ) );
489508
490509 // Creates and links the business name text asset.
491- createAndLinkTextAssetOperations =
492- createAndLinkTextAsset (customerId , "Interplanetary Cruises" , AssetFieldType .BUSINESS_NAME );
493- mutateOperations .addAll (createAndLinkTextAssetOperations );
510+ mutateOperations .addAll (
511+ createAndLinkTextAsset (
512+ customerId ,
513+ assetGroupResourceName ,
514+ "Interplanetary Cruises" ,
515+ AssetFieldType .BUSINESS_NAME ));
494516
495517 // Creates and links the image assets.
496518
497519 // Creates and links the Logo Asset.
498- createAndLinkTextAssetOperations =
520+ mutateOperations . addAll (
499521 createAndLinkImageAsset (
500- customerId , "https://gaagl.page.link/bjYi" , AssetFieldType .LOGO , "Logo Image" );
501- mutateOperations .addAll (createAndLinkTextAssetOperations );
522+ customerId ,
523+ assetGroupResourceName ,
524+ "https://gaagl.page.link/bjYi" ,
525+ AssetFieldType .LOGO ,
526+ "Logo Image" ));
502527
503528 // Creates and links the Marketing Image Asset.
504- createAndLinkTextAssetOperations =
529+ mutateOperations . addAll (
505530 createAndLinkImageAsset (
506531 customerId ,
532+ assetGroupResourceName ,
507533 "https://gaagl.page.link/Eit5" ,
508534 AssetFieldType .MARKETING_IMAGE ,
509- "Marketing Image" );
510- mutateOperations .addAll (createAndLinkTextAssetOperations );
535+ "Marketing Image" ));
511536
512537 // Creates and links the Square Marketing Image Asset.
513- createAndLinkTextAssetOperations =
538+ mutateOperations . addAll (
514539 createAndLinkImageAsset (
515540 customerId ,
541+ assetGroupResourceName ,
516542 "https://gaagl.page.link/bjYi" ,
517543 AssetFieldType .SQUARE_MARKETING_IMAGE ,
518- "Square Marketing Image" );
519- mutateOperations .addAll (createAndLinkTextAssetOperations );
544+ "Square Marketing Image" ));
520545
521546 return mutateOperations ;
522547 }
@@ -525,7 +550,7 @@ private List<MutateOperation> createAssetGroupOperations(
525550 // [START add_performance_max_retail_campaign_7]
526551 /** Creates a list of MutateOperations that create a new linked text asset. */
527552 List <MutateOperation > createAndLinkTextAsset (
528- long customerId , String text , AssetFieldType assetFieldType ) {
553+ long customerId , String assetGroupResourceName , String text , AssetFieldType assetFieldType ) {
529554 List <MutateOperation > mutateOperations = new ArrayList <>();
530555 String assetResourceName = ResourceNames .asset (customerId , getNextTemporaryId ());
531556 // Creates the Text Asset.
@@ -541,7 +566,7 @@ List<MutateOperation> createAndLinkTextAsset(
541566 AssetGroupAsset assetGroupAsset =
542567 AssetGroupAsset .newBuilder ()
543568 .setFieldType (assetFieldType )
544- .setAssetGroup (ResourceNames . assetGroup ( customerId , ASSET_GROUP_TEMPORARY_ID ) )
569+ .setAssetGroup (assetGroupResourceName )
545570 .setAsset (assetResourceName )
546571 .build ();
547572 AssetGroupAssetOperation assetGroupAssetOperation =
@@ -556,7 +581,11 @@ List<MutateOperation> createAndLinkTextAsset(
556581 // [START add_performance_max_retail_campaign_8]
557582 /** Creates a list of MutateOperations that create a new linked image asset. */
558583 List <MutateOperation > createAndLinkImageAsset (
559- long customerId , String url , AssetFieldType assetFieldType , String assetName )
584+ long customerId ,
585+ String assetGroupResourceName ,
586+ String url ,
587+ AssetFieldType assetFieldType ,
588+ String assetName )
560589 throws IOException {
561590 List <MutateOperation > mutateOperations = new ArrayList <>();
562591 String assetResourceName = ResourceNames .asset (customerId , getNextTemporaryId ());
@@ -580,7 +609,7 @@ List<MutateOperation> createAndLinkImageAsset(
580609 AssetGroupAsset assetGroupAsset =
581610 AssetGroupAsset .newBuilder ()
582611 .setFieldType (assetFieldType )
583- .setAssetGroup (ResourceNames . assetGroup ( customerId , ASSET_GROUP_TEMPORARY_ID ) )
612+ .setAssetGroup (assetGroupResourceName )
584613 .setAsset (assetResourceName )
585614 .build ();
586615 AssetGroupAssetOperation assetGroupAssetOperation =
@@ -658,6 +687,35 @@ private static List<MutateOperation> createConversionGoalOperations(
658687 }
659688 // [END add_performance_max_retail_campaign_9]
660689
690+ // [START add_performance_max_retail_campaign_10]
691+ /** Creates a MutateOperation that creates a new asset group listing group filter. */
692+ private MutateOperation createAssetGroupListingGroupFilterOperation (
693+ String assetGroupResourceName ) {
694+
695+ // Creates a new asset group listing group filter containing the "default" listing group (All
696+ // products).
697+ AssetGroupListingGroupFilter listingGroupFilter =
698+ AssetGroupListingGroupFilter .newBuilder ()
699+ .setAssetGroup (assetGroupResourceName )
700+ // Does not set the parentListingGroupFilter since this is the root node. For all other
701+ // nodes, this would refer to the parent listing group filter resource name.
702+ // .setParentListingGroupFilter("<PARENT FILTER RESOURCE NAME>")
703+
704+ // Sets the type to UNIT_INCLUDED since this node has no children.
705+ .setType (ListingGroupFilterType .UNIT_INCLUDED )
706+ // Specifies that this is in the SHOPPING vertical, as required for a Performance Max
707+ // retail campaign.
708+ .setVertical (ListingGroupFilterVertical .SHOPPING )
709+ .build ();
710+
711+ // Returns an operation to the list to create the listing group filter.
712+ return MutateOperation .newBuilder ()
713+ .setAssetGroupListingGroupFilterOperation (
714+ AssetGroupListingGroupFilterOperation .newBuilder ().setCreate (listingGroupFilter ))
715+ .build ();
716+ }
717+ // [END add_performance_max_retail_campaign_10]
718+
661719 /**
662720 * Prints the details of a MutateGoogleAdsResponse.
663721 *
0 commit comments