ExpressionEngine – getting cookie consent for Youtube embedded videos

It’s well known that embedded Youtube videos place tracking cookies into your visitor’s browsers. If you or your clients are privacy conscious that can be a bit unsettling. That’s why it can be a good idea to give your visitors a choice – be tracked or not tracked.

This is a simple example of how to give your visitors that choice with ExpressionEngine’s Cookie Consent module, using the default ee:cookies_targeting consent request.

The basics

You’ll need two custom fields, these can be separate fields or contained in a grid field:

video_embed - for the video embed code video_url - for the direct video URL on the remote site

The template code

We’ll make use of the *= conditional, all this does is look for a matching value in the video_embed field.

{!-- check if video is from youtube --}
{if video_embed *= "youtube"}
  {!-- get consent for youtube tracking cookies --}   
  {exp:consent:requests consent="ee:cookies_targeting"}

    {!-- if consent has already been granted output the video embed code --}
    {if consent_granted}


    {!-- if consent hasn’t been granted show message with option links --}
      Hidden video content: This video is from a site that may set tracking
      cookies and share your personal data with 3rd parties.
      <a href="{video_url}">Watch via direct link</a> or 
      <a href="{consent_grant_url}">Allow tracking cookies and watch here</a>

{!-- if video isn’t from youtube just output the embed code --}   


That’s it, simple eh? You could of course adapt this for any 3rd party embedded content such as Facebook or Google maps.

You might also like

You don't know unless you ask

Contact me today