diff --git a/components/GoogleAdsGenerator.tsx b/components/GoogleAdsGenerator.tsx index c999bb0..284c124 100644 --- a/components/GoogleAdsGenerator.tsx +++ b/components/GoogleAdsGenerator.tsx @@ -307,37 +307,81 @@ export default function GoogleAdsGenerator() { const exportCSV = () => { if (!googleAdsResult && !magicWandResult) return; - let csvContent = "data:text/csv;charset=utf-8,"; + let rows: string[][] = []; if (googleAdsResult) { - // Keywords section - csvContent += "KEYWORDS RESEARCH\n"; - csvContent += "Type,Keyword,CPC\n"; - googleAdsResult.keywords?.primary?.forEach(k => { - csvContent += `Primary,"${k.keyword}","${k.cpc || 'N/A'}"\n`; - }); - googleAdsResult.keywords?.longTail?.forEach(k => { - csvContent += `Long-tail,"${k.keyword}","${k.cpc || 'N/A'}"\n`; - }); - googleAdsResult.keywords?.negative?.forEach(k => { - csvContent += `Negative,"${k.keyword}",""\n`; - }); + // Keywords + rows.push(["KEYWORDS RESEARCH"]); + rows.push(["Type", "Keyword", "CPC"]); + const addKw = (type: string, list?: any[]) => { + if (list) list.forEach(k => rows.push([type, k.keyword, k.cpc || 'N/A'])); + }; + addKw("Primary", googleAdsResult.keywords?.primary); + addKw("Long-tail", googleAdsResult.keywords?.longTail); + addKw("Negative", googleAdsResult.keywords?.negative); + rows.push([]); - // Ad Copies section - csvContent += "\nAD COPIES\n"; - csvContent += "Headlines,Descriptions,CTA\n"; + // Ad Copies + rows.push(["AD COPIES"]); + rows.push(["Headlines", "Descriptions", "CTA"]); googleAdsResult.adCopies?.forEach(ad => { - csvContent += `"${ad.headlines?.join(' | ') || ''}","${ad.descriptions?.join(' | ') || ''}","${ad.callToAction || ''}"\n`; + rows.push([ + ad.headlines?.join(' | ') || '', + ad.descriptions?.join(' | ') || '', + ad.callToAction || '' + ]); }); + rows.push([]); + + // Campaigns + rows.push(["CAMPAIGN STRUCTURE"]); + rows.push(["Name", "Type", "Budget", "Locations", "Schedule"]); + googleAdsResult.campaigns?.forEach(c => { + rows.push([ + c.name, + c.type, + `${c.budget?.daily || 0} ${c.budget?.currency}`, + c.targeting?.locations?.join('; ') || 'All', + c.targeting?.schedule?.join('; ') || 'All' + ]); + }); + rows.push([]); + + // Implementation + rows.push(["IMPLEMENTATION GUIDE"]); + const impl = googleAdsResult.implementation; + if (impl) { + rows.push(["Setup Steps", impl.setupSteps?.join('; ') || '']); + rows.push(["Quality Score Tips", impl.qualityScoreTips?.join('; ') || '']); + rows.push(["Optimization Tips", impl.optimizationTips?.join('; ') || '']); + } + rows.push([]); + + // Predictions + if (googleAdsResult.predictions) { + rows.push(["PERFORMANCE PREDICTIONS"]); + const p = googleAdsResult.predictions; + rows.push(["Metric", "Estimate"]); + rows.push(["Clicks", p.estimatedClicks || "N/A"]); + rows.push(["Impressions", p.estimatedImpressions || "N/A"]); + rows.push(["CTR", p.estimatedCtr || "N/A"]); + rows.push(["Conversions", p.estimatedConversions || "N/A"]); + rows.push([]); + } } if (magicWandResult) { - csvContent += "\nMARKET ANALYSIS\n"; - csvContent += `Growth Rate,"${magicWandResult.marketAnalysis?.growthRate || 'N/A'}"\n`; - csvContent += `Top Competitors,"${magicWandResult.marketAnalysis?.topCompetitors?.join(', ') || 'N/A'}"\n`; - csvContent += `Market Trends,"${magicWandResult.marketAnalysis?.marketTrends?.join(', ') || 'N/A'}"\n`; + rows.push(["MARKET ANALYSIS"]); + const ma = magicWandResult.marketAnalysis; + rows.push(["Growth Rate", ma?.growthRate || 'N/A']); + rows.push(["Top Competitors", ma?.topCompetitors?.join('; ') || 'N/A']); + rows.push(["Market Trends", ma?.marketTrends?.join('; ') || 'N/A']); } + // CSV String Construction with proper escaping + const csvContent = "data:text/csv;charset=utf-8," + + rows.map(row => row.map(cell => `"${(cell || '').replace(/"/g, '""')}"`).join(",")).join("\n"); + const encodedUri = encodeURI(csvContent); const link = document.createElement("a"); link.setAttribute("href", encodedUri); @@ -350,85 +394,123 @@ export default function GoogleAdsGenerator() { const exportHTML = () => { if (!googleAdsResult && !magicWandResult) return; - let htmlContent = ` + let html = `
-Generated on ${new Date().toLocaleString()}
`; +Generated by PromptArch on ${new Date().toLocaleDateString()}
`; if (googleAdsResult) { // Keywords - if (googleAdsResult.keywords?.primary?.length) { - htmlContent += ` -${ad.descriptions?.[0] || ''}
- ${ad.callToAction ? `${ad.callToAction}` : ''} -${c.type.toUpperCase()} • ${c.budget.daily} ${c.budget.currency}/day
+Top Competitors: ${ma.topCompetitors.join(', ')}
` : ''} - ${ma?.marketTrends?.length ? `Market Trends: ${ma.marketTrends.join(', ')}
` : ''} -${magicWandResult.rationale}
+Growth Rate: ${magicWandResult.marketAnalysis?.growthRate || 'N/A'}
+