[Drupal] Preventing cookies from embedded video

Little, Jason P. little.129 at osu.edu
Fri Mar 19 10:47:21 EDT 2021


Nice. This is cool.

One thought. If you do this, I believe it prevents the embedded videos from being used in personalization algorithms for the user on youtube.com.

So you’ll likely be giving the user more privacy at the expense of some small portion of your YouTube channel reach.

As third party cookies slowly get phased out by browsers, the point may become moot anyway. Also, I think it’s questionable how much of a boost in reach having these cookies on would deliver since subject is probably at least as important as channel in personalization and the university has a somewhat fragmented channel strategy to begin with.

Best,
Jason

From: Drupal <drupal-bounces at lists.osu.edu> on behalf of Hopkins-Lutz, Richard via Drupal <drupal at lists.osu.edu>
Date: Thursday, March 18, 2021 at 7:58 AM
To: drupal at lists.osu.edu <drupal at lists.osu.edu>
Subject: [Drupal] Preventing cookies from embedded video
Hey Drupal folks.

Working with Ken Phillips on GDPR/Privacy compliance, I crafted some code for Drupal 8 for preventing cookies from Youtube and Vimeo, and figured I would share it.

This is for Drupal 8, using its core oEmbed system, and should be universal if you use those:

use Drupal\media\IFrameMarkup;
use Drupal\media\OEmbed\Provider;

/**
 * Implements hook_oembed_resource_url_alter().
 */
function mymodule_oembed_resource_url_alter(array &$parsed_url, Provider $provider)
{
  // Add Do Not Track flag to Vimeo oEmbed requests
  if ($provider->getName() === 'Vimeo') {
    $parsed_url['query']['dnt'] = true;
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function mymodule_preprocess_media_oembed_iframe(&$variables)
{
  // Pull iframe tag
  $iFrame = $variables['media']->__toString();
  // Switch domain to the youtube nocookie domain.
  if (stripos($iFrame, 'youtube.com') !== false){
    $newFrame = str_replace('youtube.com/', 'youtube-nocookie.com/', $iFrame);
    $variables['media'] = IFrameMarkup::create($newFrame);
  }
}
Hope this helps a few of you.

[The Ohio State University]
Richard Hopkins-Lutz
Web Services Manager
College of Engineering Engineering Technology Services
hopkins-lutz.1 at osu.edu<mailto:hopkins-lutz.1 at osu.edu> osu.edu<http://osu.edu/>
He/Him/His/Mr.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osu.edu/pipermail/drupal/attachments/20210319/26c3e330/attachment.html>


More information about the Drupal mailing list