fix(metrics): web and Android tag plays with one source vocabulary, so a surface reads the same on either (#8075)
The recommendation metrics judge each surface against a baseline of manual plays. The web tagged only system mixes, so its radio, album, artist and history plays all sat in the baseline; Android tagged nearly everything, and its search, Liked-list, library-shuffle and artist-top plays fell to Other. The surface deltas depended on which client someone listened on. - The web sends the vocabulary Android uses: radio:<seed>, album:<id>, artist:<id>, artist-top:<id>, home:most_played and history, kept in web/src/lib/player/playSource.ts. - The baseline is now named in one place (isManualSource): no source, a search pick, or a Liked-list pick. - library_shuffle gets its own row, the random baseline the mixes exist to beat; artist-top counts as an artist play. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import type { AlbumRef, AlbumDetail } from '#lib/api/types.js';
|
||||
import { api } from '#lib/api/client.js';
|
||||
import { enqueueTracks, playQueue } from '#lib/player/store.svelte.js';
|
||||
import { playSource } from '#lib/player/playSource.js';
|
||||
import { Play } from 'lucide-svelte';
|
||||
import AlbumMenu from './AlbumMenu.svelte';
|
||||
import CardActionCluster from './CardActionCluster.svelte';
|
||||
@@ -20,7 +21,7 @@
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const detail = await api.get<AlbumDetail>(`/api/albums/${album.id}`);
|
||||
playQueue(detail.tracks, 0);
|
||||
playQueue(detail.tracks, 0, { source: playSource.album(album.id) });
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ describe('AlbumCard', () => {
|
||||
expect(api.get).toHaveBeenCalledWith('/api/albums/xyz');
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0);
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0, { source: 'album:xyz' });
|
||||
});
|
||||
|
||||
test('renders the bottom-right kebab menu trigger', () => {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import type { ArtistRef, TrackRef } from '#lib/api/types.js';
|
||||
import { api } from '#lib/api/client.js';
|
||||
import { playQueue, enqueueTracks } from '#lib/player/store.svelte.js';
|
||||
import { playSource } from '#lib/player/playSource.js';
|
||||
import { Play } from 'lucide-svelte';
|
||||
import ArtistMenu from './ArtistMenu.svelte';
|
||||
import CardActionCluster from './CardActionCluster.svelte';
|
||||
@@ -18,7 +19,7 @@
|
||||
e.stopPropagation();
|
||||
const tracks = await api.get<TrackRef[]>(`/api/artists/${artist.id}/tracks`);
|
||||
if (tracks.length === 0) return;
|
||||
playQueue(shuffled(tracks), 0);
|
||||
playQueue(shuffled(tracks), 0, { source: playSource.artist(artist.id) });
|
||||
}
|
||||
|
||||
async function onAddToQueue(e: MouseEvent) {
|
||||
|
||||
@@ -15,17 +15,20 @@
|
||||
let {
|
||||
track,
|
||||
sectionTracks,
|
||||
index
|
||||
index,
|
||||
source
|
||||
}: {
|
||||
track: TrackRef;
|
||||
sectionTracks: TrackRef[];
|
||||
index: number;
|
||||
/** Where a play started here began, in the playSource vocabulary. */
|
||||
source?: string;
|
||||
} = $props();
|
||||
|
||||
const cover = $derived(coverUrl(track.album_id));
|
||||
|
||||
function onClick() {
|
||||
playQueue(sectionTracks, index);
|
||||
playQueue(sectionTracks, index, { source });
|
||||
}
|
||||
|
||||
function onAddToQueue(e: MouseEvent) {
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('CompactTrackCard', () => {
|
||||
props: { track: tracks[1], sectionTracks: tracks, index: 1 }
|
||||
});
|
||||
await fireEvent.click(screen.getByRole('button', { name: /play second/i }));
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 1);
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 1, { source: undefined });
|
||||
});
|
||||
|
||||
test('renders title and artist name', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { HistoryEvent } from '#lib/api/history.js';
|
||||
import { playQueue } from '#lib/player/store.svelte.js';
|
||||
import { playSource } from '#lib/player/playSource.js';
|
||||
import { coverUrl } from '#lib/media/covers.js';
|
||||
import TrackListRow from './TrackListRow.svelte';
|
||||
import Cover from './Cover.svelte';
|
||||
@@ -8,7 +9,7 @@
|
||||
let { event } = $props<{ event: HistoryEvent }>();
|
||||
|
||||
function handleClick() {
|
||||
playQueue([event.track], 0);
|
||||
playQueue([event.track], 0, { source: playSource.history });
|
||||
}
|
||||
|
||||
// Format played_at as a human-readable timestamp.
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('HistoryRow', () => {
|
||||
render(HistoryRow, { props: { event: sampleEvent } });
|
||||
const row = screen.getByRole('button', { name: /play song title/i });
|
||||
await fireEvent.click(row);
|
||||
expect(playQueue).toHaveBeenCalledWith([sampleTrack], 0);
|
||||
expect(playQueue).toHaveBeenCalledWith([sampleTrack], 0, { source: 'history' });
|
||||
});
|
||||
|
||||
it('carries the shared row controls: like, radio, add and the menu', () => {
|
||||
|
||||
@@ -15,11 +15,14 @@
|
||||
tracks,
|
||||
index,
|
||||
onPlay,
|
||||
source,
|
||||
showAlbum = true
|
||||
}: {
|
||||
tracks: TrackRef[];
|
||||
index: number;
|
||||
onPlay?: PlayHandler;
|
||||
/** Where a play started here began, in the playSource vocabulary. */
|
||||
source?: string;
|
||||
/** Off on the album page, where the album is the page itself. */
|
||||
showAlbum?: boolean;
|
||||
} = $props();
|
||||
@@ -50,7 +53,7 @@
|
||||
return;
|
||||
}
|
||||
if (onPlay) onPlay(tracks, index);
|
||||
else playQueue(tracks, index);
|
||||
else playQueue(tracks, index, { source });
|
||||
}
|
||||
|
||||
function onCheckboxClick(e: MouseEvent) {
|
||||
|
||||
@@ -45,19 +45,19 @@ describe('TrackRow', () => {
|
||||
test('clicking the row calls playQueue(tracks, index)', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 1 } });
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Freddie Freewheeler' }));
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 1);
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 1, { source: undefined });
|
||||
});
|
||||
|
||||
test('Enter on the row activates play', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 0 } });
|
||||
await fireEvent.keyDown(screen.getByRole('button', { name: 'So Then' }), { key: 'Enter' });
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0);
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0, { source: undefined });
|
||||
});
|
||||
|
||||
test('Space on the row activates play', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 0 } });
|
||||
await fireEvent.keyDown(screen.getByRole('button', { name: 'So Then' }), { key: ' ' });
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0);
|
||||
expect(playQueue).toHaveBeenCalledWith(tracks, 0, { source: undefined });
|
||||
});
|
||||
|
||||
test('onPlay prop overrides default playQueue', async () => {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// The play-source vocabulary: what a play_started's `source` says about where
|
||||
// a play began. The server's recommendation metrics bucket plays by it
|
||||
// (internal/api/me_recommendation_metrics.go, bucketRecSource), and the
|
||||
// Android app sends the same strings, so a surface reads the same whichever
|
||||
// client the listening happened on. System mixes send their variant name
|
||||
// ('for_you', 'discover', …) instead.
|
||||
//
|
||||
// A play with no source, or from search or the Liked list, is a manual pick:
|
||||
// the baseline every recommendation surface is judged against.
|
||||
export const playSource = {
|
||||
album: (albumId: string) => `album:${albumId}`,
|
||||
artist: (artistId: string) => `artist:${artistId}`,
|
||||
artistTop: (artistId: string) => `artist-top:${artistId}`,
|
||||
radio: (seedTrackId: string) => `radio:${seedTrackId}`,
|
||||
home: (section: string) => `home:${section}`,
|
||||
history: 'history',
|
||||
liked: 'liked',
|
||||
search: 'search'
|
||||
} as const;
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { TrackRef, RadioResponse } from '#lib/api/types.js';
|
||||
import { playSource } from './playSource';
|
||||
import { untrack } from 'svelte';
|
||||
import { api } from '#lib/api/client.js';
|
||||
import { user } from '#lib/auth/user.svelte.js';
|
||||
@@ -83,10 +84,11 @@ let _pendingRestorePosition: number | null = null;
|
||||
let _radioSeedId = $state<string | null>(null);
|
||||
let _radioRefreshInFlight = false;
|
||||
|
||||
// Which system playlist (if any) this queue was seeded from.
|
||||
// 'for_you' | 'discover' | null. Read by the events dispatcher so
|
||||
// play_started carries `source` and the play counts against that
|
||||
// playlist's rotation. Re-set on every playQueue (a fresh non-system
|
||||
// Where this queue was seeded from, in the playSource vocabulary: a system
|
||||
// playlist's variant ('for_you' | 'discover' | …), radio, an album, an
|
||||
// artist, … or null for a manual pick. Read by the events dispatcher so
|
||||
// play_started carries `source`: a mix's play counts against that
|
||||
// playlist's rotation, and every play lands on its surface in the metrics. Re-set on every playQueue (a fresh non-system
|
||||
// queue clears it).
|
||||
let _queueSource = $state<string | null>(null);
|
||||
|
||||
@@ -480,7 +482,10 @@ export async function playRadio(seedTrackId: string): Promise<void> {
|
||||
if (tracks.length === 0) return;
|
||||
// Hand the player a self-heal closure so a fully-stale radio queue
|
||||
// re-seeds from the same track instead of dead-ending.
|
||||
playQueue(tracks, 0, { refetch: () => fetchRadioTracks(seedTrackId) });
|
||||
playQueue(tracks, 0, {
|
||||
source: playSource.radio(seedTrackId),
|
||||
refetch: () => fetchRadioTracks(seedTrackId)
|
||||
});
|
||||
_radioSeedId = seedTrackId; // Set AFTER playQueue (which clears it)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user