// ========================================== // CONVERSION NUDGES - JAVASCRIPT IMPLEMENTATION // ========================================== // Track user behavior let contactsUsed = 0; let contactLimit = 9; // Free plan limit let daysRemaining = 30; let userPlan = 'free'; // free, starter, prime, elite, trust // ========================================== // NUDGE 1: CONTACT LIMIT REACHED // ========================================== function showContactLimitNudge() { const modal = `
⚠️

You've reached your free contact limit (9/9)

You're browsing like a pro! Ready to unlock more options?

Contact 25 more owners (not just 9)
See new listings 24 hours earlier
Get automated alerts via SMS/Email

💡 That's just ₹36/day to find your dream home faster.

`; document.body.insertAdjacentHTML('beforeend', modal); } // Trigger when user tries to contact 10th owner function attemptContact(propertyId) { contactsUsed++; if (userPlan === 'free' && contactsUsed >= contactLimit) { showContactLimitNudge(); return false; // Block the contact } // Allow contact return true; } // ========================================== // NUDGE 2: EXPIRY WARNING (DAY 25) // ========================================== function showExpiryWarningNudge() { const savedProperties = [ { name: '2BHK in Adyar', price: '₹65L' }, { name: 'Villa in ECR', price: '₹1.2Cr' }, { name: 'Flat in OMR', price: '₹45L' } ]; const propertiesList = savedProperties.map(p => `
  • • ${p.name} - ${p.price}
  • ` ).join(''); const modal = `

    Your Free Plan Expires in 5 Days

    Don't lose access to these properties you saved:

    Upgrade to Starter Spark for ₹1,075

    ✓ Keep your leads coming for 30 more days
    ✓ 2x more visibility on your listing
    ✓ Never miss a new property again
    ⚡ Special Offer: Upgrade now, get 5 extra days FREE
    `; document.body.insertAdjacentHTML('beforeend', modal); } // Check on page load if user is on Day 25+ function checkExpiryStatus() { const accountCreatedDate = new Date(localStorage.getItem('accountCreated')); const today = new Date(); const daysElapsed = Math.floor((today - accountCreatedDate) / (1000 * 60 * 60 * 24)); if (userPlan === 'free' && daysElapsed >= 25 && !localStorage.getItem('expiryNudgeShown')) { setTimeout(() => { showExpiryWarningNudge(); localStorage.setItem('expiryNudgeShown', 'true'); }, 3000); // Show after 3 seconds on page } } // ========================================== // NUDGE 3: FEATURE TEASE (NEW LISTINGS) // ========================================== function showFeatureTeaseNudge(hiddenCount = 3) { const modal = `
    🔒

    ${hiddenCount} New Properties Match Your Search

    But they're only visible to Starter Spark members...

    🏠
    3BHK Villa, Adyar
    Posted 2 hours ago
    🏢
    2BHK Flat, OMR
    20% below market rate
    🏰
    Penthouse, ECR
    Owner leaving next week

    These properties won't last long. Upgrade to see them before they're gone.

    💡 Free users see listings 24 hours late. Spark members see them first.

    `; document.body.insertAdjacentHTML('beforeend', modal); } // Show feature tease after user searches 3+ times let searchCount = 0; function trackSearch() { searchCount++; if (userPlan === 'free' && searchCount >= 3 && !sessionStorage.getItem('featureTeaseShown')) { showFeatureTeaseNudge(); sessionStorage.setItem('featureTeaseShown', 'true'); } } // ========================================== // UTILITY FUNCTIONS // ========================================== function closeNudgeModal(modalId) { const modal = document.getElementById(modalId); if (modal) { modal.style.animation = 'fadeOut 0.3s ease'; setTimeout(() => modal.remove(), 300); } } function upgradeToStarterSpark() { // Track conversion trackConversionEvent('upgrade_nudge_clicked', 'starter_spark'); // Redirect to pricing page with pre-selected plan window.location.href = '/pricing?plan=starter_spark&source=nudge'; } function trackConversionEvent(eventName, planName) { // Send to analytics if (typeof gtag !== 'undefined') { gtag('event', eventName, { 'plan_name': planName, 'user_plan': userPlan, 'contacts_used': contactsUsed }); } // Log to console for debugging console.log(`Conversion Event: ${eventName} - ${planName}`); } // ========================================== // DASHBOARD WIDGET: BOOST YOUR LISTING // ========================================== function showBoostWidget() { const views = Math.floor(Math.random() * 100) + 20; // Simulate views const widget = `

    🚀 BOOST YOUR LISTING

    Your listing has ${views} views.
    Properties with videos get 3.5x more.

    `; const dashboardContainer = document.getElementById('dashboardWidgets'); if (dashboardContainer) { dashboardContainer.insertAdjacentHTML('beforeend', widget); } } // ========================================== // EMAIL TRIGGER SYSTEM // ========================================== async function sendExpiryReminderEmail(userId, daysRemaining) { const emailData = { to: getUserEmail(userId), subject: daysRemaining === 5 ? '⏰ Your PrimeSquare listing expires in 5 days' : '⚠️ Last Day: Your PrimeSquare access expires tonight', template: daysRemaining === 5 ? 'day_25_reminder' : 'day_30_final', data: { userName: getUserName(userId), expiryDate: getExpiryDate(userId), savedPropertiesCount: getSavedPropertiesCount(userId), viewsCount: getListingViews(userId), contactsReceived: getContactsReceived(userId) } }; try { const response = await fetch('/api/send_email.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(emailData) }); const result = await response.json(); console.log('Email sent:', result); } catch (error) { console.error('Email send failed:', error); } } // Cron job should call this daily async function checkAndSendExpiryReminders() { const usersToNotify = await getUsersNearingExpiry(); // Backend query for (const user of usersToNotify) { if (user.daysRemaining === 5) { sendExpiryReminderEmail(user.id, 5); sendExpiryReminderWhatsApp(user.id, 5); } else if (user.daysRemaining === 0) { sendExpiryReminderEmail(user.id, 0); } } } // ========================================== // INITIALIZATION // ========================================== document.addEventListener('DOMContentLoaded', function() { // Check if user needs to see expiry warning checkExpiryStatus(); // Show boost widget on dashboard if (window.location.pathname.includes('/dashboard')) { showBoostWidget(); } // Track searches const searchForm = document.getElementById('propertySearchForm'); if (searchForm) { searchForm.addEventListener('submit', trackSearch); } }); // ========================================== // CSS STYLES FOR NUDGE MODALS // ========================================== const nudgeStyles = ` `; // Inject styles document.head.insertAdjacentHTML('beforeend', nudgeStyles);