Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Email Automation Dashboard - Lead Qualification</title> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> | |
<style> | |
.dashboard-card { | |
border: none; | |
border-radius: 15px; | |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
transition: transform 0.3s ease; | |
} | |
.dashboard-card:hover { | |
transform: translateY(-5px); | |
} | |
.email-type-card { | |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
color: white; | |
} | |
.new-properties-card { | |
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); | |
color: white; | |
} | |
.ai-recommendations-card { | |
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); | |
color: white; | |
} | |
.peak-time-card { | |
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); | |
color: white; | |
} | |
.status-indicator { | |
width: 12px; | |
height: 12px; | |
border-radius: 50%; | |
display: inline-block; | |
margin-right: 8px; | |
} | |
.status-success { background-color: #28a745; } | |
.status-warning { background-color: #ffc107; } | |
.status-error { background-color: #dc3545; } | |
.email-preview { | |
background-color: #f8f9fa; | |
border-radius: 10px; | |
padding: 20px; | |
margin-top: 20px; | |
font-family: 'Courier New', monospace; | |
font-size: 14px; | |
white-space: pre-line; | |
} | |
.customer-selector { | |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
color: white; | |
border-radius: 15px; | |
padding: 20px; | |
margin-bottom: 30px; | |
} | |
.btn-email-action { | |
border-radius: 25px; | |
padding: 10px 25px; | |
font-weight: 600; | |
text-transform: uppercase; | |
letter-spacing: 1px; | |
} | |
.analytics-chart { | |
background: white; | |
border-radius: 15px; | |
padding: 20px; | |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<!-- Header --> | |
<div class="row mb-4"> | |
<div class="col-12"> | |
<div class="customer-selector"> | |
<h2><i class="fas fa-envelope-open-text"></i> Email Automation Dashboard</h2> | |
<p class="mb-0">AI-Powered Email System Based on User Tracking Analysis</p> | |
</div> | |
</div> | |
</div> | |
<!-- Customer Selection --> | |
<div class="row mb-4"> | |
<div class="col-md-6"> | |
<div class="card dashboard-card"> | |
<div class="card-body"> | |
<h5 class="card-title"><i class="fas fa-user"></i> Select Customer</h5> | |
<div class="mb-3"> | |
<label for="customerId" class="form-label">Customer ID</label> | |
<input type="number" class="form-control" id="customerId" placeholder="Enter Customer ID" value="12345"> | |
</div> | |
<div class="mb-3"> | |
<label for="customerEmail" class="form-label">Email Address</label> | |
<input type="email" class="form-control" id="customerEmail" placeholder="[email protected]" value="[email protected]"> | |
</div> | |
<button class="btn btn-primary btn-email-action" onclick="loadCustomerData()"> | |
<i class="fas fa-search"></i> Load Customer Data | |
</button> | |
</div> | |
</div> | |
</div> | |
<div class="col-md-6"> | |
<div class="card dashboard-card"> | |
<div class="card-body"> | |
<h5 class="card-title"><i class="fas fa-chart-line"></i> Customer Analytics</h5> | |
<div id="customerAnalytics"> | |
<p class="text-muted">Select a customer to view analytics</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Email Types --> | |
<div class="row mb-4"> | |
<div class="col-12"> | |
<h4><i class="fas fa-envelope"></i> Email Automation Types</h4> | |
</div> | |
</div> | |
<div class="row mb-4"> | |
<!-- New Properties Email --> | |
<div class="col-md-4 mb-3"> | |
<div class="card dashboard-card new-properties-card"> | |
<div class="card-body text-center"> | |
<i class="fas fa-home fa-3x mb-3"></i> | |
<h5 class="card-title">New Properties Alert</h5> | |
<p class="card-text">Send notifications about newly added properties that match user preferences</p> | |
<button class="btn btn-light btn-email-action" onclick="sendNewPropertiesEmail()"> | |
<i class="fas fa-paper-plane"></i> Send Email | |
</button> | |
</div> | |
</div> | |
</div> | |
<!-- AI Recommendations Email --> | |
<div class="col-md-4 mb-3"> | |
<div class="card dashboard-card ai-recommendations-card"> | |
<div class="card-body text-center"> | |
<i class="fas fa-robot fa-3x mb-3"></i> | |
<h5 class="card-title">AI Recommendations</h5> | |
<p class="card-text">Send personalized recommendations based on AI analysis of user behavior</p> | |
<button class="btn btn-light btn-email-action" onclick="sendAIRecommendationsEmail()"> | |
<i class="fas fa-paper-plane"></i> Send Email | |
</button> | |
</div> | |
</div> | |
</div> | |
<!-- Peak Time Engagement Email --> | |
<div class="col-md-4 mb-3"> | |
<div class="card dashboard-card peak-time-card"> | |
<div class="card-body text-center"> | |
<i class="fas fa-clock fa-3x mb-3"></i> | |
<h5 class="card-title">Peak Time Engagement</h5> | |
<p class="card-text">Send emails during user's most active viewing time for maximum engagement</p> | |
<button class="btn btn-light btn-email-action" onclick="sendPeakTimeEmail()"> | |
<i class="fas fa-paper-plane"></i> Send Email | |
</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Send All Emails --> | |
<div class="row mb-4"> | |
<div class="col-12"> | |
<div class="card dashboard-card email-type-card"> | |
<div class="card-body text-center"> | |
<i class="fas fa-rocket fa-3x mb-3"></i> | |
<h4 class="card-title">Complete Email Automation</h4> | |
<p class="card-text">Send all three types of emails based on comprehensive user tracking analysis</p> | |
<button class="btn btn-light btn-email-action btn-lg" onclick="sendAllEmails()"> | |
<i class="fas fa-rocket"></i> Send All Emails | |
</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Email Status and Results --> | |
<div class="row mb-4"> | |
<div class="col-12"> | |
<div class="card dashboard-card"> | |
<div class="card-body"> | |
<h5 class="card-title"><i class="fas fa-tasks"></i> Email Status & Results</h5> | |
<div id="emailResults"> | |
<p class="text-muted">Email results will appear here</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Email Preview --> | |
<div class="row mb-4"> | |
<div class="col-12"> | |
<div class="card dashboard-card"> | |
<div class="card-body"> | |
<h5 class="card-title"><i class="fas fa-eye"></i> Email Preview</h5> | |
<div id="emailPreview" class="email-preview"> | |
<p class="text-muted">Email preview will appear here</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Analytics Charts --> | |
<div class="row mb-4"> | |
<div class="col-md-6"> | |
<div class="analytics-chart"> | |
<h5><i class="fas fa-chart-pie"></i> Email Performance</h5> | |
<canvas id="emailPerformanceChart" width="400" height="200"></canvas> | |
</div> | |
</div> | |
<div class="col-md-6"> | |
<div class="analytics-chart"> | |
<h5><i class="fas fa-chart-bar"></i> User Engagement</h5> | |
<canvas id="engagementChart" width="400" height="200"></canvas> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Loading Modal --> | |
<div class="modal fade" id="loadingModal" tabindex="-1" aria-hidden="true"> | |
<div class="modal-dialog modal-dialog-centered"> | |
<div class="modal-content"> | |
<div class="modal-body text-center"> | |
<div class="spinner-border text-primary mb-3" role="status"> | |
<span class="visually-hidden">Loading...</span> | |
</div> | |
<h5>Processing Email Automation...</h5> | |
<p class="text-muted">Analyzing user data and sending emails</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
<script> | |
let currentCustomerId = null; | |
let currentEmail = null; | |
// Load customer data | |
async function loadCustomerData() { | |
const customerId = document.getElementById('customerId').value; | |
const email = document.getElementById('customerEmail').value; | |
if (!customerId || !email) { | |
alert('Please enter both Customer ID and Email address'); | |
return; | |
} | |
currentCustomerId = customerId; | |
currentEmail = email; | |
try { | |
const response = await fetch(`/api/lead-analysis/${customerId}`); | |
const data = await response.json(); | |
if (data.success) { | |
displayCustomerAnalytics(data); | |
showSuccess('Customer data loaded successfully!'); | |
} else { | |
showError('Failed to load customer data: ' + data.error); | |
} | |
} catch (error) { | |
showError('Error loading customer data: ' + error.message); | |
} | |
} | |
// Display customer analytics | |
function displayCustomerAnalytics(data) { | |
const analyticsDiv = document.getElementById('customerAnalytics'); | |
if (data.data && data.data.analytics) { | |
const analytics = data.data.analytics; | |
analyticsDiv.innerHTML = ` | |
<div class="row"> | |
<div class="col-6"> | |
<small class="text-muted">Properties Viewed:</small> | |
<h6>${analytics.total_properties || 0}</h6> | |
</div> | |
<div class="col-6"> | |
<small class="text-muted">Engagement Score:</small> | |
<h6>${analytics.engagement_score || 'N/A'}</h6> | |
</div> | |
</div> | |
<div class="row mt-2"> | |
<div class="col-6"> | |
<small class="text-muted">Preferred Type:</small> | |
<h6>${analytics.preferred_property_type || 'Villa'}</h6> | |
</div> | |
<div class="col-6"> | |
<small class="text-muted">Budget Range:</small> | |
<h6>${analytics.budget_range || '500K-2M'}</h6> | |
</div> | |
</div> | |
`; | |
} else { | |
analyticsDiv.innerHTML = '<p class="text-muted">Analytics data not available</p>'; | |
} | |
} | |
// Send new properties email | |
async function sendNewPropertiesEmail() { | |
if (!validateCustomer()) return; | |
showLoading(); | |
try { | |
const response = await fetch(`/api/email-automation/${currentCustomerId}`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: currentEmail, | |
email_type: 'new_properties' | |
}) | |
}); | |
const data = await response.json(); | |
hideLoading(); | |
displayEmailResults(data); | |
if (data.success) { | |
showSuccess('New properties email sent successfully!'); | |
} else { | |
showError('Failed to send new properties email: ' + data.error); | |
} | |
} catch (error) { | |
hideLoading(); | |
showError('Error sending new properties email: ' + error.message); | |
} | |
} | |
// Send AI recommendations email | |
async function sendAIRecommendationsEmail() { | |
if (!validateCustomer()) return; | |
showLoading(); | |
try { | |
const response = await fetch(`/api/email-automation/${currentCustomerId}`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: currentEmail, | |
email_type: 'recommendations' | |
}) | |
}); | |
const data = await response.json(); | |
hideLoading(); | |
displayEmailResults(data); | |
if (data.success) { | |
showSuccess('AI recommendations email sent successfully!'); | |
} else { | |
showError('Failed to send AI recommendations email: ' + data.error); | |
} | |
} catch (error) { | |
hideLoading(); | |
showError('Error sending AI recommendations email: ' + error.message); | |
} | |
} | |
// Send peak time engagement email | |
async function sendPeakTimeEmail() { | |
if (!validateCustomer()) return; | |
showLoading(); | |
try { | |
const response = await fetch(`/api/email-automation/${currentCustomerId}`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: currentEmail, | |
email_type: 'peak_time' | |
}) | |
}); | |
const data = await response.json(); | |
hideLoading(); | |
displayEmailResults(data); | |
if (data.success) { | |
showSuccess('Peak time engagement email sent successfully!'); | |
} else { | |
showError('Failed to send peak time email: ' + data.error); | |
} | |
} catch (error) { | |
hideLoading(); | |
showError('Error sending peak time email: ' + error.message); | |
} | |
} | |
// Send all emails | |
async function sendAllEmails() { | |
if (!validateCustomer()) return; | |
showLoading(); | |
try { | |
const response = await fetch(`/api/email-automation/${currentCustomerId}`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: currentEmail, | |
email_type: 'all' | |
}) | |
}); | |
const data = await response.json(); | |
hideLoading(); | |
displayEmailResults(data); | |
if (data.success) { | |
showSuccess('All emails sent successfully!'); | |
} else { | |
showError('Failed to send all emails: ' + data.error); | |
} | |
} catch (error) { | |
hideLoading(); | |
showError('Error sending all emails: ' + error.message); | |
} | |
} | |
// Display email results | |
function displayEmailResults(data) { | |
const resultsDiv = document.getElementById('emailResults'); | |
if (data.success && data.results) { | |
let html = '<div class="row">'; | |
data.results.forEach(result => { | |
const statusClass = result.success ? 'status-success' : 'status-error'; | |
const statusText = result.success ? 'Success' : 'Failed'; | |
html += ` | |
<div class="col-md-4 mb-3"> | |
<div class="card"> | |
<div class="card-body"> | |
<h6 class="card-title"> | |
<span class="status-indicator ${statusClass}"></span> | |
${result.type.replace('_', ' ').toUpperCase()} | |
</h6> | |
<p class="card-text">${result.message || result.error || 'Email sent'}</p> | |
${result.properties_count ? `<small class="text-muted">Properties: ${result.properties_count}</small>` : ''} | |
</div> | |
</div> | |
</div> | |
`; | |
}); | |
html += '</div>'; | |
if (data.ai_insights) { | |
html += ` | |
<div class="mt-3"> | |
<h6>AI Insights:</h6> | |
<div class="row"> | |
<div class="col-md-3"> | |
<small class="text-muted">Personality:</small> | |
<div>${data.ai_insights.personality_type || 'N/A'}</div> | |
</div> | |
<div class="col-md-3"> | |
<small class="text-muted">Urgency:</small> | |
<div>${data.ai_insights.urgency_level || 'N/A'}</div> | |
</div> | |
<div class="col-md-3"> | |
<small class="text-muted">Peak Time:</small> | |
<div>${data.ai_insights.peak_time || 'N/A'}</div> | |
</div> | |
<div class="col-md-3"> | |
<small class="text-muted">Engagement:</small> | |
<div>${data.ai_insights.engagement_level || 'N/A'}</div> | |
</div> | |
</div> | |
</div> | |
`; | |
} | |
resultsDiv.innerHTML = html; | |
} else { | |
resultsDiv.innerHTML = `<div class="alert alert-danger">${data.error || 'Unknown error occurred'}</div>`; | |
} | |
} | |
// Validate customer selection | |
function validateCustomer() { | |
if (!currentCustomerId || !currentEmail) { | |
alert('Please load customer data first'); | |
return false; | |
} | |
return true; | |
} | |
// Show loading modal | |
function showLoading() { | |
const modal = new bootstrap.Modal(document.getElementById('loadingModal')); | |
modal.show(); | |
} | |
// Hide loading modal | |
function hideLoading() { | |
const modal = bootstrap.Modal.getInstance(document.getElementById('loadingModal')); | |
if (modal) { | |
modal.hide(); | |
} | |
} | |
// Show success message | |
function showSuccess(message) { | |
// Create and show success alert | |
const alertDiv = document.createElement('div'); | |
alertDiv.className = 'alert alert-success alert-dismissible fade show position-fixed'; | |
alertDiv.style.top = '20px'; | |
alertDiv.style.right = '20px'; | |
alertDiv.style.zIndex = '9999'; | |
alertDiv.innerHTML = ` | |
${message} | |
<button type="button" class="btn-close" data-bs-dismiss="alert"></button> | |
`; | |
document.body.appendChild(alertDiv); | |
// Auto remove after 5 seconds | |
setTimeout(() => { | |
if (alertDiv.parentNode) { | |
alertDiv.parentNode.removeChild(alertDiv); | |
} | |
}, 5000); | |
} | |
// Show error message | |
function showError(message) { | |
// Create and show error alert | |
const alertDiv = document.createElement('div'); | |
alertDiv.className = 'alert alert-danger alert-dismissible fade show position-fixed'; | |
alertDiv.style.top = '20px'; | |
alertDiv.style.right = '20px'; | |
alertDiv.style.zIndex = '9999'; | |
alertDiv.innerHTML = ` | |
${message} | |
<button type="button" class="btn-close" data-bs-dismiss="alert"></button> | |
`; | |
document.body.appendChild(alertDiv); | |
// Auto remove after 5 seconds | |
setTimeout(() => { | |
if (alertDiv.parentNode) { | |
alertDiv.parentNode.removeChild(alertDiv); | |
} | |
}, 5000); | |
} | |
// Initialize charts | |
function initializeCharts() { | |
// Email Performance Chart | |
const emailCtx = document.getElementById('emailPerformanceChart').getContext('2d'); | |
new Chart(emailCtx, { | |
type: 'doughnut', | |
data: { | |
labels: ['New Properties', 'AI Recommendations', 'Peak Time'], | |
datasets: [{ | |
data: [85, 92, 78], | |
backgroundColor: ['#f093fb', '#4facfe', '#43e97b'] | |
}] | |
}, | |
options: { | |
responsive: true, | |
maintainAspectRatio: false | |
} | |
}); | |
// Engagement Chart | |
const engagementCtx = document.getElementById('engagementChart').getContext('2d'); | |
new Chart(engagementCtx, { | |
type: 'bar', | |
data: { | |
labels: ['Morning', 'Afternoon', 'Evening', 'Night'], | |
datasets: [{ | |
label: 'Engagement Level', | |
data: [65, 80, 95, 45], | |
backgroundColor: ['#667eea', '#764ba2', '#f093fb', '#f5576c'] | |
}] | |
}, | |
options: { | |
responsive: true, | |
maintainAspectRatio: false, | |
scales: { | |
y: { | |
beginAtZero: true, | |
max: 100 | |
} | |
} | |
} | |
}); | |
} | |
// Initialize page | |
document.addEventListener('DOMContentLoaded', function() { | |
initializeCharts(); | |
}); | |
</script> | |
</body> | |
</html> | |