Overview
TheYouTubePlayer component embeds YouTube videos with privacy-first design. It wraps the PrivacyEmbed component to provide a consent-based loading mechanism that prevents cookies and tracking until the user explicitly chooses to load the video.
Props
The YouTube video ID (the alphanumeric string after
v= in YouTube URLs)Descriptive title for the video, used for accessibility and the load button
Controls loading behavior (primarily affects the poster image)
Features
Privacy-First Design
The component automatically usesyoutube-nocookie.com domain for enhanced privacy, which:
- Prevents YouTube from setting cookies until the video is played
- Reduces tracking and data collection
- Complies with stricter privacy regulations (GDPR, CCPA)
Consent-Based Loading
Videos display a poster image with a “Load Content” button instead of auto-embedding:- No iframe is loaded until user interaction
- No external requests made on page load
- User explicitly consents to loading YouTube content
Automatic Poster Images
The component automatically fetches the maximum resolution thumbnail from YouTube:Usage Examples
Basic Video Embed
Extract Video ID from URL
Multiple Videos in Grid
How It Works
1. Initial Render
On page load, the component displays:- Video poster image (thumbnail from YouTube)
- Play button overlay
- “Load Content” text
- No iframe or external scripts
2. User Interaction
When the user clicks the play button:- An iframe is dynamically created
- The iframe source is set to
youtube-nocookie.com - The facade (poster + button) is hidden
- The video player becomes interactive
3. Video Playback
The embedded player includes standard YouTube features:- Full screen support
- Playback controls
- Quality selection
- Captions (if available)
Privacy Benefits
Using
youtube-nocookie.com significantly reduces privacy concerns by preventing YouTube from tracking users across sites until they explicitly choose to watch the video.Privacy Comparison
| Feature | Standard Embed | YouTubePlayer |
|---|---|---|
| Cookies on page load | Yes | No |
| External requests on load | Multiple | One (poster image only) |
| User tracking | Immediate | Only after consent |
| GDPR compliant | Requires banner | Built-in consent |
Styling
The component includes default styling:aspect-video: Maintains 16:9 aspect ratioh-auto: Responsive heightmin-h-100: Minimum height constraintw-full: Full width of containerrounded-lg: Rounded corners
Accessibility
- Semantic
<button>element for interaction - Descriptive
aria-labelon load button - Proper
titleattribute on iframe - Keyboard accessible (click handler works with Enter/Space)
Performance
Performance Metrics
- Blocked resources: ~15-20 YouTube scripts prevented until user consent
- Saved bandwidth: ~500KB-1MB per video embed
- Reduced cookies: 10+ cookies not set until interaction
Technical Details
Generated URLs
Embed URL:Iframe Permissions
The dynamically created iframe includes:Related Components
- PrivacyEmbed - The underlying privacy wrapper
- SoundCloudPlayer - Audio player component