Documentation>Google Sheets Integration
Intermediate Level

Google Sheets Integration

Connect your scripts with Google Sheets for data import/export, dynamic configuration, and collaborative campaign management.

30 minutes
Data Export
  • Campaign performance reports
  • Keyword analysis data
  • Automated daily summaries
  • Custom dashboard data
Configuration
  • Dynamic script settings
  • Budget allocation rules
  • Bid adjustment factors
  • Campaign targeting lists
Collaboration
  • Team-shared configurations
  • Client reporting dashboards
  • Approval workflows
  • Audit trails and logging
Basic Sheet Operations
// Basic Google Sheets integration example
function exportCampaignData() {
  const SHEET_URL = 'https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit';
  const sheet = SpreadsheetApp.openByUrl(SHEET_URL).getActiveSheet();
  
  // Clear existing data (keeping headers)
  const lastRow = sheet.getLastRow();
  if (lastRow > 1) {
    sheet.getRange(2, 1, lastRow - 1, sheet.getLastColumn()).clear();
  }
  
  // Set headers if first run
  if (sheet.getLastRow() === 0) {
    sheet.getRange(1, 1, 1, 6).setValues([[
      'Campaign Name', 'Status', 'Budget', 'Cost', 'Conversions', 'ROAS'
    ]]);
  }
  
  // Export campaign data
  const campaigns = AdsApp.campaigns().get();
  const data = [];
  
  while (campaigns.hasNext()) {
    const campaign = campaigns.next();
    const stats = campaign.getStatsFor('LAST_7_DAYS');
    
    data.push([
      campaign.getName(),
      campaign.isEnabled() ? 'Active' : 'Paused',
      campaign.getBudget(),
      stats.getCost(),
      stats.getConversions(),
      stats.getConversions() > 0 ? stats.getConversionValue() / stats.getCost() : 0
    ]);
  }
  
  // Write data to sheet
  if (data.length > 0) {
    sheet.getRange(2, 1, data.length, 6).setValues(data);
  }
  
  Logger.log(`Exported ${data.length} campaigns to Google Sheets`);
}

This example shows how to export campaign performance data to a Google Sheet for analysis and reporting.

Dynamic Configuration from Sheets
// Read configuration from Google Sheets
function getConfigFromSheet() {
  const CONFIG_SHEET_URL = 'https://docs.google.com/spreadsheets/d/YOUR_CONFIG_SHEET_ID/edit';
  const sheet = SpreadsheetApp.openByUrl(CONFIG_SHEET_URL).getSheetByName('Config');
  
  const config = {};
  const data = sheet.getDataRange().getValues();
  
  // Convert sheet data to config object
  for (let i = 1; i < data.length; i++) {
    const key = data[i][0];
    const value = data[i][1];
    config[key] = value;
  }
  
  return config;
}

function main() {
  // Load dynamic configuration
  const config = getConfigFromSheet();
  
  const TARGET_ROAS = config.targetRoas || 3.0;
  const MAX_BUDGET_INCREASE = config.maxBudgetIncrease || 0.2;
  const MIN_CONVERSIONS = config.minConversions || 5;
  
  Logger.log(`Using config: ROAS=${TARGET_ROAS}, Budget=${MAX_BUDGET_INCREASE}, Min Conv=${MIN_CONVERSIONS}`);
  
  // Use configuration in optimization logic
  const campaigns = AdsApp.campaigns()
    .withCondition('Status = ENABLED')
    .withCondition(`Conversions >= ${MIN_CONVERSIONS} DURING LAST_30_DAYS`)
    .get();
    
  while (campaigns.hasNext()) {
    const campaign = campaigns.next();
    const stats = campaign.getStatsFor('LAST_30_DAYS');
    const roas = stats.getConversionValue() / stats.getCost();
    
    if (roas >= TARGET_ROAS) {
      const currentBudget = campaign.getBudget();
      const newBudget = currentBudget * (1 + MAX_BUDGET_INCREASE);
      
      campaign.setBudget(newBudget);
      Logger.log(`Increased budget for ${campaign.getName()}: €${currentBudget} → €${newBudget}`);
    }
  }
}

💡 Sheet Configuration Format

Create a "Config" sheet with two columns: "Setting" and "Value"

SettingValue
targetRoas3.5
maxBudgetIncrease0.25
minConversions10
Advanced Features

📊 Automated Reporting

  • • Daily performance summaries
  • • Weekly trend analysis
  • • Monthly client reports
  • • Alert notifications in sheets

🔄 Data Synchronization

  • • Bidirectional data sync
  • • Real-time configuration updates
  • • Batch data processing
  • • Error handling and recovery

⚠️ Best Practices

  • • Use specific sheet URLs instead of file names
  • • Implement error handling for missing sheets/ranges
  • • Cache frequently accessed data to improve performance
  • • Validate data types and ranges before processing
  • • Set up proper sharing permissions for automated access