// Google Sheets Setup Instructions // // Follow these steps to set up Google Sheets integration: export const GOOGLE_APPS_SCRIPT_CODE = ` function doPost(e) { try { // Check if e exists and has postData if (!e || !e.postData || !e.postData.contents) { throw new Error("Invalid request format - missing postData"); } console.log('Received POST request'); // Get the active spreadsheet and the first sheet const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); // Parse the incoming data const data = JSON.parse(e.postData.contents); console.log('Parsed data:', JSON.stringify(data)); // Add a new row with the data in the correct order const newRow = [ data.email || '', data.packageType || '', data.timestamp || new Date().toISOString(), data.source || '' ]; console.log('Adding row:', newRow); sheet.appendRow(newRow); console.log('Row added successfully'); return ContentService .createTextOutput(JSON.stringify({ success: true, message: 'Email added successfully' })) .setMimeType(ContentService.MimeType.JSON); } catch (error) { console.error('Error in doPost:', error); return ContentService .createTextOutput(JSON.stringify({ error: error.toString(), message: 'Failed to add email' })) .setMimeType(ContentService.MimeType.JSON); } } // IMPORTANT: Don't run doPost directly - use this test function instead function testDoPost() { // Create a mock event object that simulates a POST request const mockEvent = { postData: { contents: JSON.stringify({ email: 'test@example.com', packageType: 'starter-kit', timestamp: new Date().toISOString(), source: 'test' }) } }; // Call doPost with the mock event const result = doPost(mockEvent); console.log('Test result:', result.getContent()); } // Simple function to manually add a test row function addTestRow() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); sheet.appendRow([ 'test@example.com', 'starter-kit', new Date().toISOString(), 'manual-test' ]); console.log('Test row added manually'); } ` export const setupInstructions = ` DETAILED Setup Instructions for Google Sheets Integration: 1. CREATE GOOGLE SHEET: - Go to sheets.google.com - Create a new sheet - Make sure the first sheet is named "Sheet1" (check the tab at the bottom) - Add these exact headers in row 1: A1: Email B1: Package Type C1: Timestamp D1: Source 2. CREATE GOOGLE APPS SCRIPT: - Go to script.google.com - Click "New Project" - Replace ALL the default code with the provided script - Save the project (Ctrl+S) 3. TEST THE SCRIPT: - IMPORTANT: Don't run doPost directly - Instead, run the "testDoPost" function - Or run the "addTestRow" function to manually add a test row - Check if a test row appears in your Google Sheet 4. DEPLOY THE SCRIPT: - Click "Deploy" button (top right) - Click "New deployment" - Click the gear icon next to "Type" and select "Web app" - Set "Execute as" to "Me (your email)" - Set "Who has access" to "Anyone" - Click "Deploy" - Click "Authorize access" and go through Google's permission flow - Copy the "Web app URL" (it should end with /exec) 5. UPDATE ENVIRONMENT VARIABLE: - Make sure your GOOGLE_SHEETS_WEBHOOK_URL in Vercel matches the Web app URL exactly TROUBLESHOOTING: - Don't run doPost directly - use testDoPost instead - Make sure your sheet is named "Sheet1" (case sensitive) - Check that your headers match exactly - After deployment, make sure to authorize the app - The Web app URL must end with /exec `