Skip to content

Commit

Permalink
Default Youtube videos to off
Browse files Browse the repository at this point in the history
- previously the consent cookie was always set (to reject all cookies) prior to user choice
- now that we're not doing that, the code that turns links to Youtube videos in govspeak content into embedded videos was checking for the consent cookie, not finding it, and defaulting to... true.
- this meant that videos were appearing on a page before users had consented to cookies
- setting the default value to false seems to be the simplest way to fix this. Videos still initialise automatically as before once cookies are consented to
  • Loading branch information
andysellick committed Mar 8, 2024
1 parent b34a892 commit d21cc1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Expand Up @@ -163,7 +163,7 @@

YoutubeLinkEnhancement.prototype.campaignCookiesAllowed = function () {
var cookiePolicy = window.GOVUK.getConsentCookie()
return cookiePolicy !== null ? cookiePolicy.campaigns : true
return cookiePolicy !== null ? cookiePolicy.campaigns : false
}

YoutubeLinkEnhancement.nextId = function () {
Expand Down
8 changes: 8 additions & 0 deletions spec/javascripts/components/govspeak-spec.js
Expand Up @@ -9,6 +9,14 @@ describe('Govspeak', function () {
})

describe('youtube enhancement', function () {
beforeEach(function () {
window.GOVUK.cookie('cookies_policy', '{"essential":true,"settings":true,"usage":true,"campaigns":true}')
})

afterEach(function () {
window.GOVUK.cookie('cookies_policy', null)
})

it('embeds youtube videos', function () {
container = document.createElement('div')
container.innerHTML =
Expand Down
Expand Up @@ -6,14 +6,16 @@ describe('Youtube link enhancement', function () {
var container

beforeEach(function () {
window.GOVUK.cookie('cookies_policy', '{"essential":true,"settings":true,"usage":true,"campaigns":true}')
container = document.createElement('div')
})

afterEach(function () {
window.GOVUK.cookie('cookies_policy', null)
document.body.removeChild(container)
})

it('replaces a link and it\'s container with a media-player embed', function () {
it('replaces a link and its container with a media-player embed', function () {
container.innerHTML =
'<div class="gem-c-govspeak govuk-govspeak" data-module="govspeak">' +
'<p><a href="https://www.youtube.com/watch?v=0XpAtr24uUQ">Agile at GDS</a></p>' +
Expand Down Expand Up @@ -124,14 +126,16 @@ describe('Youtube link enhancement', function () {
var container

beforeEach(function () {
window.GOVUK.cookie('cookies_policy', '{"essential":true,"settings":true,"usage":true,"campaigns":true}')
container = document.createElement('div')
})

afterEach(function () {
window.GOVUK.cookie('cookies_policy', null)
document.body.removeChild(container)
})

it('replaces a livestream link and it\'s container with a media-player embed', function () {
it('replaces a livestream link and its container with a media-player embed', function () {
container.innerHTML =
'<div class="gem-c-govspeak govuk-govspeak" data-module="govspeak">' +
'<p><a href="https://www.youtube.com/embed/live_stream?channel=UCoMdktPbSTixAyNGwb-UYkQ">Livestream</a></p>' +
Expand Down

0 comments on commit d21cc1e

Please sign in to comment.