/** * Main Orchestrator — entry point */ (function () { 'use strict'; var App = window.BenchmarkApp; document.addEventListener('DOMContentLoaded', function () { // 1. Parse GET params var params = App.parseParams(); if (!params) { App.renderFallbackScreen(); return; } // Show report container document.getElementById('report').style.display = 'block'; // 2. Calculate scoring var scoring = App.calculateScoring(params); // 3. Calculate recommendations var recommendations = App.calculateRecommendations(scoring); // 4. Determine A/B variant var variant = App.getVariant(); // 5. Render tier block (always visible) App.renderTierBlock(scoring, params); // 6. Setup variant layout var recsSection = document.getElementById('recommendations-section'); var gatedContent = document.getElementById('gated-content'); // Both variants: recommendations + top-3 under blur, gate right after tier block var top3 = document.getElementById('top3-section'); gatedContent.insertBefore(recsSection, top3); recsSection.classList.add('in-gate'); App.renderRecommendationCards(recommendations, scoring.tier); App.renderPlaceholderTables(); // 7. Render email gate overlay and apply blur App.renderEmailGate(); App.applyBlur(); // 8. Track analytics App.trackEvent('benchmark_report_view', { industry: params.industry, tier: scoring.tier, ab_variant: variant }); App.trackEvent('benchmark_variant_shown', { variant: variant }); App.trackEvent('benchmark_email_gate_shown', { variant: variant }); // 9. Wire up email form document.getElementById('email-form').addEventListener('submit', function (e) { e.preventDefault(); App.clearGateError(); var form = e.target; // Bot check if (App.isBot(form)) return; var emailInput = document.getElementById('gate-email'); var email = emailInput.value.trim(); if (!email) { App.showGateError('Please enter your email address.'); emailInput.focus(); return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { App.showGateError('Please enter a valid email address.'); emailInput.focus(); return; } App.trackEvent('benchmark_email_submitted', { industry: params.industry, tier: scoring.tier, variant: variant }); App.showSpinner(); App.submitEmail(email, params, scoring, recommendations, variant) .then(function (data) { App.hideSpinner(); if (data && data.top_companies) { // Success: render real tables and remove blur App.renderTop3Tables(data.top_companies, params.companyRaw); // Make recs visible now recsSection.classList.remove('in-gate'); App.removeBlur(); App.trackEvent('benchmark_report_unlocked', { industry: params.industry, tier: scoring.tier, variant: variant }); } else { // Fallback: webhook failed after retries App.showFallbackMessage(email); // Unlock recs (they're client-side) gatedContent.parentNode.insertBefore(recsSection, gatedContent); recsSection.classList.remove('in-gate'); App.removeBlur(); } }); }); // 10. Retry any pending submission from previous failed attempt App.retryPendingSubmission(); }); })();