From 42496331b7f0b8b2af300d1fcf32e19ea745d14b Mon Sep 17 00:00:00 2001 From: Simon Thorley Date: Fri, 13 Nov 2026 16:12:01 +0000 Subject: [PATCH 1/4] feat(web): enable live Google AdSense unit and compact slot layout --- TODO.md | 5 +- apps/web/src/components/MonetizationSlot.tsx | 111 +++++++++++------- .../__tests__/MonetizationSlot.spec.tsx | 37 +++++- infra/tofu/variables.tf | 10 +- 4 files changed, 113 insertions(+), 50 deletions(-) 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..004294b 100644 --- a/apps/web/src/components/MonetizationSlot.tsx +++ b/apps/web/src/components/MonetizationSlot.tsx @@ -120,20 +120,45 @@ 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 mode = (import.meta.env.VITE_MONETIZATION_MODE as MonetizationMode) || 'live'; + 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 +169,77 @@ 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) { + // Graceful degradation when ad blocker is active or ad slot is unfilled + if (adBlocked || adUnfilled) { return null; } 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 -
-
-
- + // Compact, low-profile dark-mode mock creative +
+
+
+
-
+
Aegis Flight Systems & Precision HOTAS Mounts
-

+

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

@@ -218,18 +248,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 +
{ }); 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,9 +70,10 @@ 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(); @@ -67,9 +84,10 @@ describe('Monetization Components', () => { } unmount(); + document.head.innerHTML = ''; // Trigger onerror for adblock detection - const { container: container2 } = render(); + render(); const script2 = document.querySelector('script[src*="adsbygoogle.js"]') as HTMLScriptElement; if (script2 && script2.onerror) { (script2 as any).onerror(new Event('error')); @@ -77,5 +95,20 @@ describe('Monetization Components', () => { 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(); + }); }); }); 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" } From b3a4b136df11107281a711cb91d242aa6afcf0a5 Mon Sep 17 00:00:00 2001 From: Simon Thorley Date: Fri, 13 Nov 2026 16:21:05 +0000 Subject: [PATCH 2/4] fix(web): prevent svg w-* wildcard CSS rule from collapsing containers and show fallback on unfilled preview --- apps/web/src/components/MonetizationSlot.tsx | 17 +++++++---------- apps/web/src/index.css | 15 ++++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/MonetizationSlot.tsx b/apps/web/src/components/MonetizationSlot.tsx index 004294b..ac79a07 100644 --- a/apps/web/src/components/MonetizationSlot.tsx +++ b/apps/web/src/components/MonetizationSlot.tsx @@ -201,15 +201,12 @@ export const AdSenseSlot: React.FC = ({ className = '' }) => return null; } - // Graceful degradation when ad blocker is active or ad slot is unfilled - if (adBlocked || adUnfilled) { - return null; - } + const showFallbackCreative = mode === 'mock' || adBlocked || adUnfilled; return (
@@ -228,9 +225,9 @@ export const AdSenseSlot: React.FC = ({ className = '' }) =>
- {mode === 'mock' ? ( - // Compact, low-profile dark-mode mock creative -
+ {showFallbackCreative ? ( + // Compact, low-profile dark-mode creative (used in mock mode or when AdSense is blocked/unfilled on preview domains) +
@@ -255,8 +252,8 @@ export const AdSenseSlot: React.FC = ({ className = '' }) =>
) : ( - // Official Google AdSense Default Ad Unit -
+ // Official Google AdSense Default Ad Unit (block container ensures non-zero availableWidth on push) +
Date: Fri, 13 Nov 2026 16:27:49 +0000 Subject: [PATCH 3/4] test(web): add regression coverage for AdSense fallback, CSS width selectors, and E2E boundingBox --- .../__tests__/MonetizationSlot.spec.tsx | 45 ++++++++++++++++--- e2e/app-workflow.spec.ts | 10 +++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx b/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx index bbf0a8a..e9749dd 100644 --- a/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx +++ b/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx @@ -1,6 +1,8 @@ import React from 'react'; -import { describe, it, expect } from 'vitest'; -import { render, screen } from '@testing-library/react'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { describe, it, expect, vi } from 'vitest'; +import { render, screen, act, waitFor } from '@testing-library/react'; import { SupporterFuelBadge, HardwareAffiliateCard, @@ -80,19 +82,45 @@ describe('Monetization Components', () => { // 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 + // 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(); }); @@ -110,5 +138,12 @@ describe('Monetization Components', () => { 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/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 }) => { From 4a9fb4603f0c3006c5b9fbeffc511e3ceb32a337 Mon Sep 17 00:00:00 2001 From: Simon Thorley Date: Fri, 13 Nov 2026 16:37:12 +0000 Subject: [PATCH 4/4] feat(web): auto-enable live AdSense mode on scbind.com production hostname --- apps/web/src/components/MonetizationSlot.tsx | 7 +++++- .../__tests__/MonetizationSlot.spec.tsx | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/MonetizationSlot.tsx b/apps/web/src/components/MonetizationSlot.tsx index ac79a07..facee6a 100644 --- a/apps/web/src/components/MonetizationSlot.tsx +++ b/apps/web/src/components/MonetizationSlot.tsx @@ -120,7 +120,12 @@ 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) || 'live'; + 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' diff --git a/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx b/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx index e9749dd..f98cb24 100644 --- a/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx +++ b/apps/web/src/components/__tests__/MonetizationSlot.spec.tsx @@ -139,6 +139,29 @@ describe('Monetization Components', () => { 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');