From 3186c281ddd313c5faa3c7401b1b343e178618c9 Mon Sep 17 00:00:00 2001 From: olga-jwp Date: Thu, 21 Mar 2024 15:39:09 +0100 Subject: [PATCH] feat(project): OWA-56 add DRM check for CDN analytics --- packages/common/src/utils/analytics.ts | 25 ++++++++++++++++++------- packages/common/types/settings.ts | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/common/src/utils/analytics.ts b/packages/common/src/utils/analytics.ts index aac42e5b8..4b55ed067 100644 --- a/packages/common/src/utils/analytics.ts +++ b/packages/common/src/utils/analytics.ts @@ -5,10 +5,12 @@ import type { PlaylistItem, Source } from '../../types/playlist'; export const attachAnalyticsParams = (item: PlaylistItem) => { // @todo pass these as params instead of reading the stores - const { config } = useConfigStore.getState(); + const { config, settings } = useConfigStore.getState(); const { user } = useAccountStore.getState(); const { profile } = useProfileStore.getState(); + const vendorId = settings.vendorId; + const { sources, mediaid } = item; const userId = user?.id; @@ -17,22 +19,31 @@ export const attachAnalyticsParams = (item: PlaylistItem) => { sources.map((source: Source) => { const url = new URL(source.file); + const urlSearchParams = url.searchParams; const mediaId = mediaid.toLowerCase(); const sourceUrl = url.href.toLowerCase(); - // Attach user_id and profile_id only for VOD and BCL SaaS Live Streams - const isVOD = sourceUrl === `https://cdn.jwplayer.com/manifests/${mediaId}.m3u8`; - const isBCL = sourceUrl === `https://content.jwplatform.com/live/broadcast/${mediaId}.m3u8`; + const cdnUrlVOD = `https://cdn.jwplayer.com/manifests/${mediaId}.m3u8`; + const cdnUrlBCL = `https://content.jwplatform.com/live/broadcast/${mediaId}.m3u8`; + + // Attach user_id, profile_id and vendor_id only for VOD, BCL SaaS Live Streams and DRM + const isVOD = sourceUrl === cdnUrlVOD; + const isBCL = sourceUrl === cdnUrlBCL; + const isDRM = sourceUrl.startsWith(cdnUrlVOD) && urlSearchParams.has('exp') && urlSearchParams.has('sig'); - if ((isVOD || isBCL) && userId) { - url.searchParams.set('user_id', userId); + if ((isVOD || isBCL || isDRM) && userId) { + urlSearchParams.set('user_id', userId); if (isJwIntegration && profileId) { - url.searchParams.set('profile_id', profileId); + urlSearchParams.set('profile_id', profileId); } } + if (vendorId) { + urlSearchParams.set('vendor_id', vendorId); + } + source.file = url.toString(); }); }; diff --git a/packages/common/types/settings.ts b/packages/common/types/settings.ts index 38eaab547..ce700c144 100644 --- a/packages/common/types/settings.ts +++ b/packages/common/types/settings.ts @@ -4,4 +4,5 @@ export type Settings = { playerLicenseKey?: string; additionalAllowedConfigSources?: string[]; UNSAFE_allowAnyConfigSource?: boolean; + vendorId?: string; };