Iframe cookie consent with YouTube example

Please note that this is no longer being updated. Kindly visit the new Cookiebot support area (https://support.cookiebot.com/hc/en-us) for updated guides, articles and FAQs. If you do not find the answer to your question there, you are welcome to post it in the Cookiebot community (https://support.cookiebot.com/hc/en-us/community/topics).

Website content loaded in iframes from third party content providers like YouTube may set cookies and thereby require the visitor's prior consent.

To hold back cookies until the website visitor has consented, Cookiebot will postpone loading the video until the visitor has consented. On subsequent page requests where the visitor has already submitted a consent, the iframe content will automatically load in accordance with the individual visitors consent state.

To implement prior consent, change the original iframe tag (example):

<iframe src="https://www.youtube.com/embed/xxxxxxxxxxx" frameborder="0" allowfullscreen></iframe>

to the following (rename 'src' to 'data-src' and apply the data-cookieconsent-attribute to the tag):

<iframe data-src="https://www.youtube.com/embed/xxxxxxxxxxx" data-cookieconsent="marketing" frameborder="0" allowfullscreen></iframe>

Replace the example-URL 'https://www.youtube.com/embed/xxxxxxxxxxx' with the URL of you own iframe-src.

Please note that YouTube offers you to serve videos from the alternative domain www.youtube-nocookie.com which is not setting http cookies. Instead the alternative domain is setting persistent "super cookies" in the browsers HTML Locale Storage which also requires consent. 

Display a message if not consented


You can add a placeholder before or after the iframe-tag to show a message to the visitor, when the visitor has not consented to the types of cookies used by the iframe, e.g.:

<div class="cookieconsent-optout-marketing">
  Please <a href="javascript:Cookiebot.renew()">accept marketing-cookies</a> to watch this video.
</div>

Cookiebot will hide the message when the visitor has consented.

Feedback and Knowledge Base