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; };