Skip to content

Commit 2e2e7b3

Browse files
dylanjeffersclaude
andauthored
Add collectionId to PLAYBACK_PLAY analytics events (#14101)
## Summary - Adds `collectionId` to the `PlaybackPlay` Amplitude analytics event type, so every `PLAYBACK_PLAY` event fired from a playlist/album context now includes the collection ID - Enriches all collection play surfaces: web collection page, web collection tiles (desktop + mobile), queue sagas (passive next/prev), and mobile collection screen - Complements the `PLAYLIST_PLAY` event from #14087 — that tracks playlist-level play intent, while this tracks individual track plays attributed to a specific playlist/album This enables Amplitude queries like: - "How many track plays originated from playlists vs other sources?" - "Which playlists drive the most track plays?" - "What % of a track's plays came from playlist X?" ## Test plan - [ ] Play a track from a playlist page on web — verify Amplitude `Playback: Play` event includes `collectionId` - [ ] Click a track row within a playlist on web — verify `collectionId` is present - [ ] Let a track auto-advance (next) within a playlist on web — verify passive `Playback: Play` event includes `collectionId` - [ ] Play from a collection tile on web (desktop + mobile web) — verify `collectionId` is present - [ ] Play a track from a collection screen on mobile — verify `collectionId` is present - [ ] Play a track from a non-collection context (e.g. track page, trending) — verify `collectionId` is NOT present https://claude.ai/code/session_01QszUni9cixkeUCYyViirgV --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 423538c commit 2e2e7b3

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@audius/common": patch
3+
"@audius/mobile": patch
4+
"@audius/web": patch
5+
---
6+
7+
Add collectionId to PLAYBACK_PLAY analytics events when a track is played from a playlist or album context

packages/common/src/models/Analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ type PlaybackPlay = {
14761476
id?: string
14771477
isPreview?: boolean
14781478
source: PlaybackSource
1479+
collectionId?: string
14791480
}
14801481
type PlaybackPause = {
14811482
eventName: Name.PLAYBACK_PAUSE

packages/mobile/src/screens/collection-screen/CollectionScreenDetailsTile.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,19 @@ type CollectionScreenDetailsTileProps = {
167167
| 'contentType'
168168
>
169169

170-
const recordPlay = (id: Maybe<number>, play = true) => {
170+
const recordPlay = (
171+
id: Maybe<number>,
172+
play = true,
173+
collectionId?: Maybe<number>
174+
) => {
171175
track(
172176
make({
173177
eventName: play ? Name.PLAYBACK_PLAY : Name.PLAYBACK_PAUSE,
174178
id: String(id),
175-
source: PlaybackSource.PLAYLIST_PAGE
179+
source: PlaybackSource.PLAYLIST_PAGE,
180+
...(play && collectionId != null
181+
? { collectionId: String(collectionId) }
182+
: {})
176183
})
177184
)
178185
}
@@ -337,7 +344,7 @@ export const CollectionScreenDetailsTile = ({
337344
recordPlay(playingTrackId, false)
338345
} else if (!isPlaying && isQueued) {
339346
dispatch(tracksActions.play())
340-
recordPlay(playingTrackId)
347+
recordPlay(playingTrackId, true, numericCollectionId)
341348
recordPlaylistPlay({
342349
collectionId: numericCollectionId,
343350
isAlbum: !!isAlbum,
@@ -347,7 +354,7 @@ export const CollectionScreenDetailsTile = ({
347354
} else if (trackCount > 0 && firstTrack) {
348355
dispatch(queueActions.clear({}))
349356
dispatch(tracksActions.play(firstTrack.uid, { isPreview }))
350-
recordPlay(firstTrack.id)
357+
recordPlay(firstTrack.id, true, numericCollectionId)
351358
recordPlaylistPlay({
352359
collectionId: numericCollectionId,
353360
isAlbum: !!isAlbum,
@@ -582,13 +589,13 @@ const CollectionTrackList = ({
582589
recordPlay(id, false)
583590
} else if (playingUid !== uid) {
584591
dispatch(tracksActions.play(uid))
585-
recordPlay(id)
592+
recordPlay(id, true, numericCollectionId)
586593
} else {
587594
dispatch(tracksActions.play())
588-
recordPlay(id)
595+
recordPlay(id, true, numericCollectionId)
589596
}
590597
},
591-
[dispatch, isPlaying, playingUid]
598+
[dispatch, isPlaying, playingUid, numericCollectionId]
592599
)
593600
return (
594601
<TrackList

packages/web/src/common/store/queue/sagas.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const {
5151
getShuffle,
5252
getSource,
5353
getUid,
54-
getUndershot
54+
getUndershot,
55+
getCollectionId
5556
} = queueSelectors
5657

5758
const { getProfileUserHandle } = profilePageSelectors
@@ -417,9 +418,11 @@ function* watchNext() {
417418
playerBehavior
418419
})
419420
)
421+
const collId = yield* select(getCollectionId)
420422
const event = make(Name.PLAYBACK_PLAY, {
421423
id: `${id}`,
422-
source: PlaybackSource.PASSIVE
424+
source: PlaybackSource.PASSIVE,
425+
...(collId ? { collectionId: collId } : {})
423426
})
424427
yield* put(event)
425428
}
@@ -507,9 +510,11 @@ function* watchPrevious() {
507510
playerBehavior
508511
})
509512
)
513+
const collId = yield* select(getCollectionId)
510514
const event = make(Name.PLAYBACK_PLAY, {
511515
id: `${id}`,
512-
source: PlaybackSource.PASSIVE
516+
source: PlaybackSource.PASSIVE,
517+
...(collId ? { collectionId: collId } : {})
513518
})
514519
yield* put(event)
515520
} else {

packages/web/src/components/track/desktop/CollectionTile.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ export const CollectionTile = ({
244244
record(
245245
make(Name.PLAYBACK_PLAY, {
246246
id: `${playingTrackId}`,
247-
source: PlaybackSource.PLAYLIST_TILE_TRACK
247+
source: PlaybackSource.PLAYLIST_TILE_TRACK,
248+
collectionId: `${id}`
248249
})
249250
)
250251
record(
@@ -265,7 +266,8 @@ export const CollectionTile = ({
265266
record(
266267
make(Name.PLAYBACK_PLAY, {
267268
id: `${trackId}`,
268-
source: PlaybackSource.PLAYLIST_TILE_TRACK
269+
source: PlaybackSource.PLAYLIST_TILE_TRACK,
270+
collectionId: `${id}`
269271
})
270272
)
271273
record(

packages/web/src/components/track/mobile/CollectionTile.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ export const CollectionTile = ({
422422
record(
423423
make(Name.PLAYBACK_PLAY, {
424424
id: `${playingTrackId}`,
425-
source
425+
source,
426+
collectionId: `${collection.playlist_id}`
426427
})
427428
)
428429
record(
@@ -441,7 +442,8 @@ export const CollectionTile = ({
441442
record(
442443
make(Name.PLAYBACK_PLAY, {
443444
id: `${trackId}`,
444-
source
445+
source,
446+
collectionId: `${collection.playlist_id}`
445447
})
446448
)
447449
record(

packages/web/src/pages/collection-page/useCollectionPage.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,20 +444,22 @@ export const useCollectionPage = (
444444
dispatch(
445445
make(Name.PLAYBACK_PLAY, {
446446
id: `${trackRecord.track_id}`,
447-
source: PlaybackSource.PLAYLIST_TRACK
447+
source: PlaybackSource.PLAYLIST_TRACK,
448+
...(playlistId ? { collectionId: `${playlistId}` } : {})
448449
})
449450
)
450451
} else {
451452
dispatch(tracksActions.play())
452453
dispatch(
453454
make(Name.PLAYBACK_PLAY, {
454455
id: `${trackRecord.track_id}`,
455-
source: PlaybackSource.PLAYLIST_TRACK
456+
source: PlaybackSource.PLAYLIST_TRACK,
457+
...(playlistId ? { collectionId: `${playlistId}` } : {})
456458
})
457459
)
458460
}
459461
},
460-
[playing, getPlayingUid, dispatch]
462+
[playing, getPlayingUid, dispatch, playlistId]
461463
)
462464

463465
const onClickRepostTrack = useCallback(
@@ -545,7 +547,8 @@ export const useCollectionPage = (
545547
make(Name.PLAYBACK_PLAY, {
546548
id: `${playingId}`,
547549
isPreview: shouldPreview,
548-
source: PlaybackSource.PLAYLIST_PAGE
550+
source: PlaybackSource.PLAYLIST_PAGE,
551+
...(playlistId ? { collectionId: `${playlistId}` } : {})
549552
})
550553
)
551554
if (playlistId) {
@@ -570,7 +573,8 @@ export const useCollectionPage = (
570573
make(Name.PLAYBACK_PLAY, {
571574
id: `${tracks.entries[0].track_id}`,
572575
isPreview: shouldPreview,
573-
source: PlaybackSource.PLAYLIST_PAGE
576+
source: PlaybackSource.PLAYLIST_PAGE,
577+
...(playlistId ? { collectionId: `${playlistId}` } : {})
574578
})
575579
)
576580
if (playlistId) {

0 commit comments

Comments
 (0)