diff --git a/TODO.md b/TODO.md index 2dcfb44..82bb906 100644 --- a/TODO.md +++ b/TODO.md @@ -28,9 +28,8 @@ This document tracks optional items, future stage milestones, and deferred confi - [ ] **Flight Hardware Partnerships (VKB / VIRPIL)**: - Apply to VKB-Sim and VIRPIL Controls creator/partner programs. - Update `VITE_AFFILIATE_VKB_TAG` and `VITE_AFFILIATE_VIRPIL_TAG`. -- [ ] **Google AdSense Approval**: - - Submit `scbind.com` to Google AdSense review. - - Replace sandbox ID `ca-pub-0000000000000000` with live publisher ID and switch `VITE_MONETIZATION_MODE=live`. +- [x] **Google AdSense Integration**: + - Configured `scbind.com` with live publisher ID (`ca-pub-4414971156573564`), ad unit slot ID (`9700539154`), `ads.txt`, and `VITE_MONETIZATION_MODE=live`. --- diff --git a/apps/web/src/components/MonetizationSlot.tsx b/apps/web/src/components/MonetizationSlot.tsx index f363966..facee6a 100644 --- a/apps/web/src/components/MonetizationSlot.tsx +++ b/apps/web/src/components/MonetizationSlot.tsx @@ -120,20 +120,50 @@ export const HardwareAffiliateCard: React.FC = ({ className = * AdSenseSlot: Aesthetic, sci-fi container with test mode / mock mode and automatic adblock fallback. */ export const AdSenseSlot: React.FC = ({ className = '' }) => { - const mode = (import.meta.env.VITE_MONETIZATION_MODE as MonetizationMode) || 'mock'; - const clientId = import.meta.env.VITE_ADSENSE_CLIENT_ID || 'ca-pub-4414971156573564'; - const slotId = import.meta.env.VITE_ADSENSE_SLOT_ID || '0000000000'; + const envMode = (import.meta.env.VITE_MONETIZATION_MODE as MonetizationMode) || 'live'; + const isProductionHostname = + typeof window !== 'undefined' && + (window.location.hostname === 'scbind.com' || window.location.hostname.endsWith('.scbind.com')); + const mode: MonetizationMode = + envMode === 'off' ? 'off' : isProductionHostname ? 'live' : envMode; + const rawClientId = import.meta.env.VITE_ADSENSE_CLIENT_ID; + const clientId = + rawClientId && rawClientId !== 'ca-pub-0000000000000000' + ? rawClientId + : 'ca-pub-4414971156573564'; + const rawSlotId = import.meta.env.VITE_ADSENSE_SLOT_ID; + const slotId = + rawSlotId && rawSlotId !== '0000000000' + ? rawSlotId + : '9700539154'; const [adBlocked, setAdBlocked] = useState(false); - const [isLoaded, setIsLoaded] = useState(false); + const [adUnfilled, setAdUnfilled] = useState(false); + const [, setIsLoaded] = useState(false); + const insRef = React.useRef(null); + const pushedRef = React.useRef(false); useEffect(() => { if (mode === 'off') return; if (mode === 'test' || mode === 'live') { + const pushAd = () => { + if (pushedRef.current) return; + try { + pushedRef.current = true; + // @ts-ignore + (window.adsbygoogle = window.adsbygoogle || []).push({}); + } catch (err) { + console.warn('[AdSense] Push execution error:', err); + } + }; + try { - // Attempt to load Google AdSense script dynamically if not present - if (!document.querySelector('script[src*="adsbygoogle.js"]')) { + const existingScript = document.querySelector( + 'script[src*="adsbygoogle.js"]' + ) as HTMLScriptElement | null; + + if (!existingScript) { const script = document.createElement('script'); script.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${clientId}`; script.async = true; @@ -144,72 +174,74 @@ export const AdSenseSlot: React.FC = ({ className = '' }) => }; script.onload = () => { setIsLoaded(true); - try { - // @ts-ignore - (window.adsbygoogle = window.adsbygoogle || []).push({}); - } catch (err) { - console.warn('[AdSense] Push execution error:', err); - } + pushAd(); }; document.head.appendChild(script); } else { + existingScript.addEventListener('error', () => setAdBlocked(true)); setIsLoaded(true); - try { - // @ts-ignore - (window.adsbygoogle = window.adsbygoogle || []).push({}); - } catch (err) { - console.warn('[AdSense] Push execution error:', err); - } + pushAd(); } } catch (e) { setAdBlocked(true); } } - }, [mode, clientId]); + }, [mode, clientId, slotId]); + + // Watch for AdSense marking the slot as unfilled so we don't leave a blank box + useEffect(() => { + const el = insRef.current; + if (!el || typeof MutationObserver === 'undefined') return; + + const observer = new MutationObserver(() => { + if (el.getAttribute('data-ad-status') === 'unfilled') { + setAdUnfilled(true); + } + }); + observer.observe(el, { attributes: true, attributeFilter: ['data-ad-status'] }); + return () => observer.disconnect(); + }, [mode]); if (mode === 'off') { return null; } - // Graceful degradation when ad blocker is active: seamlessly hide container or show sleek hardware fallback - if (adBlocked) { - return null; - } + const showFallbackCreative = mode === 'mock' || adBlocked || adUnfilled; return (
-
-
- - +
+
+ + {mode === 'live' ? 'SPONSOR COMM TRANSMISSION' : 'SPONSOR COMM // SIMULATOR MODE'}
{mode !== 'live' && ( - + SAFE TEST ACTIVE )} - Supports Hosting + Supports Hosting
- {mode === 'mock' ? ( - // High-fidelity dark-mode mock creative to verify layout and aesthetics -
-
-
- + {showFallbackCreative ? ( + // Compact, low-profile dark-mode creative (used in mock mode or when AdSense is blocked/unfilled on preview domains) +
+
+
+
-
+
Aegis Flight Systems & Precision HOTAS Mounts
-

+

Zero-flex flight stick positioning engineered specifically for high-G space combat simulation.

@@ -218,18 +250,19 @@ export const AdSenseSlot: React.FC = ({ className = '' }) => href="https://www.amazon.com/s?k=hotas+desk+mount" target="_blank" rel="noopener noreferrer" - className="flex-shrink-0 px-3 py-1.5 rounded text-xs font-mono font-medium border border-cyan-500/40 bg-cyan-950/50 text-cyan-300 hover:bg-cyan-900/40 hover:border-cyan-400 transition-all duration-150 flex items-center gap-1" + className="flex-shrink-0 px-2.5 py-1 rounded text-[10px] font-mono font-medium border border-cyan-500/30 bg-cyan-950/30 text-cyan-300 hover:bg-cyan-900/30 hover:border-cyan-400 transition-all duration-150 flex items-center gap-1" > Learn More - +
) : ( - // Official Google AdSense slot with sandbox/test attributes -
+ // Official Google AdSense Default Ad Unit (block container ensures non-zero availableWidth on push) +
{ }); describe('AdSenseSlot', () => { + it('renders live Google AdSense unit by default with publisher and slot IDs', () => { + const { container } = render(); + const slotContainer = screen.getByTestId('monetization-slot-container'); + expect(slotContainer).toBeDefined(); + expect(screen.getByText(/SPONSOR COMM TRANSMISSION/i)).toBeDefined(); + + const ins = container.querySelector('ins.adsbygoogle'); + expect(ins).not.toBeNull(); + expect(ins?.getAttribute('data-ad-client')).toBe('ca-pub-4414971156573564'); + expect(ins?.getAttribute('data-ad-slot')).toBe('9700539154'); + expect(ins?.getAttribute('data-ad-format')).toBe('auto'); + expect(ins?.getAttribute('data-full-width-responsive')).toBe('true'); + }); + it('renders mock simulator creative when in mock mode without breaking layout', () => { + vi.stubEnv('VITE_MONETIZATION_MODE', 'mock'); render(); const container = screen.getByTestId('monetization-slot-container'); expect(container).toBeDefined(); expect(screen.getByText(/SPONSOR COMM \/\/ SIMULATOR MODE/i)).toBeDefined(); expect(screen.getByText(/SAFE TEST ACTIVE/i)).toBeDefined(); expect(screen.getByText(/Aegis Flight Systems & Precision HOTAS Mounts/i)).toBeDefined(); + vi.unstubAllEnvs(); }); it('returns null when mode is off', () => { @@ -54,28 +72,101 @@ describe('Monetization Components', () => { }); it('injects script in test/live mode and handles onload and onerror', () => { + document.head.innerHTML = ''; vi.stubEnv('VITE_MONETIZATION_MODE', 'test'); vi.stubEnv('VITE_ADSENSE_CLIENT_ID', 'ca-pub-test1234'); - const { container, unmount } = render(); + const { unmount } = render(); const script = document.querySelector('script[src*="adsbygoogle.js"]') as HTMLScriptElement; expect(script).toBeDefined(); // Trigger onload if (script && script.onload) { - (script as any).onload(new Event('load')); + act(() => { + (script as any).onload(new Event('load')); + }); } unmount(); + document.head.innerHTML = ''; - // Trigger onerror for adblock detection - const { container: container2 } = render(); + // Trigger onerror for adblock detection and verify graceful fallback creative remains visible + render(); const script2 = document.querySelector('script[src*="adsbygoogle.js"]') as HTMLScriptElement; if (script2 && script2.onerror) { - (script2 as any).onerror(new Event('error')); + act(() => { + (script2 as any).onerror(new Event('error')); + }); } + expect(screen.getByTestId('monetization-slot-container')).toBeDefined(); + expect(screen.getByText(/Aegis Flight Systems & Precision HOTAS Mounts/i)).toBeDefined(); + + vi.unstubAllEnvs(); + }); + + it('gracefully renders compact fallback banner when AdSense marks slot as unfilled (e.g. preview domains)', async () => { + vi.stubEnv('VITE_MONETIZATION_MODE', 'live'); + const { container } = render(); + + const ins = container.querySelector('ins.adsbygoogle'); + expect(ins).not.toBeNull(); + + act(() => { + ins?.setAttribute('data-ad-status', 'unfilled'); + }); + + await waitFor(() => { + expect(screen.getByTestId('monetization-slot-container')).toBeDefined(); + expect(screen.getByText(/Aegis Flight Systems & Precision HOTAS Mounts/i)).toBeDefined(); + }); + vi.unstubAllEnvs(); }); + + it('falls back from placeholder ca-pub-0000000000000000 client ID and 0000000000 slot ID', () => { + vi.stubEnv('VITE_MONETIZATION_MODE', 'live'); + vi.stubEnv('VITE_ADSENSE_CLIENT_ID', 'ca-pub-0000000000000000'); + vi.stubEnv('VITE_ADSENSE_SLOT_ID', '0000000000'); + + const { container } = render(); + const ins = container.querySelector('ins.adsbygoogle'); + expect(ins).not.toBeNull(); + expect(ins?.getAttribute('data-ad-client')).toBe('ca-pub-4414971156573564'); + expect(ins?.getAttribute('data-ad-slot')).toBe('9700539154'); + expect(ins?.getAttribute('data-ad-format')).toBe('auto'); + + vi.unstubAllEnvs(); + }); + + it('forces live mode on scbind.com even when VITE_MONETIZATION_MODE is set to test in Cloudflare build env', () => { + vi.stubEnv('VITE_MONETIZATION_MODE', 'test'); + const originalLocation = window.location; + Object.defineProperty(window, 'location', { + configurable: true, + value: { ...originalLocation, hostname: 'scbind.com' } + }); + + const { container } = render(); + expect(screen.getByText(/SPONSOR COMM TRANSMISSION/i)).toBeDefined(); + expect(screen.queryByText(/SAFE TEST ACTIVE/i)).toBeNull(); + + const ins = container.querySelector('ins.adsbygoogle'); + expect(ins).not.toBeNull(); + expect(ins?.getAttribute('data-adtest')).toBeNull(); + + Object.defineProperty(window, 'location', { + configurable: true, + value: originalLocation + }); + vi.unstubAllEnvs(); + }); + + it('prevents unscoped [class*="w-*"] CSS substring selectors in index.css from collapsing layout containers', () => { + const cssPath = path.resolve(__dirname, '../../index.css'); + const cssContent = fs.readFileSync(cssPath, 'utf-8'); + expect(cssContent).not.toMatch(/,\s*\[class\*="w-\d/); + expect(cssContent).not.toMatch(/,\s*\[class\*="h-\d/); + }); }); }); diff --git a/apps/web/src/index.css b/apps/web/src/index.css index e8b404e..66a153f 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -192,13 +192,14 @@ svg { display: inline-block; } -svg.w-3, svg.h-3, [class*="w-3"] { width: 12px; height: 12px; } -svg.w-3\.5, svg.h-3\.5, [class*="w-3.5"] { width: 14px; height: 14px; } -svg.w-4, svg.h-4, [class*="w-4"] { width: 16px; height: 16px; } -svg.w-5, svg.h-5, [class*="w-5"] { width: 20px; height: 20px; } -svg.w-6, svg.h-6, [class*="w-6"] { width: 24px; height: 24px; } -svg.w-7, svg.h-7, [class*="w-7"] { width: 28px; height: 28px; } -svg.w-8, svg.h-8, [class*="w-8"] { width: 32px; height: 32px; } +svg.w-2\.5, svg.h-2\.5 { width: 10px; height: 10px; } +svg.w-3, svg.h-3 { width: 12px; height: 12px; } +svg.w-3\.5, svg.h-3\.5 { width: 14px; height: 14px; } +svg.w-4, svg.h-4 { width: 16px; height: 16px; } +svg.w-5, svg.h-5 { width: 20px; height: 20px; } +svg.w-6, svg.h-6 { width: 24px; height: 24px; } +svg.w-7, svg.h-7 { width: 28px; height: 28px; } +svg.w-8, svg.h-8 { width: 32px; height: 32px; } /* Display & Flexbox Utilities */ .flex { display: flex; } diff --git a/e2e/app-workflow.spec.ts b/e2e/app-workflow.spec.ts index 71711fa..f9fd821 100644 --- a/e2e/app-workflow.spec.ts +++ b/e2e/app-workflow.spec.ts @@ -220,6 +220,16 @@ test.describe('Star Citizen Keybinding Architect E2E UX Suite', () => { const closeReferralModal = referralModal.getByRole('button', { name: 'Close', exact: true }); await closeReferralModal.click(); await expect(referralModal).not.toBeVisible(); + + // 6. Verify AdSense / Sponsor slot container is visible and has a non-collapsed, compact bounding box + const adSlot = page.getByTestId('monetization-slot-container'); + await expect(adSlot).toBeVisible(); + await expect(adSlot).toContainText(/SPONSOR COMM/i); + const adBox = await adSlot.boundingBox(); + expect(adBox).not.toBeNull(); + expect(adBox!.width).toBeGreaterThan(300); + expect(adBox!.height).toBeGreaterThanOrEqual(45); + expect(adBox!.height).toBeLessThanOrEqual(220); }); test('opens and dismisses Hardware Studio modal', async ({ page }) => { diff --git a/infra/tofu/variables.tf b/infra/tofu/variables.tf index a9ebd2a..978e268 100644 --- a/infra/tofu/variables.tf +++ b/infra/tofu/variables.tf @@ -99,9 +99,9 @@ variable "supporter_url" { } variable "monetization_mode" { - description = "Monetization display mode ('test', 'mock', 'live', or 'off'). Defaults to automatic ('test' during Zero Trust staging, 'live' upon public release)." + description = "Monetization display mode ('test', 'mock', 'live', or 'off'). Defaults to 'live'." type = string - default = "" + default = "live" } variable "affiliate_amazon_tag" { @@ -111,13 +111,13 @@ variable "affiliate_amazon_tag" { } variable "adsense_client_id" { - description = "Google AdSense Publisher Client ID (e.g., ca-pub-0000000000000000)." + description = "Google AdSense Publisher Client ID (e.g., ca-pub-4414971156573564)." type = string - default = "ca-pub-0000000000000000" + default = "ca-pub-4414971156573564" } variable "adsense_slot_id" { description = "Google AdSense Slot ID." type = string - default = "0000000000" + default = "9700539154" }