Performance Max campaigns using AdsApp

Google Ads scripts provide for some management of yourPerformance Maxcampaigns. You can usescripts to retrieve Performance Max campaigns, manage asset groups, and runreports; however, you can't use scripts to create Performance Max campaigns. Todo more advanced operations, see the remainder of this guide, which demonstrates a more generic approach usingmutate.

Retrieval of Performance Max campaigns

Performance max campaigns are available through theperformanceMaxCampaignscollection of anAdsAppobject. You can retrieve them as usual:

constcampaignName="My Performance Max campaign";constcampaignIterator=AdsApp.performanceMaxCampaigns().withCondition(`campaign.name = "${campaignName}"`).get();for(constcampaignofcampaignIterator){...}

Unlike some other campaign types, Performance Max campaigns do not have adgroups or ad objects that you can see; everything related to these concepts forother campaigns is handled automatically for you based on the asset groups youset.

Assets and asset groups

Ads from Performance Max campaigns run off ofassets such as videos,images, headlines, and descriptions—either provided by you orautomatically generated. For a full overview of what kinds of assets arerequired, see theGoogle Ads API Performance Max assetguide.

Assets for Performance Max campaigns are bundled together into an asset group,and each Performance Max campaign must have at least one asset group. Youcannot create these asset groups directly in scripts, but you can add andremove assets from an existing asset group.

Add asset to asset group

First, create the asset:

constimageUrl="http://www.example.com/example.png";constimageBlob=UrlFetchApp.fetch(imageUrl).getBlob();constassetOperation=AdsApp.adAssets().newImageAssetBuilder().withName("new asset name").withData(imageBlob).build();constimageAsset=assetOperation.getResult();

Then, using the asset you just created, add it to an existing asset group:

// First, fetch the Performance Max campaign we want to operate on.constcampaignIterator=AdsApp.performanceMaxCampaigns().withCondition(`campaign.name = '${campaignName}'`).get();letcampaign;if(campaignIterator.hasNext()){campaign=campaignIterator.next();}else{throw`No campaign found with name${campaignName}.`}// Then, get that campaign's asset groups.constassetGroupIterator=campaign.assetGroups().get();// The campaign must have at least one asset group, so we can just assume so here.constassetGroup=assetGroupIterator.next();// Add the asset from the previous step.assetGroup.addAsset(imageAsset,'MARKETING_IMAGE');

Note how you must specify the type of asset in the last step. You can find acomplete list of asset types in theGoogle Ads APIdocumentation

To use an existing asset, first create an asset selector:

constassetSelector=AdsApp.adAssets().assets();

Then use awithCondition filter to narrow down to the assets you want tooperate on. See theAssetSelectorreference documentation for a full list of filter options.

Finally, fetch the iterator and iterate as with other entities:

constassetIterator=assetSelector.get();for(constassetofassetIterator){...}

Text assets

Text assets work a little differently, in that you don't need to make the assetin advance. You just specify the text instead of an asset, and the system willcreate the asset for you automatically. If the text is an exact duplicate of anexisting text asset, the existing asset will be re-used instead.

For example, here's how to create a headline asset:

assetGroup.addAsset('asset text here','HEADLINE');

Remove asset from asset group

You can also remove an asset from an asset group; however, keep in mind thatyou must have aminimum number of certain kinds ofassetsin order for the campaign to be valid.

Here is how to remove the asset that was added in the previous example:

assetGroup.removeAsset(imageAsset,'MARKETING_IMAGE');

You can also get a list of assets in a given asset group with thesearchfunction:

// The resource name is a unique identifier for this asset group.constassetGroupName=assetGroup.getResourceName();results=AdsApp.search(`SELECT asset.resource_name, asset_group_asset.field_type    FROM asset_group_asset    WHERE asset_group.resource_name = '${assetGroupName}'`);

This selects the asset's resource name as its unique identifier. You couldselect other fields as well, such asasset.type orasset.text_asset.text tofurther refine the results. Use thequery builder for this reporttype to craftyour own query.

Once you have the target asset, callremove on the asset group to remove theasset from the asset group:

// Let's assume at least one asset is returned. We'll just remove the first// asset, whatever it is. In your code, customize this to choose the right asset.constrow_info=results.next().asset;assetGroup.remove(row_info.asset.resource_name,row_info.asset_group_asset.field_type);

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

Last updated 2025-07-11 UTC.