„`html
Danke.
Deine Antworten sind angekommen. Devin liest sie sich persönlich durch und meldet sich in den nächsten Tagen bei dir, wenn er glaubt, dass er dir wirklich weiterhelfen kann.
const QUESTIONS=[
{id:"q1",type:"checkbox",required:true,title:"Wo stehst du gerade in deinem Leben?",hint:"Mehrfachauswahl möglich.",options:["Ich funktioniere nur noch","Ich bin innerlich oft leer oder erschöpft","Beziehung läuft nicht so, wie ich will","Ich habe keine klare Richtung","Ich weiß eigentlich, was zu tun ist – mache es aber nicht"]},
{id:"q2",type:"radio",required:true,title:"Was belastet dich aktuell am meisten?",options:["Innere Unruhe / Stress / Überforderung","Konflikte in Beziehung / fehlende Nähe","Fehlende Klarheit / Orientierung","Alte Muster / Trigger / emotionale Reaktionen","Gefühl, nicht ich selbst zu sein"]},
{id:"q3",type:"textarea",required:true,title:"Was ist gerade dein größtes Problem – wenn du ehrlich bist?",placeholder:"Schreib es einfach so, wie es dir in den Kopf kommt …"},
{id:"q4",type:"radio",required:true,title:"Was hast du bisher versucht, um das zu verändern?",options:["Viel nachgedacht / analysiert","Podcasts / Bücher / Wissen","Sport / Ablenkung","Gespräche mit Freunden","Therapie / Coaching","Nichts"]},
{id:"q5",type:"textarea",required:false,title:"Was hat bisher nicht funktioniert?",hint:"Optional – aber sehr hilfreich für Devin.",placeholder:"Erzähl kurz davon …"},
{id:"q6",type:"textarea",required:true,title:"Stell dir vor, das Thema wäre gelöst …",hint:"Wie würde dein Leben aussehen?",placeholder:"Beschreib es in deinen eigenen Worten …"},
{id:"q7",type:"radio",required:true,title:"Wenn sich das wirklich verändern lässt – wie viel Zeit wärst du bereit zu investieren?",options:["1–2 Stunden pro Woche","3–5 Stunden pro Woche","So viel wie nötig"]},
{id:"q8",type:"radio",required:true,title:"Wie viel wärst du bereit zu investieren, um das wirklich zu verändern?",options:["Unter 500€","500€ – 1.000€","Über 1.000€","Wenn es passt, offen nach oben."]},
{id:"contact",type:"contact",required:true,title:"Fast geschafft.",hint:"Devin liest jede Antwort persönlich. Wenn er glaubt, dass er dir wirklich weiterhelfen kann, meldet er sich persönlich bei dir. Dafür braucht er nur deine Telefonnummer."}
];
let current=0,surveyStarted=false,leadFired=false;
const firedSteps=new Set();
const stepsEl=document.getElementById("yvSteps");
const errorEl=document.getElementById("yvError");
const backBtn=document.getElementById("yvBack");
const nextBtn=document.getElementById("yvNext");
const progressFill=document.getElementById("yvProgressFill");
const stepLabel=document.getElementById("yvStepLabel");
const surveyCard=document.querySelector(".yv-card");
const successEl=document.getElementById("yvSuccess");
function fbqSafe(){if(typeof window.fbq==="function"){window.fbq.apply(window,arguments);}}
function generateEventId(){return window.crypto&&crypto.randomUUID?"yv_"+crypto.randomUUID():"yv_"+Date.now()+"_"+Math.random().toString(36).slice(2);}
function markSurveyStarted(){if(surveyStarted)return;surveyStarted=true;fbqSafe("trackCustom","SurveyStart",{survey:SURVEY_NAME});}
function trackStepComplete(n){if(firedSteps.has(n))return;firedSteps.add(n);fbqSafe("trackCustom","SurveyStep"+n,{survey:SURVEY_NAME,step:n});}
function trackCompletion(eventId){if(leadFired)return;leadFired=true;fbqSafe("trackCustom","SurveyComplete",{survey:SURVEY_NAME});fbqSafe("track","Lead",{survey:SURVEY_NAME},{eventID:eventId});}
function escapeHtml(str){return String(str).replace(/[&<>"']/g,m=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[m]));}
function renderOptions(q,type){
return q.options.map((opt,i)=>`
`).join("");
}
function renderStep(q){
if(q.type==="checkbox")return `
`;
if(q.type==="radio")return `
`;
if(q.type==="textarea")return ``;
if(q.type==="contact")return `
`;
return "";
}
function buildAllSteps(){
stepsEl.innerHTML=QUESTIONS.map((q,i)=>`
${escapeHtml(q.title)}
${q.hint?`
${escapeHtml(q.hint)}
`:""}
${renderStep(q)}
`).join("");
stepsEl.querySelectorAll(".yv-option").forEach(label=>{
const input=label.querySelector("input");
input.addEventListener("change",()=>{
if(input.type==="radio"){
label.closest(".yv-options").querySelectorAll(".yv-option").forEach(o=>o.classList.remove("is-selected"));
}
label.classList.toggle("is-selected",input.checked);
});
});
}
function showStep(idx){
stepsEl.querySelectorAll(".yv-step").forEach(s=>s.classList.remove("active"));
const stepEl=stepsEl.querySelector(`.yv-step[data-step="${idx}"]`);
stepEl.classList.add("active");
errorEl.classList.remove("show");
progressFill.style.width=Math.round(((idx+1)/QUESTIONS.length)*100)+"%";
stepLabel.textContent=`Schritt ${idx+1} von ${QUESTIONS.length}`;
backBtn.classList.toggle("is-hidden",idx===0);
nextBtn.textContent=idx===QUESTIONS.length-1?"Antworten an Devin senden":"Weiter";
}
function validateStep(idx){
const q=QUESTIONS[idx],stepEl=stepsEl.querySelector(`.yv-step[data-step="${idx}"]`);
if(!q.required)return true;
if(q.type==="checkbox"&&!stepEl.querySelector('input[type="checkbox"]:checked'))return "Bitte wähle mindestens eine Option aus.";
if(q.type==="radio"&&!stepEl.querySelector('input[type="radio"]:checked'))return "Bitte wähle eine Option aus.";
if(q.type==="textarea"&&!stepEl.querySelector("textarea").value.trim())return "Bitte fülle dieses Feld aus.";
if(q.type==="contact"&&!stepEl.querySelector("#yv_phone").value.trim())return "Bitte gib deine Telefonnummer an.";
return true;
}
function collectAnswers(){
const data={};
QUESTIONS.forEach(q=>{
if(q.type==="checkbox")data[q.id]=Array.from(stepsEl.querySelectorAll(`input[name="${q.id}"]:checked`)).map(i=>i.value).join("; ");
else if(q.type==="radio"){const sel=stepsEl.querySelector(`input[name="${q.id}"]:checked`);data[q.id]=sel?sel.value:"";}
else if(q.type==="textarea")data[q.id]=stepsEl.querySelector(`textarea[name="${q.id}"]`).value.trim();
else if(q.type==="contact"){data.name=stepsEl.querySelector("#yv_name").value.trim();data.phone=stepsEl.querySelector("#yv_phone").value.trim();}
});
return data;
}
function showSuccess(name){
surveyCard.style.display="none";
document.getElementById("yvNameEcho").textContent=name?", "+name:"";
successEl.classList.add("show");
}
function submitSurvey(){
const payload=collectAnswers();
const hp=stepsEl.querySelector('input[name="yv_hp"]');
if(hp&&hp.value){showSuccess(payload.name);return;}
nextBtn.disabled=true;
nextBtn.textContent="Wird gesendet …";
const eventId=generateEventId();
fetch(GOOGLE_SCRIPT_URL,{
method:"POST",
mode:"no-cors",
headers:{"Content-Type":"text/plain;charset=utf-8"},
body:JSON.stringify(payload)
}).then(()=>{
trackCompletion(eventId);
showSuccess(payload.name);
}).catch(()=>{
errorEl.textContent="Da ist etwas schiefgelaufen. Bitte versuch es nochmal.";
errorEl.classList.add("show");
nextBtn.disabled=false;
nextBtn.textContent="Antworten an Devin senden";
});
}
nextBtn.addEventListener("click",()=>{
markSurveyStarted();
const result=validateStep(current);
if(result!==true){errorEl.textContent=result;errorEl.classList.add("show");return;}
if(current===QUESTIONS.length-1){submitSurvey();return;}
trackStepComplete(current+1);
current++;
showStep(current);
});
backBtn.addEventListener("click",()=>{if(current===0)return;current--;showStep(current);});
stepsEl.addEventListener("input",markSurveyStarted);
stepsEl.addEventListener("change",markSurveyStarted);
buildAllSteps();
showStep(0);
})();
„`