Customize Website

x
Color Swatches
Theme
Font Size
100%

Youtube Engagement Calculator

100% FREE

Check the engagement rate of any YouTube video or channel. Get detailed insights and compare its performance with similar videos from the channel or niche.

'; const blob = new Blob(['' + html], { type: 'application/vnd.ms-excel' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'engagement-' + String(name).replace(/[^a-z0-9]+/gi, '-').toLowerCase().slice(0, 40) + '.xls'; document.body.appendChild(a); a.click(); setTimeout(function () { URL.revokeObjectURL(a.href); a.remove(); }, 1000); } // ── Render dispatcher ── function renderReport(d) { newResultDiv.html(d.type === 'video' ? buildVideoDash(d) : buildChannelDash(d)).hide().fadeIn(400, renderVideoRows); } // ── Video dashboard ── function buildVideoDash(d) { let html = `

Video Engagement Report

Single Video Analysis
`; // Video card — title/details overlay the thumbnail if (d.thumbnail || d.title) { html += `
${d.thumbnail ? `thumb` : ''}
${esc(d.title)}
${esc(d.channel)}${d.published ? ' · ' + d.published : ''}
Watch on YouTube
`; } html += buildRateHero(d.rate, d.benchmark, d.likes_ratio, d.comment_ratio); html += `
👁️
Views
${numFmt(d.views)}
👍
Likes
${numFmt(d.likes)}
${d.likes_ratio.toFixed(2)}% of views
💬
Comments
${numFmt(d.comments)}
${d.comment_ratio.toFixed(2)}% of views
🔥
Engagement
${d.rate.toFixed(2)}%
${d.benchmark.label}
`; // Breakdown meters html += `

Engagement Breakdown

`; html += `
`; html += buildMeter('Like Rate', d.likes_ratio, '#10b981'); html += buildMeter('Comment Rate', d.comment_ratio, 'var(--yec-accent)'); html += `
`; // Channel comparison (vs last 15) if (d.channel_benchmark && d.videos_analysed) { const diff = d.rate - d.channel_avg_rate; const diffTxt = (diff >= 0 ? '+' : '') + diff.toFixed(2) + '% vs channel avg'; const diffCol = diff >= 0 ? '#10b981' : '#ef4444'; html += `

vs Channel Average

`; html += `
This Video
${d.rate.toFixed(2)}%
${d.benchmark.label}
VS
Channel Avg (last ${d.videos_analysed})
${d.channel_avg_rate.toFixed(2)}%
${d.channel_benchmark.label}
`; html += `
${diffTxt}
`; if (typeof d.channel_avg_like_rate === 'number') { html += `
Channel avg — 👍 ${d.channel_avg_like_rate.toFixed(2)}% likes · 💬 ${d.channel_avg_comment_rate.toFixed(2)}% comments
`; } } html += buildBenchmarkNote(); if (d.video_rows && d.video_rows.length) { html += `

Channel Videos — Ranked by Engagement (last ${d.video_rows.length})

`; html += buildVideoTableSection(d.video_rows, true); } html += buildStatsPlaceholder(); html += buildBottomActions(); return html; } // ── Channel dashboard ── function buildChannelDash(d) { let html = `

Channel Engagement Report

Based on last ${d.videos_analysed} videos
`; // Channel header html += `
`; if (d.channel_thumb) html += `${esc(d.channel_name)}`; html += `
${esc(d.channel_name)}
View Channel
`; html += buildRateHero(d.avg_rate, d.benchmark, d.avg_like_rate, d.avg_comment_rate); // Stats grid — channel totals html += `
👥
Subscribers
${numFmt(d.subscribers)}
📹
Total Videos
${numFmt(d.total_videos)}
👁️
Total Channel Views
${numFmt(d.total_views)}
all-time
📊
Avg Views
${numFmt(d.avg_views)}
per recent video
👍
Total Likes
${numFmt(d.total_likes)}
last ${d.videos_analysed} · ${d.avg_like_rate.toFixed(2)}%
💬
Total Comments
${numFmt(d.total_comments)}
last ${d.videos_analysed} · ${d.avg_comment_rate.toFixed(2)}%
🔥
Avg Engagement
${d.avg_rate.toFixed(2)}%
${d.benchmark.label}
`; // Breakdown meters (channel-level like/comment rates) html += `

Engagement Breakdown

`; html += `
`; html += buildMeter('Like Rate', d.avg_like_rate, '#10b981'); html += buildMeter('Comment Rate', d.avg_comment_rate, 'var(--yec-accent)'); html += `
`; html += buildBenchmarkNote(); if (d.video_rows && d.video_rows.length) { html += `

Recent Videos — Ranked by Engagement (last ${d.video_rows.length})

`; html += buildVideoTableSection(d.video_rows, false); } html += buildStatsPlaceholder(); html += buildBottomActions(); return html; } // ── Public tool statistics ── function buildStatsPlaceholder() { return `

Tool Statistics — Powered by the community

`; } function buildBottomActions() { return `
`; } function renderPublicStats(s) { const box = $('#yec-livestats'); if (!box.length) return; if (!s || !s.total_checks) { box.html('

Be the first to analyse a channel — stats will appear here.

'); return; } box.html(`
${numFmt(s.total_videos_analyzed)}
Videos Analysed
${numFmt(s.total_checks)}
Total Checks
${(s.channels_avg_eng || 0).toFixed(2)}%
Avg Channel Engagement
${(s.videos_avg_eng || 0).toFixed(2)}%
Avg Video Engagement
`); } function loadPublicStats() { $.ajax({ url: window.location.origin + '/wp-admin/admin-ajax.php', type: 'POST', data: { action: 'yt_engagement_stats' }, success: function (res) { try { const r = typeof res === 'string' ? JSON.parse(res) : res; if (r && r.success) renderPublicStats(r.stats); } catch (e) {} } }); } // ── Report downloads ── function reportBaseName(d) { const raw = d && d.type === 'channel' ? (d.channel_name || 'channel') : ((d && (d.title || d.channel)) || 'video'); const slug = String(raw).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 55); return 'engagement-' + (slug || 'report'); } function mdCell(value) { return String(value == null ? '' : value).replace(/\|/g, '\\|').replace(/\s+/g, ' ').trim(); } function exactNumber(value) { return Number(value || 0).toLocaleString('en-US'); } function buildReportMarkdown(d) { if (!d) return ''; const lines = ['# YouTube Engagement Report', '']; if (d.type === 'video') { lines.push('## ' + mdCell(d.title || 'Video report'), ''); lines.push('- Channel: ' + mdCell(d.channel)); if (d.published) lines.push('- Published: ' + mdCell(d.published)); lines.push('- Views: ' + exactNumber(d.views)); lines.push('- Likes: ' + exactNumber(d.likes)); lines.push('- Comments: ' + exactNumber(d.comments)); lines.push('- Engagement rate: ' + Number(d.rate || 0).toFixed(2) + '%'); lines.push('- Like rate: ' + Number(d.likes_ratio || 0).toFixed(3) + '%'); lines.push('- Comment rate: ' + Number(d.comment_ratio || 0).toFixed(3) + '%'); lines.push('- Benchmark: ' + mdCell(d.benchmark && d.benchmark.label)); if (d.channel_benchmark && d.videos_analysed) { lines.push('- Channel average (last ' + Number(d.videos_analysed) + ' videos): ' + Number(d.channel_avg_rate || 0).toFixed(2) + '%'); } } else { lines.push('## ' + mdCell(d.channel_name || 'Channel report'), ''); lines.push('- Subscribers: ' + exactNumber(d.subscribers)); lines.push('- Total videos: ' + exactNumber(d.total_videos)); lines.push('- Total channel views: ' + exactNumber(d.total_views)); lines.push('- Recent videos analysed: ' + exactNumber(d.videos_analysed)); lines.push('- Average views per recent video: ' + exactNumber(d.avg_views)); lines.push('- Average engagement rate: ' + Number(d.avg_rate || 0).toFixed(2) + '%'); lines.push('- Average like rate: ' + Number(d.avg_like_rate || 0).toFixed(3) + '%'); lines.push('- Average comment rate: ' + Number(d.avg_comment_rate || 0).toFixed(3) + '%'); lines.push('- Benchmark: ' + mdCell(d.benchmark && d.benchmark.label)); } const rows = Array.isArray(d.video_rows) ? d.video_rows : []; if (rows.length) { lines.push('', '## Analysed Videos', ''); lines.push('| # | Video | Published | Views | Likes | Comments | Like % | Comment % | Engagement % |'); lines.push('|---:|---|---|---:|---:|---:|---:|---:|---:|'); rows.forEach(function (v, i) { lines.push('| ' + (i + 1) + ' | ' + mdCell(v.title) + ' | ' + mdCell(v.published) + ' | ' + exactNumber(v.views) + ' | ' + exactNumber(v.likes) + ' | ' + exactNumber(v.comments) + ' | ' + Number(v.like_rate || 0).toFixed(3) + ' | ' + Number(v.comment_rate || 0).toFixed(3) + ' | ' + Number(v.rate || 0).toFixed(2) + ' |'); }); } lines.push('', 'Industry benchmarks: below 0.5% = Below Average; 0.5%–1% = Average; 1%–3% = Good; 3%–5% = Excellent; above 5% = Exceptional.'); return lines.join('\n').trim() + '\n'; } function buildReportText(d) { return buildReportMarkdown(d).split('\n').filter(function (line) { return !/^\|(?:\s*:?-+:?\s*\|)+$/.test(line); }).map(function (line) { if (/^\|.*\|$/.test(line)) { const protectedLine = line.replace(/\\\|/g, '\u0000'); return protectedLine.slice(1, -1).split('|').map(function (cell) { return cell.trim().replace(/\u0000/g, '|'); }).join('\t'); } return line.replace(/^#{1,6}\s+/, '').replace(/^-\s+/, '• '); }).join('\n'); } function downloadReportBlob(content, type, filename) { const blob = new Blob(['\ufeff' + content], { type: type }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = filename; document.body.appendChild(a); a.click(); setTimeout(function () { URL.revokeObjectURL(a.href); a.remove(); }, 1000); } function setExportStatus(message, state) { $('#yec-export-status').text(message || '').removeClass('success error').addClass(state || ''); } function printReportFallback() { const d = window.YEC_DATA; if (!d) return; const w = window.open('', '_blank'); if (!w) { setExportStatus('Popup blocked. Allow popups to save the report as PDF.', 'error'); return; } w.document.write('Engagement Report
' + esc(buildReportText(d)) + '
'); w.document.close(); w.focus(); setTimeout(function () { w.print(); }, 350); setExportStatus('Print dialog opened. Choose Save as PDF.', 'success'); } function loadHtml2Pdf(onReady, onError) { if (window.html2pdf) { onReady(); return; } if (yecPdfLoading) return; yecPdfLoading = true; const script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/html2pdf.js@0.10.1/dist/html2pdf.bundle.min.js'; script.onload = function () { yecPdfLoading = false; onReady(); }; script.onerror = function () { yecPdfLoading = false; onError(); }; document.head.appendChild(script); } function downloadReportPdf() { const d = window.YEC_DATA; const $source = $('#yec-ai-result').last(); if (!d || !$source.length) return; const $button = $('#yec-download-pdf').prop('disabled', true); setExportStatus('Preparing PDF…'); loadHtml2Pdf(function () { const $clone = $source.clone(); $clone.find('.yec-share-btn,.yec-toolbar,.yec-bottom-actions,.ai-loader').remove(); const stage = document.createElement('div'); stage.className = 'result-container yec-pdf-stage'; const liveStyles = getComputedStyle($source.closest('.result-container')[0]); stage.style.setProperty('--yec-accent', liveStyles.getPropertyValue('--yec-accent').trim() || '#377dff'); stage.style.setProperty('--yec-accent-dark', liveStyles.getPropertyValue('--yec-accent-dark').trim() || '#2563eb'); stage.appendChild($clone[0]); document.body.appendChild(stage); window.html2pdf().set({ margin: 8, filename: reportBaseName(d) + '.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, backgroundColor: '#ffffff' }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, pagebreak: { mode: ['css', 'legacy'] } }).from(stage).save().then(function () { stage.remove(); $button.prop('disabled', false); setExportStatus('PDF downloaded.', 'success'); }).catch(function () { stage.remove(); $button.prop('disabled', false); printReportFallback(); }); }, function () { $button.prop('disabled', false); printReportFallback(); }); } $(document).on('click', '#yec-download-pdf', downloadReportPdf); $(document).on('click', '#yec-download-txt', function () { const d = window.YEC_DATA; if (!d) return; downloadReportBlob(buildReportText(d), 'text/plain;charset=utf-8', reportBaseName(d) + '.txt'); setExportStatus('TXT downloaded.', 'success'); }); $(document).on('click', '#yec-download-md', function () { const d = window.YEC_DATA; if (!d) return; downloadReportBlob(buildReportMarkdown(d), 'text/markdown;charset=utf-8', reportBaseName(d) + '.md'); setExportStatus('Markdown downloaded.', 'success'); }); // ── Share report ── function closeShareModal() { $('#yec-share-overlay').removeClass('active').attr('aria-hidden', 'true'); } $(document).on('click', '.yec-share-report-btn', function () { if (!window.YEC_DATA) return; const $overlay = $('#yec-share-overlay'); const $urlInput = $('#yec-share-url-input'); setExportStatus(''); $urlInput.val('Generating link…'); $overlay.addClass('active').attr('aria-hidden', 'false'); setTimeout(function () { $('#yec-share-close').trigger('focus'); }, 0); $.ajax({ type: 'POST', url: window.location.origin + '/wp-admin/admin-ajax.php', data: { action: 'yt_eng_share_create', data_json: JSON.stringify(window.YEC_DATA) }, success: function (res) { let r; try { r = typeof res === 'string' ? JSON.parse(res) : res; } catch (e) { r = {}; } if (r.success) { $urlInput.val(window.location.href.split('?')[0] + '?yec_share=' + r.token); } else { $urlInput.val('Error generating link. Please try again.'); } }, error: function () { $urlInput.val('Network error. Please try again.'); } }); }); $(document).on('click', '#yec-share-close', closeShareModal); $(document).on('click', '#yec-share-overlay', function (e) { if (e.target === this) closeShareModal(); }); $(document).on('keydown', function (e) { if (e.key === 'Escape' && $('#yec-share-overlay').hasClass('active')) closeShareModal(); }); window.yecCopyShareUrl = function () { const val = $('#yec-share-url-input').val(); if (!val || val.indexOf('Error') === 0 || val.indexOf('Generating') === 0 || val.indexOf('Network') === 0) return; navigator.clipboard.writeText(val).then(function () { const $btn = $('.yec-share-url-row .yec-btn.primary'); $btn.html(' Copied!'); setTimeout(function () { $btn.html(' Copy'); }, 2000); }).catch(function () { $('#yec-share-url-input').select(); document.execCommand('copy'); }); }; // ── Auto-load shared report on page load (?yec_share=TOKEN) ── (function () { const params = new URLSearchParams(window.location.search); const token = params.get('yec_share'); if (!token) { loadPublicStats(); return; } newResultContainer = $('
'); newResultDiv = $('
'); newResultContainer.append(newResultDiv); $('.tool-box').after(newResultContainer); newResultDiv.html('


Loading shared report…
'); $.ajax({ type: 'POST', url: window.location.origin + '/wp-admin/admin-ajax.php', data: { action: 'yt_eng_share_get', token: token }, success: function (res) { let r; try { r = typeof res === 'string' ? JSON.parse(res) : res; } catch (e) { r = {}; } if (r.success && r.data) { window.YEC_DATA = r.data; renderReport(r.data); loadPublicStats(); $('html,body').animate({ scrollTop: newResultDiv.offset().top - 80 }, 300); } else { newResultDiv.html('

Not found

' + ((r && r.error) || 'Share link not found or expired.') + '

'); } }, error: function () { newResultDiv.html('

Error

Failed to load shared report.

'); } }); })(); console.log('✅ Engagement Calculator loaded'); });

Tool Comments