-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from jwplayer/OWA-52-add-user-profile-id-for-…
…cdn-analytics feat: add user_id and profile_id for CDN analytics
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useAccountStore } from '#src/stores/AccountStore'; | ||
import { useConfigStore } from '#src/stores/ConfigStore'; | ||
import { useProfileStore } from '#src/stores/ProfileStore'; | ||
import type { PlaylistItem, Source } from '#types/playlist'; | ||
|
||
export const attachAnalyticsParams = (item: PlaylistItem) => { | ||
const { config } = useConfigStore.getState(); | ||
const { user } = useAccountStore.getState(); | ||
const { profile } = useProfileStore.getState(); | ||
|
||
const { sources, mediaid } = item; | ||
|
||
const userId = user?.id; | ||
const profileId = profile?.id; | ||
const isJwIntegration = !!config?.integrations?.jwp; | ||
|
||
return sources.map((source: Source) => { | ||
const url = new URL(source.file); | ||
|
||
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`; | ||
|
||
if ((isVOD || isBCL) && userId) { | ||
url.searchParams.set('user_id', userId); | ||
|
||
if (isJwIntegration && profileId) { | ||
url.searchParams.set('profile_id', profileId); | ||
} | ||
} | ||
|
||
source.file = url.toString(); | ||
}); | ||
}; |