542 lines
42 KiB
Python
542 lines
42 KiB
Python
import re
|
||
|
||
print("Starting implementation of 'پکیجها و تبلیغات' and Interactive UTM Analytics Tracker...")
|
||
|
||
with open('/workspace/live_marketing_index.html', 'r', encoding='utf-8') as f:
|
||
html = f.read()
|
||
|
||
# 1. Update Navigation Labels
|
||
html = html.replace('<span>گوگل ادز و پکیجهای B2B</span>', '<span>پکیجها و تبلیغات</span>')
|
||
html = html.replace('<span>منابع و استودیو UTM</span>', '<span>استودیو و تحلیل UTM</span>')
|
||
|
||
# 2. Build the Comprehensive UTM Tracker & Campaigns Engine
|
||
new_render_func = """
|
||
// ================= MASTER PACKAGES & ADS + UTM TRACKER ENGINE =================
|
||
let customUtmList = JSON.parse(localStorage.getItem('ekeepa_custom_utms_v1') || '[]');
|
||
if (customUtmList.length === 0) {
|
||
customUtmList = [
|
||
{ id: 'utm_1', campaign: 'halloween_special', source: 'instagram', medium: 'story', content: 'art_discount_20', clicks: 1420, leads: 185, sales_count: 62, revenue: 37200000, tag: 'فروش ویژه', date: '۱۴۰۵/۰۷/۰۱' },
|
||
{ id: 'utm_2', campaign: 'escape_weekend_ad', source: 'telegram', medium: 'channel_post', content: 'horror_cinema_vip', clicks: 980, leads: 94, sales_count: 38, revenue: 26600000, tag: 'آخر هفته', date: '۱۴۰۵/۰۷/۰۲' },
|
||
{ id: 'utm_3', campaign: 'b2b_teambuilding_q3', source: 'linkedin', medium: 'cpc', content: 'corporate_packages', clicks: 430, leads: 78, sales_count: 14, revenue: 84000000, tag: 'سازمانی B2B', date: '۱۴۰۵/۰۷/۰۴' },
|
||
{ id: 'utm_4', campaign: 'google_search_escaperoom', source: 'google', medium: 'cpc', content: 'tehran_best_rooms', clicks: 3200, leads: 410, sales_count: 155, revenue: 93000000, tag: 'گوگل ادز', date: '۱۴۰۵/۰۷/۰۵' },
|
||
{ id: 'utm_5', campaign: 'influencer_sheeshlik_promo', source: 'instagram', medium: 'reels', content: 'bio_link_ticket', clicks: 5400, leads: 620, sales_count: 210, revenue: 126000000, tag: 'اینفلوئنسر', date: '۱۴۰۵/۰۷/۰۶' }
|
||
];
|
||
localStorage.setItem('ekeepa_custom_utms_v1', JSON.stringify(customUtmList));
|
||
}
|
||
|
||
let utmFilterSource = 'all';
|
||
let utmFilterTag = 'all';
|
||
let utmSearchQuery = '';
|
||
|
||
function renderGoogleAdsB2BView() {
|
||
const pane = document.getElementById('tabPaneGoogleAdsB2B');
|
||
if (!pane) return;
|
||
|
||
const data = GOOGLE_ADS_B2B_MASTER;
|
||
const s = data.summary;
|
||
|
||
let criticalCount = data.vip_rooms.filter(r => r.status === 'critical').length;
|
||
let warningCount = data.vip_rooms.filter(r => r.status === 'warning').length;
|
||
|
||
// Filter UTMs
|
||
let filteredUtms = customUtmList.filter(item => {
|
||
const matchSrc = (utmFilterSource === 'all') || (item.source === utmFilterSource);
|
||
const matchTag = (utmFilterTag === 'all') || (item.tag === utmFilterTag);
|
||
const q = utmSearchQuery.toLowerCase().trim();
|
||
const matchSearch = !q || (item.campaign.toLowerCase().includes(q) || item.source.toLowerCase().includes(q) || item.medium.toLowerCase().includes(q) || (item.content && item.content.toLowerCase().includes(q)) || (item.tag && item.tag.toLowerCase().includes(q)));
|
||
return matchSrc && matchTag && matchSearch;
|
||
});
|
||
|
||
// Calculate aggregated UTM stats
|
||
const totalUtmClicks = filteredUtms.reduce((sum, it) => sum + (it.clicks || 0), 0);
|
||
const totalUtmLeads = filteredUtms.reduce((sum, it) => sum + (it.leads || 0), 0);
|
||
const totalUtmSales = filteredUtms.reduce((sum, it) => sum + (it.sales_count || 0), 0);
|
||
const totalUtmRevenue = filteredUtms.reduce((sum, it) => sum + (it.revenue || 0), 0);
|
||
const avgConversionRate = totalUtmClicks > 0 ? ((totalUtmSales / totalUtmClicks) * 100).toFixed(1) : '0';
|
||
|
||
let html = `
|
||
<div style="margin-bottom: 24px;">
|
||
<!-- ALERT BANNER: END OF MONTH REMINDER -->
|
||
<div style="background: linear-gradient(135deg, #FFF1F2 0%, #FFE4E6 100%); border: 1.5px solid #FDA4AF; border-radius: 16px; padding: 18px 24px; margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; box-shadow: 0 4px 15px rgba(225, 29, 72, 0.08);">
|
||
<div style="display: flex; align-items: center; gap: 16px;">
|
||
<div style="width: 46px; height: 46px; border-radius: 12px; background: #E11D48; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0;">
|
||
⏰
|
||
</div>
|
||
<div>
|
||
<div style="font-size: 1.05rem; font-weight: 800; color: #9F1239; margin-bottom: 4px;">
|
||
هشدار اتمام دوره ماهانه: تنها ${s.days_left_in_month} روز تا پایان ماه باقی مانده است!
|
||
</div>
|
||
<div style="font-size: 0.85rem; color: #BE123C; line-height: 1.5;">
|
||
تعداد <strong>${criticalCount} پکیج VIP بحرانی</strong> و <strong>${warningCount} پکیج نیازمند توجه</strong> به تارگت فروش ماهانه نرسیدهاند. برای جلوگیری از خالی ماندن سانسها، کمپینهای فوری سوشال را فعال کنید.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; gap: 10px;">
|
||
<button onclick="scrollToVipAlerts()" style="background: #E11D48; color: #fff; border: none; padding: 10px 18px; border-radius: 10px; font-weight: 800; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 12px rgba(225, 29, 72, 0.3);">
|
||
<span>مشاهده پکیجهای جا مانده از تارگت</span>
|
||
<span>↓</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- TOP KPI STRIP -->
|
||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px;">
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
|
||
<div style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px;">بودجه تبلیغات و گوگل ادز</div>
|
||
<div style="font-size: 1.35rem; font-weight: 900; color: var(--text-main); font-feature-settings: 'tnum';">${(s.total_ad_spend_toman / 1000000).toLocaleString('fa-IR')} م تومان</div>
|
||
<div style="font-size: 0.76rem; color: #059669; margin-top: 4px; font-weight: 600;">CPC میانگین: ${s.avg_cpc_toman.toLocaleString('fa-IR')} تومان</div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
|
||
<div style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px;">فروش کل پکیجها و ادز</div>
|
||
<div style="font-size: 1.35rem; font-weight: 900; color: var(--primary); font-feature-settings: 'tnum';">${((s.b2b_revenue_toman + totalUtmRevenue) / 1000000).toLocaleString('fa-IR')} م تومان</div>
|
||
<div style="font-size: 0.76rem; color: var(--primary); margin-top: 4px; font-weight: 600;">بازگشت سرمایه (ROAS): ${s.ad_roas}</div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
|
||
<div style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px;">لیدها و قراردادهای B2B</div>
|
||
<div style="font-size: 1.35rem; font-weight: 900; color: var(--text-main); font-feature-settings: 'tnum';">${s.b2b_closed_deals.toLocaleString('fa-IR')} / ${s.total_b2b_leads.toLocaleString('fa-IR')} لید</div>
|
||
<div style="font-size: 0.76rem; color: #2563EB; margin-top: 4px; font-weight: 600;">نرخ بستن قرارداد: ۱۷.۴%</div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
|
||
<div style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px;">کلیک و فروش لینکهای UTM</div>
|
||
<div style="font-size: 1.35rem; font-weight: 900; color: #0d9488; font-feature-settings: 'tnum';">${totalUtmSales.toLocaleString('fa-IR')} خرید (${totalUtmClicks.toLocaleString('fa-IR')} کلیک)</div>
|
||
<div style="font-size: 0.76rem; color: #0d9488; margin-top: 4px; font-weight: 700;">نرخ تبدیل فروش: ${avgConversionRate}%</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ================= NEW SECTION: UTM ANALYTICS & CAMPAIGN TRACKER ================= -->
|
||
<div style="background: var(--bg-card); border: 1.5px solid var(--border-color); border-radius: 16px; padding: 22px; margin-bottom: 28px; box-shadow: 0 4px 15px rgba(0,0,0,0.04);">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; border-bottom: 1px solid var(--border-color); padding-bottom: 14px;">
|
||
<div>
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 1.3rem;">🎯</span>
|
||
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--text-main);">ردیاب و آنالیزور پیشرفته کمپینهای UTM (تکی و گروهی)</h3>
|
||
</div>
|
||
<div style="font-size: 0.8rem; color: var(--text-muted); margin-top: 4px;">
|
||
پیگیری کلیکها، لیدهای دریافتی، تعداد بلیتهای خریداریشده و درآمد حاصل از هر لینک تبلیغاتی در سوشال و ادز
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||
<button onclick="openAddUtmModal()" class="date-btn active" style="background: var(--primary); color: #fff; padding: 8px 16px; font-size: 0.82rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px;">
|
||
<span>➕ ثبت و ست کردن UTM جدید</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- UTM Quick Aggregate Highlights -->
|
||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px;">
|
||
<div style="background: var(--bg-body); border: 1px solid var(--border-color); padding: 12px 14px; border-radius: 10px; text-align: center;">
|
||
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">تعداد کمپینهای انتخابی</div>
|
||
<div style="font-size: 1.2rem; font-weight: 900; color: var(--text-main); margin-top: 4px;">${filteredUtms.length.toLocaleString('fa-IR')} لینک</div>
|
||
</div>
|
||
<div style="background: var(--bg-body); border: 1px solid var(--border-color); padding: 12px 14px; border-radius: 10px; text-align: center;">
|
||
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">مجموع کلیکها</div>
|
||
<div style="font-size: 1.2rem; font-weight: 900; color: #2563EB; margin-top: 4px;">${totalUtmClicks.toLocaleString('fa-IR')}</div>
|
||
</div>
|
||
<div style="background: var(--bg-body); border: 1px solid var(--border-color); padding: 12px 14px; border-radius: 10px; text-align: center;">
|
||
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">تعداد خرید / بلیت پکیج</div>
|
||
<div style="font-size: 1.2rem; font-weight: 900; color: #059669; margin-top: 4px;">${totalUtmSales.toLocaleString('fa-IR')} سانس</div>
|
||
</div>
|
||
<div style="background: var(--bg-body); border: 1px solid var(--border-color); padding: 12px 14px; border-radius: 10px; text-align: center;">
|
||
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">درآمد رهگیریشده</div>
|
||
<div style="font-size: 1.2rem; font-weight: 900; color: var(--primary); margin-top: 4px;">${(totalUtmRevenue / 1000000).toLocaleString('fa-IR')} م تومان</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- UTM Search & Filters Bar -->
|
||
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; background: var(--bg-body); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border-color);">
|
||
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
|
||
<span style="font-size: 0.8rem; font-weight: 700; color: var(--text-muted);">فیلتر منبع (Source):</span>
|
||
<div style="display: flex; gap: 4px;">
|
||
<button onclick="setUtmSourceFilter('all')" class="date-btn ${utmFilterSource === 'all' ? 'active' : ''}" style="padding: 4px 10px; font-size: 0.75rem;">همه</button>
|
||
<button onclick="setUtmSourceFilter('instagram')" class="date-btn ${utmFilterSource === 'instagram' ? 'active' : ''}" style="padding: 4px 10px; font-size: 0.75rem;">📸 اینستاگرام</button>
|
||
<button onclick="setUtmSourceFilter('telegram')" class="date-btn ${utmFilterSource === 'telegram' ? 'active' : ''}" style="padding: 4px 10px; font-size: 0.75rem;">✈️ تلگرام</button>
|
||
<button onclick="setUtmSourceFilter('google')" class="date-btn ${utmFilterSource === 'google' ? 'active' : ''}" style="padding: 4px 10px; font-size: 0.75rem;">🔍 گوگل ادز</button>
|
||
<button onclick="setUtmSourceFilter('linkedin')" class="date-btn ${utmFilterSource === 'linkedin' ? 'active' : ''}" style="padding: 4px 10px; font-size: 0.75rem;">💼 لینکدین</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: flex; align-items: center; gap: 10px;">
|
||
<input type="text" id="utmLiveSearchInput" value="${utmSearchQuery}" oninput="handleUtmSearch(this.value)" placeholder="جستجو در کمپین، تگ، مدیوم..." style="padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); font-size: 0.78rem; width: 220px;">
|
||
</div>
|
||
</div>
|
||
|
||
<!-- UTM Data Table -->
|
||
<div style="overflow-x: auto; width: 100%;">
|
||
<table class="data-table" style="width: 100%; border-collapse: collapse; font-size: 0.8rem;">
|
||
<thead>
|
||
<tr style="background: var(--bg-body); border-bottom: 2px solid var(--border-color); text-align: right;">
|
||
<th style="padding: 10px 12px; font-weight: 800;">کمپین (utm_campaign)</th>
|
||
<th style="padding: 10px 12px; font-weight: 800;">منبع / مدیوم</th>
|
||
<th style="padding: 10px 12px; font-weight: 800;">محتوا (utm_content)</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">گروه / تگ</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">کلیکها</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">لید / تماس</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">خرید موفق</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">نرخ تبدیل (CR)</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: left;">فروش حاصله (تومان)</th>
|
||
<th style="padding: 10px 12px; font-weight: 800; text-align: center;">عملیات</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
${filteredUtms.length === 0 ? `
|
||
<tr>
|
||
<td colspan="10" style="padding: 30px; text-align: center; color: var(--text-muted);">هیچ کمپین یا لینکی با این فیلتر یافت نشد.</td>
|
||
</tr>
|
||
` : filteredUtms.map((it, idx) => {
|
||
const cr = it.clicks > 0 ? ((it.sales_count / it.clicks) * 100).toFixed(1) : 0;
|
||
return `
|
||
<tr style="border-bottom: 1px solid var(--border-color); transition: background 0.15s;">
|
||
<td style="padding: 10px 12px; font-weight: 800; color: var(--text-main);">
|
||
<div style="font-family: monospace; direction: ltr; text-align: right; color: var(--primary);">${it.campaign}</div>
|
||
<div style="font-size: 0.7rem; color: var(--text-muted);">${it.date || ''}</div>
|
||
</td>
|
||
<td style="padding: 10px 12px;">
|
||
<span style="display: inline-block; padding: 2px 8px; border-radius: 6px; background: rgba(59, 130, 246, 0.1); color: #2563EB; font-size: 0.72rem; font-weight: 700; font-family: monospace;">${it.source} / ${it.medium}</span>
|
||
</td>
|
||
<td style="padding: 10px 12px; font-family: monospace; color: var(--text-body); font-size: 0.74rem;">${it.content || '-'}</td>
|
||
<td style="padding: 10px 12px; text-align: center;">
|
||
<span style="display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--bg-body); border: 1px solid var(--border-color); font-size: 0.72rem; font-weight: 700;">${it.tag || 'عمومی'}</span>
|
||
</td>
|
||
<td style="padding: 10px 12px; text-align: center; font-weight: 800; font-feature-settings: 'tnum';">${(it.clicks || 0).toLocaleString('fa-IR')}</td>
|
||
<td style="padding: 10px 12px; text-align: center; font-feature-settings: 'tnum'; color: #2563EB; font-weight: 700;">${(it.leads || 0).toLocaleString('fa-IR')}</td>
|
||
<td style="padding: 10px 12px; text-align: center; font-weight: 900; color: #059669; font-feature-settings: 'tnum';">${(it.sales_count || 0).toLocaleString('fa-IR')}</td>
|
||
<td style="padding: 10px 12px; text-align: center; font-weight: 800; color: ${cr >= 4 ? '#059669' : '#D97706'}; font-feature-settings: 'tnum';">${cr}%</td>
|
||
<td style="padding: 10px 12px; text-align: left; font-weight: 900; color: var(--primary); font-feature-settings: 'tnum';">${((it.revenue || 0)).toLocaleString('fa-IR')} ت</td>
|
||
<td style="padding: 10px 12px; text-align: center;">
|
||
<div style="display: flex; gap: 4px; justify-content: center;">
|
||
<button onclick="copyUtmUrl('${it.campaign}', '${it.source}', '${it.medium}', '${it.content || ''}')" title="کپی لینک کامل UTM" style="background: none; border: none; cursor: pointer; font-size: 0.9rem;">🔗</button>
|
||
<button onclick="editUtmRecord('${it.id}')" title="ویرایش آمار فروش و کلیک" style="background: none; border: none; cursor: pointer; font-size: 0.9rem;">✏️</button>
|
||
<button onclick="deleteUtmRecord('${it.id}')" title="حذف" style="background: none; border: none; cursor: pointer; font-size: 0.9rem; color: #EF4444;">🗑️</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
`;
|
||
}).join('')}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- SECTION 1: VIP ROOMS SALES WARNING & RESCUE ENGINE -->
|
||
<div id="vipAlertsSection" style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; padding: 22px; margin-bottom: 28px; box-shadow: 0 2px 12px rgba(0,0,0,0.04);">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px;">
|
||
<div>
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 1.3rem;">🚨</span>
|
||
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 800; color: #9F1239;">اتاقهای VIP و سینماهای بحرانی (نیازمند پوشش سناریو در سوشال)</h3>
|
||
</div>
|
||
<div style="font-size: 0.8rem; color: var(--text-muted); margin-top: 4px;">
|
||
اتاقها و سانسهای با نرخ تکمیل کمتر از ۷۰٪ در پایان ماه — محتوای فوری برای پر کردن سانسها تولید شود
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;">
|
||
${data.vip_rooms.map(room => {
|
||
let isCrit = room.status === 'critical';
|
||
let isWarn = room.status === 'warning';
|
||
let badgeBg = isCrit ? '#FFE4E6' : (isWarn ? '#FEF3C7' : '#DCFCE7');
|
||
let badgeColor = isCrit ? '#9F1239' : (isWarn ? '#92400E' : '#166534');
|
||
let badgeText = isCrit ? '⚠️ بحرانی (فاصله زیاد از تارگت)' : (isWarn ? '⚡ نیازمند توجه' : '✅ در مسیر تارگت');
|
||
|
||
return `
|
||
<div style="border: 1.5px solid ${isCrit ? '#FDA4AF' : (isWarn ? '#FDE68A' : '#BBF7D0')}; background: var(--bg-card); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.02);">
|
||
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px;">
|
||
<div>
|
||
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main);">${room.room_name}</div>
|
||
<div style="font-size: 0.75rem; color: var(--text-muted);">${room.genre} | ظرفیت: ${room.capacity_per_slot} نفر</div>
|
||
</div>
|
||
<span style="background: ${badgeBg}; color: ${badgeColor}; font-size: 0.72rem; font-weight: 800; padding: 3px 8px; border-radius: 6px;">${badgeText}</span>
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.78rem;">
|
||
<span style="color: var(--text-muted);">رزرو شده: <strong>${room.booked_slots}</strong> از ${room.target_slots} سانس</span>
|
||
<span style="font-weight: 800; color: ${isCrit ? '#E11D48' : '#059669'};">${room.completion_pct}%</span>
|
||
</div>
|
||
|
||
<div style="height: 7px; background: var(--bg-body); border-radius: 4px; overflow: hidden; margin-bottom: 12px;">
|
||
<div style="height: 100%; width: ${room.completion_pct}%; background: ${isCrit ? '#E11D48' : (isWarn ? '#F59E0B' : '#10B981')}; border-radius: 4px;"></div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-body); padding: 8px 10px; border-radius: 8px; font-size: 0.75rem; line-height: 1.5; color: var(--text-body); margin-bottom: 12px;">
|
||
💡 <strong>اکشن فوری سوشال:</strong> ${room.suggested_rescue_action}
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 10px;">
|
||
<span style="font-size: 0.75rem; font-weight: 700; color: var(--primary);">قیمت بلیت: ${room.ticket_price_toman.toLocaleString('fa-IR')} تومان</span>
|
||
<button onclick="createScenarioForRescue('${room.room_name.replace(/'/g, "\\\\'")}', '${room.suggested_rescue_action.replace(/'/g, "\\\\'")}')" class="date-btn active" style="padding: 4px 10px; font-size: 0.72rem; background: var(--primary); color: #fff;">
|
||
➕ ایجاد سناریو در شیت
|
||
</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
}).join('')}
|
||
</div>
|
||
</div>
|
||
|
||
<!-- SECTION 2: B2B CORPORATE PACKAGES -->
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; padding: 22px; margin-bottom: 28px; box-shadow: 0 2px 12px rgba(0,0,0,0.04);">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px;">
|
||
<div>
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 1.3rem;">💼</span>
|
||
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--text-main);">پکیجهای سازمانی، تیمبیلدینگ و سینماهای دربستی</h3>
|
||
</div>
|
||
<div style="font-size: 0.8rem; color: var(--text-muted); margin-top: 4px;">
|
||
وضعیت فروش پکیجهای B2B، لیدهای سازمانی و قراردادهای منعقد شده در ماه جاری
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;">
|
||
${data.b2b_packages.map(pkg => `
|
||
<div style="border: 1px solid var(--border-color); background: var(--bg-card); border-radius: 14px; padding: 16px;">
|
||
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px;">
|
||
<div>
|
||
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main);">${pkg.title}</div>
|
||
<div style="font-size: 0.74rem; color: var(--text-muted);">${pkg.target_audience}</div>
|
||
</div>
|
||
<span style="background: rgba(124, 58, 237, 0.1); color: var(--primary); font-size: 0.74rem; font-weight: 800; padding: 3px 8px; border-radius: 6px;">${pkg.price_range}</span>
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; background: var(--bg-body); padding: 10px; border-radius: 8px; margin-bottom: 10px; text-align: center;">
|
||
<div>
|
||
<div style="font-size: 0.7rem; color: var(--text-muted);">لید دریافتی</div>
|
||
<div style="font-size: 0.95rem; font-weight: 800; color: #2563EB; font-feature-settings: 'tnum';">${pkg.leads_generated.toLocaleString('fa-IR')}</div>
|
||
</div>
|
||
<div>
|
||
<div style="font-size: 0.7rem; color: var(--text-muted);">قرارداد نهایی</div>
|
||
<div style="font-size: 0.95rem; font-weight: 800; color: #059669; font-feature-settings: 'tnum';">${pkg.closed_deals.toLocaleString('fa-IR')}</div>
|
||
</div>
|
||
<div>
|
||
<div style="font-size: 0.7rem; color: var(--text-muted);">درآمد حاصله</div>
|
||
<div style="font-size: 0.95rem; font-weight: 800; color: var(--primary); font-feature-settings: 'tnum';">${(pkg.revenue_generated_toman / 1000000).toLocaleString('fa-IR')} م</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="font-size: 0.75rem; color: var(--text-muted); line-height: 1.5;">
|
||
🎯 <strong>محتوا و درگاه جذب:</strong> ${pkg.suggested_content_hook}
|
||
</div>
|
||
</div>
|
||
`).join('')}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
|
||
pane.innerHTML = html;
|
||
}
|
||
|
||
// ================= UTM CONTROLLER FUNCTIONS =================
|
||
function setUtmSourceFilter(src) {
|
||
utmFilterSource = src;
|
||
renderGoogleAdsB2BView();
|
||
}
|
||
|
||
function handleUtmSearch(query) {
|
||
utmSearchQuery = query;
|
||
renderGoogleAdsB2BView();
|
||
}
|
||
|
||
function copyUtmUrl(campaign, source, medium, content) {
|
||
const baseUrl = "https://ekeepa.ir/tickets";
|
||
const fullUrl = `${baseUrl}?utm_source=${source}&utm_medium=${medium}&utm_campaign=${campaign}${content ? '&utm_content=' + content : ''}`;
|
||
navigator.clipboard.writeText(fullUrl).then(() => {
|
||
showToast('لینک اختصاصی UTM در کلیپبورد کپی شد 🔗✅');
|
||
}).catch(() => {
|
||
showToast(fullUrl);
|
||
});
|
||
}
|
||
|
||
function openAddUtmModal() {
|
||
const modal = document.getElementById('addUtmModal');
|
||
if (modal) {
|
||
modal.style.display = 'flex';
|
||
}
|
||
}
|
||
|
||
function closeAddUtmModal() {
|
||
const modal = document.getElementById('addUtmModal');
|
||
if (modal) {
|
||
modal.style.display = 'none';
|
||
}
|
||
}
|
||
|
||
function handleAddUtmSubmit(event) {
|
||
event.preventDefault();
|
||
const campaign = document.getElementById('newUtmCampaign').value.trim();
|
||
const source = document.getElementById('newUtmSource').value;
|
||
const medium = document.getElementById('newUtmMedium').value;
|
||
const content = document.getElementById('newUtmContent').value.trim();
|
||
const tag = document.getElementById('newUtmTag').value.trim() || 'عمومی';
|
||
const clicks = parseInt(document.getElementById('newUtmClicks').value) || 0;
|
||
const leads = parseInt(document.getElementById('newUtmLeads').value) || 0;
|
||
const sales = parseInt(document.getElementById('newUtmSales').value) || 0;
|
||
const revenue = parseInt(document.getElementById('newUtmRevenue').value) || 0;
|
||
|
||
if (!campaign) {
|
||
alert('لطفاً نام کمپین را وارد کنید.');
|
||
return;
|
||
}
|
||
|
||
const newItem = {
|
||
id: 'utm_' + Date.now(),
|
||
campaign,
|
||
source,
|
||
medium,
|
||
content,
|
||
tag,
|
||
clicks,
|
||
leads,
|
||
sales_count: sales,
|
||
revenue,
|
||
date: '۱۴۰۵/۰۷/' + String(new Date().getDate()).padStart(2, '0')
|
||
};
|
||
|
||
customUtmList.unshift(newItem);
|
||
localStorage.setItem('ekeepa_custom_utms_v1', JSON.stringify(customUtmList));
|
||
closeAddUtmModal();
|
||
renderGoogleAdsB2BView();
|
||
showToast('کمپین UTM با موفقیت ثبت شد 🎯✅');
|
||
}
|
||
|
||
function deleteUtmRecord(id) {
|
||
if (confirm('آیا از حذف این رکورد UTM اطمینان دارید؟')) {
|
||
customUtmList = customUtmList.filter(it => it.id !== id);
|
||
localStorage.setItem('ekeepa_custom_utms_v1', JSON.stringify(customUtmList));
|
||
renderGoogleAdsB2BView();
|
||
showToast('کمپین UTM حذف شد 🗑️');
|
||
}
|
||
}
|
||
|
||
function editUtmRecord(id) {
|
||
const item = customUtmList.find(it => it.id === id);
|
||
if (!item) return;
|
||
|
||
const clicksStr = prompt('تعداد کلیک جدید:', item.clicks);
|
||
if (clicksStr === null) return;
|
||
const salesStr = prompt('تعداد خرید / بلیت موفق جدید:', item.sales_count);
|
||
if (salesStr === null) return;
|
||
const revStr = prompt('مبلغ فروش به تومان:', item.revenue);
|
||
if (revStr === null) return;
|
||
|
||
item.clicks = parseInt(clicksStr) || 0;
|
||
item.sales_count = parseInt(salesStr) || 0;
|
||
item.revenue = parseInt(revStr) || 0;
|
||
|
||
localStorage.setItem('ekeepa_custom_utms_v1', JSON.stringify(customUtmList));
|
||
renderGoogleAdsB2BView();
|
||
showToast('آمار UTM با موفقیت بهروزرسانی شد 📊✅');
|
||
}
|
||
|
||
window.renderGoogleAdsB2BView = renderGoogleAdsB2BView;
|
||
window.setUtmSourceFilter = setUtmSourceFilter;
|
||
window.handleUtmSearch = handleUtmSearch;
|
||
window.copyUtmUrl = copyUtmUrl;
|
||
window.openAddUtmModal = openAddUtmModal;
|
||
window.closeAddUtmModal = closeAddUtmModal;
|
||
window.handleAddUtmSubmit = handleAddUtmSubmit;
|
||
window.deleteUtmRecord = deleteUtmRecord;
|
||
window.editUtmRecord = editUtmRecord;
|
||
"""
|
||
|
||
# Replace renderGoogleAdsB2BView in html
|
||
s_idx = html.find('function renderGoogleAdsB2BView() {')
|
||
if s_idx != -1:
|
||
e_idx = html.find('function scrollToVipAlerts()', s_idx)
|
||
if e_idx != -1:
|
||
html = html[:s_idx] + new_render_func + '\n\n' + html[e_idx:]
|
||
|
||
# Add UTM Modal to HTML
|
||
utm_modal_html = """
|
||
<!-- ================= 5. ADD UTM CAMPAIGN MODAL ================= -->
|
||
<div id="addUtmModal" style="display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(5px); z-index: 10000; align-items: center; justify-content: center; padding: 1rem;">
|
||
<div style="background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); padding: 1.5rem;">
|
||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.75rem;">
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 1.3rem;">🎯</span>
|
||
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">ثبت و ردیابی کمپین UTM جدید</h3>
|
||
</div>
|
||
<button type="button" onclick="closeAddUtmModal()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted);">×</button>
|
||
</div>
|
||
|
||
<form onsubmit="handleAddUtmSubmit(event)">
|
||
<div style="margin-bottom: 12px;">
|
||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">نام کمپین (utm_campaign) *:</label>
|
||
<input type="text" id="newUtmCampaign" required placeholder="e.g. mehr_vip_discount" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-family: monospace; font-size: 0.82rem;">
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
|
||
<div>
|
||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">منبع (utm_source):</label>
|
||
<select id="newUtmSource" style="width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-size: 0.8rem;">
|
||
<option value="instagram">📸 اینستاگرام (instagram)</option>
|
||
<option value="telegram">✈️ تلگرام (telegram)</option>
|
||
<option value="google">🔍 گوگل ادز (google)</option>
|
||
<option value="linkedin">💼 لینکدین (linkedin)</option>
|
||
<option value="sms">📱 پیامک (sms)</option>
|
||
<option value="bale">💬 پیامرسان بله (bale)</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">مدیوم (utm_medium):</label>
|
||
<select id="newUtmMedium" style="width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-size: 0.8rem;">
|
||
<option value="story">📱 استوری (story)</option>
|
||
<option value="reels">🎬 ریلز (reels)</option>
|
||
<option value="post">🖼️ پست فید (post)</option>
|
||
<option value="cpc">💰 تبلیغ کلیکی (cpc)</option>
|
||
<option value="channel_post">📢 پست کانال (channel_post)</option>
|
||
<option value="direct_dm">💬 دایرکت (direct_dm)</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
|
||
<div>
|
||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">محتوای لینک (utm_content):</label>
|
||
<input type="text" id="newUtmContent" placeholder="e.g. story_sticker_link" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-family: monospace; font-size: 0.8rem;">
|
||
</div>
|
||
<div>
|
||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">تگ / دستهبندی گروهی:</label>
|
||
<input type="text" id="newUtmTag" placeholder="e.g. فروش ویژه, سینما ترس, B2B" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main); font-size: 0.8rem;">
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; background: var(--bg-body); padding: 10px; border-radius: 10px; border: 1px solid var(--border-color);">
|
||
<div>
|
||
<label style="display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px;">کلیک اولیه:</label>
|
||
<input type="number" id="newUtmClicks" value="0" style="width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); font-size: 0.78rem;">
|
||
</div>
|
||
<div>
|
||
<label style="display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px;">لید / تماس:</label>
|
||
<input type="number" id="newUtmLeads" value="0" style="width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); font-size: 0.78rem;">
|
||
</div>
|
||
<div>
|
||
<label style="display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px;">خرید موفق:</label>
|
||
<input type="number" id="newUtmSales" value="0" style="width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); font-size: 0.78rem;">
|
||
</div>
|
||
<div>
|
||
<label style="display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px;">درآمد (تومان):</label>
|
||
<input type="number" id="newUtmRevenue" value="0" style="width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); font-size: 0.78rem;">
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border-color); padding-top: 1rem;">
|
||
<button type="button" onclick="closeAddUtmModal()" class="date-btn" style="padding: 8px 16px; font-size: 0.8rem;">انصراف</button>
|
||
<button type="submit" class="date-btn active" style="padding: 8px 20px; font-size: 0.82rem; font-weight: 800; background: var(--primary); color: #fff;">💾 ثبت و فعالسازی UTM</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
"""
|
||
|
||
if '<div id="addUtmModal"' not in html:
|
||
html = html.replace('</body>', utm_modal_html + '\n</body>')
|
||
|
||
with open('/workspace/live_marketing_index.html', 'w', encoding='utf-8') as f:
|
||
f.write(html)
|
||
|
||
print("Saved updated live_marketing_index.html with Packages & Ads and UTM Tracker!")
|