Skip to content
Case Studies
Home Case Studies
// Primansh Lead Capture Script for Custom Forms
// Version: 1.0.0
// Place this script in your custom website or form handler
// Configuration - REPLACE WITH YOUR ACTUAL CLIENT ID
const CLIENT_ID = '71452776-abef-4ebd-b581-e3e51f553d53'; // This is pre-filled with your client's ID
const WEBHOOK_URL = 'https://tpeskbbvrfebtjiituwi.supabase.co/functions/v1/process-webhook';
// Helper function to normalize form values
function normalizeValue(value) {
if (value === null || value === undefined) return '';
if (typeof value === 'string') return value.trim();
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
return String(value);
}
// Handle form submission
async function handleFormSubmit(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
// Convert FormData to object
const data = {};
formData.forEach((value, key) => {
data[key] = normalizeValue(value);
});
// Prepare lead data
const leadData = {
client_id: CLIENT_ID,
source: 'website',
status: 'new',
...data
};
// Add common field mappings if they exist
const fieldMappings = {
name: ['name', 'fullname', 'full_name', 'your-name', 'fname', 'firstname'],
email: ['email', 'e-mail', 'your-email', 'emailaddress'],
phone: ['phone', 'telephone', 'tel', 'mobile', 'your-phone', 'whatsapp'],
notes: ['message', 'comments', 'comment', 'notes', 'requirement', 'description'],
service: ['service', 'services', 'subject', 'inquiry-type', 'interest'],
firm_name: ['firm_name', 'firm name', 'company', 'company name', 'business name'],
budget: ['budget', 'estimated-budget', 'estimated budget', 'project-budget']
};
// Apply field mappings
Object.keys(fieldMappings).forEach((leadField) => {
const possibleFields = fieldMappings[leadField];
for (const field of possibleFields) {
if (data[field] !== undefined && data[field] !== '') {
leadData[leadField] = data[field];
break;
}
}
});
// Submit to webhook
try {
const response = await fetch(`${WEBHOOK_URL}?client_id=${encodeURIComponent(CLIENT_ID)}`, {
method: 'POST',
body: new URLSearchParams(leadData)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
console.log('Primansh lead capture success:', result);
return { success: true, data: result };
} catch (error) {
console.error('Primansh lead capture error:', error);
return { success: false, error: error.message };
}
}
// Export for use in form handlers
window.PrimanshLeadCapture = { handleFormSubmit };