Skip to content

Commit

Permalink
Enable privacy enhanced mode
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed Jan 8, 2025
1 parent ab639f4 commit 061a867
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/sdk-components-react/src/youtube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ type YouTubePlayerParameters = {
*/
autoplay?: boolean;

/**
* The Privacy Enhanced Mode of the YouTube embedded player prevents the use of views of embedded YouTube content from influencing the viewer’s browsing experience on YouTube.
* https://support.google.com/youtube/answer/171780?hl=en#zippy=%2Cturn-on-privacy-enhanced-mode
* @default true
*/
privacyEnhancedMode?: boolean;

/**
* Whether to show player controls.
* @default true
Expand Down Expand Up @@ -148,7 +155,9 @@ type YouTubePlayerOptions = {
loading?: "eager" | "lazy";
};

const PLAYER_CDN = "https://www.youtube.com";
const PLAYER_PRIVACY_ENHANVED_MODE_CDN = "https://www.youtube-nocookie.com";
const PLAYER_ORIGINAL_CDN = "https://www.youtube.com";

const IMAGE_CDN = "https://img.youtube.com";

const getVideoId = (url?: string) => {
Expand All @@ -173,7 +182,10 @@ const getVideoUrl = (options: YouTubePlayerOptions) => {
return;
}

const url = new URL(`${PLAYER_CDN}/embed/${videoId}`);
const privacyEnhancedMode = options.privacyEnhancedMode ?? true;
const url = new URL(
`${privacyEnhancedMode ? PLAYER_PRIVACY_ENHANVED_MODE_CDN : PLAYER_ORIGINAL_CDN}/embed/${videoId}`
);

const optionsKeys = Object.keys(options) as (keyof YouTubePlayerParameters)[];

Expand Down

0 comments on commit 061a867

Please sign in to comment.