Skip to main content

Block YouTube Embeds Until Consent

YouTube embeds set marketing/advertising cookies the moment the iframe loads — even without autoplay.

Step 1: Replace src with data-src

<!-- Before: loads immediately -->
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
width="560" height="315" frameborder="0"></iframe>

<!-- After: blocked until marketing consent -->
<iframe
data-src="https://www.youtube.com/embed/VIDEO_ID"
data-consent-category="marketing"
width="560" height="315"
frameborder="0"
allowfullscreen>
</iframe>

Show users what they're missing and give them a quick consent path:

<div class="video-consent-wrapper" data-consent-category="marketing">
<iframe
data-src="https://www.youtube.com/embed/VIDEO_ID"
data-consent-category="marketing"
width="560" height="315" frameborder="0">
</iframe>
<div class="video-placeholder">
<p>This video requires marketing cookies.</p>
<button data-cf-action="accept-category" data-cf-category="marketing">
Accept and play
</button>
</div>
</div>

Step 3: Use YouTube's privacy-enhanced mode

Even with consent, use the no-cookie domain to minimise tracking:

https://www.youtube-nocookie.com/embed/VIDEO_ID

Verification

Open DevTools → Network before consenting. No request to youtube.com or youtube-nocookie.com should appear. After accepting marketing consent, the iframe should load and the network request should appear.