CTA Optimization Tool

CTA Optimization Tool

Generate and analyze high-impact Call-to-Action text with AI.

CTA Details

Generated CTA Variations

Your AI-generated CTA ideas will appear here.

AI is crafting your CTAs...

`; const systemPrompt = "You are a conversion-focused copywriter. Your task is to generate 4-5 compelling Call-to-Action (CTA) text variations based on the user's input. For each CTA, provide a brief rationale explaining why it works. Respond only with a valid JSON object matching the provided schema."; const userPrompt = `Original CTA: "${inputsData.ctaText}", Goal: "${inputsData.goal}", Context: "${inputsData.context}"`; const jsonSchema = { type: "OBJECT", properties: { cta_variations: { type: "ARRAY", items: { type: "OBJECT", properties: { text: { type: "STRING" }, rationale: { type: "STRING" } }, required: ["text", "rationale"] } } }, required: ["cta_variations"] }; const apiKey = ""; const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const payload = { contents: [{ parts: [{ text: userPrompt }] }], systemInstruction: { parts: [{ text: systemPrompt }] }, generationConfig: { responseMimeType: "application/json", responseSchema: jsonSchema } }; try { const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) throw new Error(`API Error: ${response.statusText}`); const result = await response.json(); const aiResult = JSON.parse(result.candidates?.[0]?.content?.parts?.[0]?.text); if (aiResult.cta_variations && aiResult.cta_variations.length > 0) { generatedCtas = aiResult.cta_variations; renderCtas(); } else { throw new Error("No CTA variations were generated."); } } catch (error) { console.error("Content generation error:", error); resultsContainer.innerHTML = `

An error occurred: ${error.message}

`; } finally { generateBtn.disabled = false; generateBtn.textContent = 'Generate Variations'; } } function renderCtas() { resultsContainer.innerHTML = generatedCtas.map((cta, index) => `

${cta.text}

Rationale: ${cta.rationale}

`).join(''); } // --- UTILITY FUNCTIONS --- function showNotification(message) { notification.textContent = message; notification.classList.remove('opacity-0'); setTimeout(() => notification.classList.add('opacity-0'), 2000); } function copyToClipboard(text, message) { navigator.clipboard.writeText(text).then(() => showNotification(message)); } // --- PDF GENERATION --- async function generatePdfReport() { if (generatedCtas.length === 0) { showNotification("No CTAs to export."); return; } downloadPdfBtn.disabled = true; downloadPdfBtn.textContent = '...'; const ctaCards = generatedCtas.map(cta => `
${cta.text}

Rationale: ${cta.rationale}

`).join(''); const reportHtml = `

Conversion Strategy Brief

For CTA: ${inputsData.ctaText}

Campaign Goal & Audience

Goal: ${inputsData.goal}
Audience: ${inputsData.context}

Generated CTA Variations
${ctaCards}
`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`CTA_Variations_${inputsData.ctaText.replace(/\s+/g, '_')}.pdf`); } catch (e) { console.error('PDF Generation Error:', e); } finally { downloadPdfBtn.disabled = false; downloadPdfBtn.textContent = 'Download PDF'; pdfTemplate.classList.add('invisible'); pdfTemplate.innerHTML = ''; } } // --- EVENT LISTENERS --- generateBtn.addEventListener('click', generateCtas); resultsContainer.addEventListener('click', (e) => { if (e.target.classList.contains('copy-cta-btn')) { const text = generatedCtas[e.target.dataset.index].text; copyToClipboard(text, 'CTA copied!'); } }); downloadPdfBtn.addEventListener('click', generatePdfReport); });
Scroll to Top