Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---

Expand Down
119 changes: 76 additions & 43 deletions apps/web/src/components/MonetizationSlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,50 @@ export const HardwareAffiliateCard: React.FC<MonetizationProps> = ({ className =
* AdSenseSlot: Aesthetic, sci-fi container with test mode / mock mode and automatic adblock fallback.
*/
export const AdSenseSlot: React.FC<MonetizationProps> = ({ 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<boolean>(false);
const [isLoaded, setIsLoaded] = useState<boolean>(false);
const [adUnfilled, setAdUnfilled] = useState<boolean>(false);
const [, setIsLoaded] = useState<boolean>(false);
const insRef = React.useRef<HTMLModElement | null>(null);
const pushedRef = React.useRef<boolean>(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;
Expand All @@ -144,72 +174,74 @@ export const AdSenseSlot: React.FC<MonetizationProps> = ({ 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 (
<div
data-testid="monetization-slot-container"
className={`relative rounded-xl border border-slate-800/90 bg-slate-950/80 p-3 overflow-hidden backdrop-blur-md shadow-md ${className}`}
className={`relative w-full rounded-lg border border-slate-800/60 bg-slate-950/50 px-3 py-2 overflow-hidden backdrop-blur-sm ${className}`}
>
<div className="flex items-center justify-between pb-2 mb-2 border-b border-slate-800/60 text-[10px] font-mono text-slate-300">
<div className="flex items-center gap-1.5 text-cyan-400">
<Radio className="w-3 h-3 animate-pulse" />
<span className="tracking-wider uppercase font-semibold">
<div className="flex items-center justify-between pb-1.5 mb-1.5 border-b border-slate-800/40 text-[9px] font-mono text-slate-400">
<div className="flex items-center gap-1.5 text-slate-400">
<Radio className="w-2.5 h-2.5 text-cyan-500/70" />
<span className="tracking-wider uppercase font-medium">
{mode === 'live' ? 'SPONSOR COMM TRANSMISSION' : 'SPONSOR COMM // SIMULATOR MODE'}
</span>
</div>
<div className="flex items-center gap-2">
{mode !== 'live' && (
<span className="px-1.5 py-0.5 rounded bg-emerald-950/60 border border-emerald-700/50 text-emerald-300 font-mono text-[9px]">
<span className="px-1.5 py-0.2 rounded bg-emerald-950/40 border border-emerald-700/40 text-emerald-400/90 font-mono text-[8px]">
SAFE TEST ACTIVE
</span>
)}
<span className="text-slate-300">Supports Hosting</span>
<span className="text-slate-500">Supports Hosting</span>
</div>
</div>

{mode === 'mock' ? (
// High-fidelity dark-mode mock creative to verify layout and aesthetics
<div className="flex flex-col sm:flex-row items-center justify-between gap-4 p-4 rounded-lg border border-slate-800/70 bg-gradient-to-r from-slate-900/60 via-slate-900/40 to-cyan-950/20">
<div className="flex items-center gap-3">
<div className="p-2.5 rounded-lg bg-cyan-950/40 border border-cyan-800/40 text-cyan-400">
<Sparkles className="w-5 h-5" />
{showFallbackCreative ? (
// Compact, low-profile dark-mode creative (used in mock mode or when AdSense is blocked/unfilled on preview domains)
<div className="flex flex-col sm:flex-row items-center justify-between gap-2.5 px-3 py-1.5 rounded-md border border-slate-800/50 bg-slate-900/40">
<div className="flex items-center gap-2.5">
<div className="p-1.5 rounded bg-cyan-950/30 border border-cyan-800/30 text-cyan-400/80 shrink-0">
<Sparkles className="w-3.5 h-3.5" />
</div>
<div>
<div className="text-xs font-bold text-slate-100 tracking-wide">
<div className="text-[11px] font-semibold text-slate-200 tracking-wide">
Aegis Flight Systems & Precision HOTAS Mounts
</div>
<p className="text-[11px] text-slate-300 mt-0.5">
<p className="text-[10px] text-slate-400 leading-tight">
Zero-flex flight stick positioning engineered specifically for high-G space combat simulation.
</p>
</div>
Expand All @@ -218,18 +250,19 @@ export const AdSenseSlot: React.FC<MonetizationProps> = ({ 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"
>
<span>Learn More</span>
<ExternalLink className="w-3 h-3" />
<ExternalLink className="w-2.5 h-2.5" />
</a>
</div>
) : (
// Official Google AdSense slot with sandbox/test attributes
<div className="min-h-[90px] flex items-center justify-center overflow-hidden">
// Official Google AdSense Default Ad Unit (block container ensures non-zero availableWidth on push)
<div className="w-full min-h-[60px] overflow-hidden">
<ins
ref={insRef}
className="adsbygoogle"
style={{ display: 'block', minHeight: '90px', width: '100%' }}
style={{ display: 'block', width: '100%' }}
data-ad-client={clientId}
data-ad-slot={slotId}
data-ad-format="auto"
Expand Down
105 changes: 98 additions & 7 deletions apps/web/src/components/__tests__/MonetizationSlot.spec.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -37,13 +39,29 @@ describe('Monetization Components', () => {
});

describe('AdSenseSlot', () => {
it('renders live Google AdSense unit by default with publisher and slot IDs', () => {
const { container } = render(<AdSenseSlot />);
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(<AdSenseSlot />);
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', () => {
Expand All @@ -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(<AdSenseSlot />);
const { unmount } = render(<AdSenseSlot />);

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(<AdSenseSlot />);
// Trigger onerror for adblock detection and verify graceful fallback creative remains visible
render(<AdSenseSlot />);
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(<AdSenseSlot />);

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(<AdSenseSlot />);
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(<AdSenseSlot />);
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/);
});
});
});
15 changes: 8 additions & 7 deletions apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
10 changes: 10 additions & 0 deletions e2e/app-workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Loading
Loading