Skip to content
Back to skills

607 Best Practices 99fa6cef

ASecurity

Detailed best practices with code examples for writing efficient, reliable Google Ads Scripts.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
developmentjavascriptgojavarailsapi

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 607-best-practices_99fa6cef --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 607 Best Practices 99fa6cef?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 607 Best Practices 99fa6cef
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-607-best-practices-99fa6cef/badge)](https://www.skillsdirectory.com/skills/tools-only-607-best-practices-99fa6cef)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Google Ads Scripts - Best Practices

Detailed best practices with code examples for writing efficient, reliable Google Ads Scripts.

## 1. Use Batch Operations

Avoid individual API calls in loops. Instead, collect entities and perform batch operations:

```javascript
// Good - Batch collection
const keywords = AdsApp.keywords()
  .withCondition('keyword.quality_info.quality_score < 5')
  .get();

const toUpdate = [];
while (keywords.hasNext()) {
  toUpdate.push(keywords.next());
}

toUpdate.forEach(keyword => keyword.setMaxCpc(50000));
```

## 2. Filter with Conditions

Use `.withCondition()` to filter at the API level rather than in JavaScript:

```javascript
// Good - API-level filtering
const campaigns = AdsApp.campaigns()
  .withCondition('campaign.status = ENABLED')
  .withCondition('campaign.budget_information.budget_amount > 100000000')
  .get();
```

## 3. Handle Errors Gracefully

Always wrap operations in try-catch blocks and log errors:

```javascript
function safeOperation() {
  try {
    // Operation code
  } catch (error) {
    Logger.log('Error: ' + error.message);
    Logger.log('Stack: ' + error.stack);

    // Optionally email alert
    MailApp.sendEmail(
      Session.getEffectiveUser().getEmail(),
      'Ads Script Error',
      error.message
    );
  }
}
```

## 4. Respect Execution Limits

Scripts have a 30-minute execution timeout. For large accounts:

- Limit result sets with `.withLimit()`
- Process in batches
- Use early termination when needed

## 5. Convert Micros Correctly

Google Ads API uses micros (1/1,000,000) for currency values:

```javascript
const costMicros = stats.getCost();
const costCurrency = costMicros / 1000000;  // Convert to dollars/local currency

const bidCurrency = 5.00;  // $5.00
const bidMicros = bidCurrency * 1000000;  // 5000000 micros
```

## 6. Log Operations for Auditing

Maintain audit trails by logging changes to Google Sheets:

```javascript
function logChange(operation, entity, details) {
  const ss = SpreadsheetApp.openById('LOG_SHEET_ID');
  const sheet = ss.getSheetByName('Audit Log');
  sheet.appendRow([
    new Date(),
    operation,
    entity,
    JSON.stringify(details)
  ]);
}
```

Files in this skill

  • README.md1 KB
  • skill.md2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.