Skip to content

Commit

Permalink
feat: cdn analytics code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
olga-jwp committed Jan 12, 2024
1 parent 114150e commit d92937d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useConfigStore } from '#src/stores/ConfigStore';
import type { AdSchedule } from '#types/ad-schedule';
import { useAccountStore } from '#src/stores/AccountStore';
import { useProfileStore } from '#src/stores/ProfileStore';
import { attachAnalyticsParams } from '#src/utils/player';
import { attachAnalyticsParams } from '#src/utils/analytics';

type Props = {
feedId?: string;
Expand Down Expand Up @@ -174,8 +174,7 @@ const Player: React.FC<Props> = ({
playerRef.current = window.jwplayer(playerElementRef.current) as JWPlayer;

// Inject user_id and profile_id into the CDN analytics
const { sources, mediaid } = item;
attachAnalyticsParams(sources, mediaid, isJwIntegration, userId, profileId);
attachAnalyticsParams(item, isJwIntegration, userId, profileId);

// Player options are untyped
const playerOptions: { [key: string]: unknown } = {
Expand Down
8 changes: 5 additions & 3 deletions src/utils/player.ts → src/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Source } from '#types/playlist';
import type { PlaylistItem, Source } from '#types/playlist';

export const attachAnalyticsParams = (item: PlaylistItem, isJwIntegration: boolean, userId?: string, profileId?: string) => {
const { sources, mediaid } = item;

export const attachAnalyticsParams = (sources: Source[], mediaid: string, isJwIntegration: boolean, userId?: string, profileId?: string) => {
return sources.map((source: Source) => {
const url = new URL(source.file);

Expand All @@ -12,7 +14,7 @@ export const attachAnalyticsParams = (sources: Source[], mediaid: string, isJwIn
url.searchParams.set('user_id', userId);

if (isJwIntegration && profileId) {
url.searchParams.append('profile_id', profileId);
url.searchParams.set('profile_id', profileId);
}
}

Expand Down

0 comments on commit d92937d

Please sign in to comment.