Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "do not track" query parameter to vimeo links in the video widget to ensure tracking/analytics cookies don't get set. #795

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-shrimps-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

Add "do not track" query parameter to vimeo links in the video widget to ensure tracking/analytics cookies don't get set.
10 changes: 9 additions & 1 deletion packages/perseus/src/widgets/__stories__/video.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";

import {RendererWithDebugUI} from "../../../../../testing/renderer-with-debug-ui";
import {question1} from "../__testdata__/video.testdata";
import {question1, question2, question3} from "../__testdata__/video.testdata";

export default {
title: "Perseus/Widgets/Video",
Expand All @@ -12,3 +12,11 @@ type StoryArgs = Record<any, any>;
export const Question1 = (args: StoryArgs): React.ReactElement => {
return <RendererWithDebugUI question={question1} />;
};

export const Question2 = (args: StoryArgs): React.ReactElement => {
return <RendererWithDebugUI question={question2} />;
};

export const Question3 = (args: StoryArgs): React.ReactElement => {
return <RendererWithDebugUI question={question3} />;
};
40 changes: 40 additions & 0 deletions packages/perseus/src/widgets/__testdata__/video.testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,43 @@ export const question1: PerseusRenderer = {
},
replace: false,
};

export const question2: PerseusRenderer = {
content:
"Watch the WMF at Angkor Wat video to find the answer.\n\n[[\u2603 video 1]]\n\n",
images: {},
widgets: {
"video 1": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "video",
options: {
static: false,
location: "https://player.vimeo.com/video/4754041",
},
alignment: "block",
},
},
replace: false,
};

export const question3: PerseusRenderer = {
content:
"Watch the WMF at Angkor Wat video to find the answer.\n\n[[\u2603 video 1]]\n\n",
images: {},
widgets: {
"video 1": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "video",
options: {
static: false,
location: "https://player.vimeo.com/video/4754041?h=64fbc32a6e",
},
alignment: "block",
},
},
replace: false,
};
11 changes: 11 additions & 0 deletions packages/perseus/src/widgets/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const DEFAULT_HEIGHT = 720;
const KA_EMBED = "{host}/embed_video?slug={slug}" + "&internal_video_only=1";
const IS_URL = /^https?:\/\//;
const IS_KA_SITE = /(khanacademy\.org|localhost)/;
const IS_VIMEO = /(vimeo\.com)/;

type UserInput = null;
type Rubric = PerseusVideoWidgetOptions;
Expand Down Expand Up @@ -75,6 +76,16 @@ class Video extends React.Component<Props> {

if (IS_URL.test(location)) {
url = location;
if (IS_VIMEO.test(url)) {
// If this is a vimeo video, we need to add the query string
// parameter "dnt" so that analytics/tracking cookies aren't set.
// https://help.vimeo.com/hc/en-us/articles/12426260232977-Player-parameters-overview
if (url.indexOf("?") === -1) {
url += "?dnt=1";
} else {
url += "&dnt=1";
}
Comment on lines +83 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action needed: I think this is fine to ship as-is, but there's also the URLSearchParams API now.

}
} else {
url = KA_EMBED.replace("{slug}", location);
let embedHostname = "https://www.khanacademy.org";
Expand Down
Loading