Component Reference
This document provides the API reference for all AdSense-related components in the board-web application.
File Structure
app/third-parties/
├── google-ad-sense.jsx # Script loader component
└── google-ad-sense/
├── ad-sense-constants.js # Slot ID constants
├── ad-sense-unit.jsx # Main ad component
├── ad-sense-unit.scss # Styles
└── ad-sense-placeholder.jsx # Dev/QA placeholder
GoogleAdSenseScript
Location: app/third-parties/google-ad-sense.jsx
Loads the AdSense library script in the document <head>. Only renders when VITE_ADSENSE_PUBLISHER_ID is set.
Usage
// In root.jsx Layout component
import { GoogleAdSenseScript } from '@/third-parties/google-ad-sense'
export function Layout({ children }) {
return (
<html>
<head>
<GoogleTagManagerScript />
<GoogleAdSenseScript /> {/* Add after GTM */}
<Meta />
<Links />
</head>
<body>{children}</body>
</html>
)
}
Behavior
| Environment | VITE_ADSENSE_PUBLISHER_ID | Result |
|---|---|---|
| Production | Set | Script tag renders |
| Development | Not set | Returns null |
| QA | Not set | Returns null |
AdSenseUnit
Location: app/third-parties/google-ad-sense/ad-sense-unit.jsx
The main component for displaying ads. Handles environment detection, initialization, and responsive sizing.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
slot | string | required | The AdSense slot ID (from AD_SENSE_UNITS) |
format | string | 'auto' | Ad format: 'auto', 'fluid', 'rectangle', 'horizontal', 'vertical' |
layout | string | undefined | Layout for in-article ads: 'in-article' |
style | object | {} | Additional inline styles |
minHeight | string | '250px' | Minimum height to reserve (prevents CLS) |
className | string | '' | Additional CSS classes for wrapper |
responsiveClass | string | undefined | CSS class for responsive sizing |
Usage Examples
In-Article Fluid Ad
Best for: Between content sections
import AdSenseUnit from '@/third-parties/google-ad-sense/ad-sense-unit'
import AD_SENSE_UNITS from '@/third-parties/google-ad-sense/ad-sense-constants'
<AdSenseUnit
slot={AD_SENSE_UNITS.HOME_AFTER_HERO}
format="fluid"
layout="in-article"
minHeight="100px"
/>
Responsive Horizontal Banner
Best for: Above the fold, fixed positions
<AdSenseUnit
slot={AD_SENSE_UNITS.HOME_HERO}
responsiveClass="ad-sense-horizontal-banner"
/>
Rectangle Ad
Best for: Sidebars, in-content
<AdSenseUnit
slot={AD_SENSE_UNITS.SIDEBAR}
format="rectangle"
minHeight="250px"
/>
Component Logic Flow
AdSensePlaceholder
Location: app/third-parties/google-ad-sense/ad-sense-placeholder.jsx
Visual placeholder shown in development and QA environments.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
width | string | '100%' | Placeholder width |
height | string | '250px' | Placeholder height |
slot | string | 'Auto' | Slot name to display |
className | string | '' | Additional CSS classes |
responsiveClass | string | '' | CSS class for responsive sizing |
Appearance
The placeholder displays:
- "Google AdSense Placeholder" header
- The slot ID/name
- "Visible in Development/QA only" note
- Dashed border styling
AD_SENSE_UNITS
Location: app/third-parties/google-ad-sense/ad-sense-constants.js
Constants for ad slot IDs. Always use these constants instead of hardcoding slot IDs.
Current Slots
const AD_SENSE_UNITS = {
PLACEHOLDER : 'placeholder', // Forces placeholder display
HOME_HERO : '1133995872', // Display ad - hero banner
HOME_AFTER_HERO : '3568603439', // In-article ad - after hero
HOME_LIST_GROUP_ITEM : '8803768184' // In-feed ad - job listings
}
Adding New Slots
- Create the ad unit in Google AdSense Dashboard
- Copy the
data-ad-slotvalue - Add to
ad-sense-constants.js:
const AD_SENSE_UNITS = {
// ... existing slots
NEW_PLACEMENT: '1234567890' // Description of where it's used
}
CSS Classes
Location: app/third-parties/google-ad-sense/ad-sense-unit.scss
.ad-sense-wrapper
Applied to all ad unit wrappers. Used for:
- Hiding unfilled ads via
:has()selector - Applying
minHeightfor CLS prevention
.ad-sense-horizontal-banner
Responsive banner with standard IAB sizes. Breakpoints are designed to work inside Bootstrap columns (e.g., Col lg={7}):
| Breakpoint | Dimensions | Ad Type | Notes |
|---|---|---|---|
| < 576px | 320 x 50 | Mobile Banner | Mobile devices |
| 576-1399px | 468 x 60 | Banner | Tablet through large desktop |
| 1400px+ | 728 x 90 | Leaderboard | Only at xxl when column is wide enough |
Why these breakpoints?
At Bootstrap's lg breakpoint (992-1199px), a Col lg={7} is only ~560px wide. A 728px leaderboard would overflow. We only show the leaderboard at xxl (1400px+) where the column is ~770px wide.
Adding Custom Responsive Classes
// Example: Large rectangle for sidebars
.ad-sense-large-rectangle {
width: 300px;
height: 250px;
margin: 0 auto;
@media (min-width: 992px) {
width: 336px;
height: 280px;
}
}
Environment Variables
VITE_ADSENSE_PUBLISHER_ID
| Environment | Value | Effect |
|---|---|---|
| Production | ca-pub-XXXXXXXX | Real ads load |
| QA | not set | Placeholders shown |
| Development | not set | Placeholders shown |
Configuration Files
The variable must be set in:
.env(local development) - Leave emptyDockerfile- Build arg and runtime envdeploy/deploy.yml- Kamal deployment secrets.github/workflows/ci.yml- CI build args
Type Definitions (JSDoc)
For better IDE support, the components use JSDoc comments:
/**
* @param {Object} props
* @param {string} props.slot - The AdSense slot ID
* @param {string} [props.format='auto'] - Ad format
* @param {string} [props.layout] - Layout for in-article ads
* @param {Object} [props.style={}] - Additional inline styles
* @param {string} [props.minHeight='250px'] - Minimum height
* @param {string} [props.className=''] - Additional CSS classes
* @param {string} [props.responsiveClass] - CSS class for responsive sizing
* @returns {JSX.Element}
*/