Digital Presence Audit — AJCPRELIGERA ');
pw.document.close();
pw.focus();
setTimeout(function(){pw.print();},500);
};function buildNotificationEmail(data, invNumber) {
var rows=Object.keys(data).map(function(k){return '
| '+k+' | '+data[k]+' |
';}).join('');
return '
| New '+AUDIT_CONFIG.eyebrow+' Request New brief from '+data['Name']+'Invoice: '+invNumber+' | Client Brief | | Reply to '+data['Name']+' |
|
';
}async function submitForm() {
btnNext.textContent='Generating invoice...';
btnNext.disabled=true;
document.getElementById('submitError').classList.remove('visible');var fname=document.getElementById('fname').value.trim(), lname=document.getElementById('lname').value.trim();
var email=document.getElementById('email').value.trim(), bizName=document.getElementById('biz_name').value.trim();
var bizInd=document.getElementById('biz_industry').value.trim(), bizStage=document.getElementById('biz_stage').value;
var websiteUrl=document.getElementById('website_url').value.trim(), instagram=document.getElementById('instagram').value.trim();
var otherPlat=document.getElementById('other_platforms').value.trim(), targetAud=document.getElementById('target_audience').value.trim();
var notWorking=document.getElementById('not_working').value.trim(), competitors=document.getElementById('competitors').value.trim();
var extraNotes=document.getElementById('extra_notes').value.trim(), referral=document.getElementById('referral').value;var focusAreasText=answers['focus_areas']?answers['focus_areas'].join(', '):'All areas';
var goalLabels={leads:'Understand why not generating leads',brand:'Improve brand online',gaps:'Identify gaps',strategy:'Get direction before full strategy'};
var auditGoal=goalLabels[answers['audit_goal']]||answers['audit_goal']||AUDIT_CONFIG.notionGoalFallback;var invNumber=generateInvoiceNumber(), now=new Date();
window._invoiceNumber=invNumber;
var validUntil=new Date(now); validUntil.setDate(validUntil.getDate()+14);var invoicePayload={
parent:{database_id:NOTION_INVOICE_DB_ID},
properties:{
'Title':{title:[{text:{content:fname+' '+lname}}]},
'Email':{email:email},
'USD':{number:AUDIT_CONFIG.price},
'Status':{select:{name:'Draft'}},
'Transaction Details':{rich_text:[{text:{content:AUDIT_CONFIG.invServiceName+' - '+invNumber}}]},
'URL for Receipt':{url:websiteUrl||null}
}
};var leadPayload={
parent:{database_id:NOTION_AUDIT_DB_ID},
properties:{
'Name':{title:[{text:{content:fname+' '+lname}}]},
'Email':{email:email},
'Business':{rich_text:[{text:{content:bizName+' - '+bizInd}}]},
'Industry':{rich_text:[{text:{content:bizInd}}]},
'Business Stage':{select:{name:bizStage||'Not specified'}},
'Website URL':{url:websiteUrl||null},
'Instagram':{rich_text:[{text:{content:instagram||''}}]},
'Other Platforms':{rich_text:[{text:{content:otherPlat||''}}]},
'Focus Areas':{rich_text:[{text:{content:focusAreasText}}]},
'Audit Goal':{select:{name:auditGoal}},
'Target Audience':{rich_text:[{text:{content:targetAud}}]},
'Not Working':{rich_text:[{text:{content:notWorking}}]},
'Competitors':{rich_text:[{text:{content:competitors||''}}]},
'How They Found Me':{select:{name:referral||'Not specified'}},
'Invoice Number':{rich_text:[{text:{content:invNumber}}]},
'Source':{select:{name:AUDIT_CONFIG.sourceLabel}},
'Notes':{rich_text:[{text:{content:extraNotes||''}}]},
'Status':{select:{name:'New Lead'}}
}
};var notifData={
'Name':fname+' '+lname, 'Email':email, 'Business':bizName+' - '+bizInd,
'Stage':bizStage||'', 'Website':websiteUrl, 'Instagram':instagram||'',
'Other':otherPlat||'', 'Focus Areas':focusAreasText, 'Goal':auditGoal,
'Not Working':notWorking, 'Audience':targetAud, 'Competitors':competitors||'',
'Found via':referral||'', 'Invoice':invNumber,
'Audit Type':AUDIT_CONFIG.eyebrow,
'Amount':'$'+AUDIT_CONFIG.price+' USD'
};try {
var notificationHtml=buildNotificationEmail(notifData, invNumber);const invoiceRes=await fetch('https://ajcpreligera.com/wp-admin/admin-ajax.php',{
method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'ajcp_brief_submit', client_name:fname, client_email:email,
your_email:YOUR_EMAIL, confirmation_html:'', notification_html:notificationHtml,
subject_client:'', subject_owner:'New '+AUDIT_CONFIG.eyebrow+': '+fname+' '+lname,
notion_token:NOTION_TOKEN_INVOICE, notion_database_id:NOTION_INVOICE_DB_ID,
notion_payload:JSON.stringify(invoicePayload)
})
});
var invoiceData=await invoiceRes.json();// Show success
document.querySelectorAll('.step').forEach(function(s){s.classList.remove('active');});
document.getElementById('formNav').style.display='none';
progressFill.style.width='100%';
progressCount.textContent='Complete';
document.getElementById('successName').textContent=fname;
document.getElementById('invNumber').textContent='Generating...';
document.getElementById('invReference').textContent='Generating...';
document.getElementById('invDate').textContent='Issued: '+formatDate(now)+' | Due: '+formatDueDate(now);
document.getElementById('invClientName').textContent=fname+' '+lname;
document.getElementById('invClientDetail').textContent=bizName+'\n'+email;
document.getElementById('invClientDetail').style.whiteSpace='pre-line';
document.getElementById('invEmailRef').textContent=email;
document.getElementById('invValidUntil').textContent=formatDate(validUntil);
document.getElementById('successScreen').classList.add('active');// GTM dataLayer push
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'form_website_brand_audit',
form_name: 'Website and Brand Audit Form',
user_email: email || ''
});
var c=document.querySelector('.form-card'); if(c) c.scrollIntoView({behavior:'smooth',block:'start'});// Wait then read back invoice number
await new Promise(function(resolve){setTimeout(resolve,3000);});
const readRes=await fetch('https://ajcpreligera.com/wp-admin/admin-ajax.php',{
method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'ajcp_notion_read', notion_token:NOTION_TOKEN_INVOICE,
page_id:invoiceData.data&&invoiceData.data.page_id?invoiceData.data.page_id:''
})
});
var readData=await readRes.json();
var finalInvNumber=(readData&&readData.invoice_number)?readData.invoice_number:invNumber;
window._invoiceNumber=finalInvNumber;
document.getElementById('invNumber').textContent=finalInvNumber;
document.getElementById('invReference').textContent=finalInvNumber;// Save to audit leads DB
await fetch('https://ajcpreligera.com/wp-admin/admin-ajax.php',{
method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'ajcp_brief_submit', client_name:fname, client_email:email,
your_email:YOUR_EMAIL, confirmation_html:'', notification_html:'',
subject_client:'', subject_owner:'',
notion_token:NOTION_TOKEN_AUDIT, notion_database_id:NOTION_AUDIT_DB_ID,
notion_payload:JSON.stringify(leadPayload)
})
});// Save to Client List DB
var clientPayload = {
parent: { database_id: NOTION_CLIENT_DB_ID },
properties: {
'Name': { title: [{ text: { content: fname + ' ' + lname } }] },
'Email': { email: email },
'Client Status': { select: { name: 'New Lead' } },
'Industry': { rich_text: [{ text: { content: bizInd } }] },
'Website': { url: websiteUrl || null },
'Service': { multi_select: [{ name: AUDIT_CONFIG.invServiceName }] },
'How They Found Me': { select: { name: referral || 'Other' } },
'Notes': { rich_text: [{ text: { content: 'Invoice: ' + finalInvNumber + '\nBusiness: ' + bizName + (extraNotes ? '\n' + extraNotes : '') } }] }
}
};await fetch('https://ajcpreligera.com/wp-admin/admin-ajax.php',{
method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'ajcp_brief_submit', client_name:fname, client_email:email,
your_email:YOUR_EMAIL, confirmation_html:'', notification_html:'',
subject_client:'', subject_owner:'',
notion_token:NOTION_TOKEN_CLIENT, notion_database_id:NOTION_CLIENT_DB_ID,
notion_payload:JSON.stringify(clientPayload)
})
});} catch(err) {
console.error(err);
btnNext.textContent='Submit & Generate Invoice →';
btnNext.disabled=false;
document.getElementById('submitError').classList.add('visible');
}
}// ── Hide irrelevant fields for website audit ─────────────────
if (isWebsiteAudit) {
document.getElementById('focusAreasSection').style.display = 'none';
// Pre-set focus areas to website only
answers['focus_areas'] = ['website'];
}showStep(1);