This script scans enabled Performance Max campaigns, checks enabled asset group names for a date in YYYY-MM-DD format, and pauses any asset group whose extracted date is already in the past. If no valid date is found, the asset group is skipped. Name your asset groups like Summer Sale - 2026-07-15 and this keeps expired, date-based creative from continuing to serve.
Setup
- In Google Ads, go to Tools > Bulk Actions > Scripts.
- Click the blue + button to create a new script.
- Paste the code below, replacing any placeholder code.
- Click Authorize, then Preview and check the Logs tab to confirm it's identifying expected asset groups.
- Click Save, then set the schedule to Daily.
Script code
function main() {
// Set reference date to today at midnight (00:00:00)
const today = new Date();
today.setHours(0, 0, 0, 0);
let pausedCount = 0;
// Fetch enabled Performance Max campaigns
const campaignIterator = AdsApp.performanceMaxCampaigns()
.withCondition("campaign.status = 'ENABLED'")
.get();
while (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
// Fetch enabled asset groups within each Performance Max campaign
const assetGroupIterator = campaign.assetGroups()
.withCondition("asset_group.status = 'ENABLED'")
.get();
while (assetGroupIterator.hasNext()) {
const assetGroup = assetGroupIterator.next();
const name = assetGroup.getName();
const extractedDate = extractDateFromName(name);
if (extractedDate) {
extractedDate.setHours(0, 0, 0, 0);
if (extractedDate < today) {
assetGroup.pause();
pausedCount++;
Logger.log(`PAUSED: "${name}" (Campaign: "${campaign.getName()}") | Extracted Date: ${formatDate(extractedDate)}`);
} else {
Logger.log(`ACTIVE (Current/Future): "${name}" | Extracted Date: ${formatDate(extractedDate)}`);
}
}
}
}
Logger.log(`Execution complete. Total asset groups paused: ${pausedCount}`);
}
/**
* Extracts strictly YYYY-MM-DD formatted dates from asset group names.
*/
function extractDateFromName(name) {
// Matches YYYY-MM-DD only
const match = name.match(/\b(20\d{2})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b/);
if (match) {
return new Date(parseInt(match[1], 10), parseInt(match[2], 10) - 1, parseInt(match[3], 10));
}
return null;
}
function formatDate(date) {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
Want scripts like this built out for your own account?
Get started