Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/playlist-play-collection-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@audius/common": patch
"@audius/mobile": patch
"@audius/web": patch
---

Add collectionId to PLAYBACK_PLAY analytics events when a track is played from a playlist or album context
1 change: 1 addition & 0 deletions packages/common/src/models/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ type PlaybackPlay = {
id?: string
isPreview?: boolean
source: PlaybackSource
collectionId?: string
}
type PlaybackPause = {
eventName: Name.PLAYBACK_PAUSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,19 @@ type CollectionScreenDetailsTileProps = {
| 'contentType'
>

const recordPlay = (id: Maybe<number>, play = true) => {
const recordPlay = (
id: Maybe<number>,
play = true,
collectionId?: Maybe<number>
) => {
track(
make({
eventName: play ? Name.PLAYBACK_PLAY : Name.PLAYBACK_PAUSE,
id: String(id),
source: PlaybackSource.PLAYLIST_PAGE
source: PlaybackSource.PLAYLIST_PAGE,
...(play && collectionId != null
? { collectionId: String(collectionId) }
: {})
})
)
}
Expand Down Expand Up @@ -337,7 +344,7 @@ export const CollectionScreenDetailsTile = ({
recordPlay(playingTrackId, false)
} else if (!isPlaying && isQueued) {
dispatch(tracksActions.play())
recordPlay(playingTrackId)
recordPlay(playingTrackId, true, numericCollectionId)
recordPlaylistPlay({
collectionId: numericCollectionId,
isAlbum: !!isAlbum,
Expand All @@ -347,7 +354,7 @@ export const CollectionScreenDetailsTile = ({
} else if (trackCount > 0 && firstTrack) {
dispatch(queueActions.clear({}))
dispatch(tracksActions.play(firstTrack.uid, { isPreview }))
recordPlay(firstTrack.id)
recordPlay(firstTrack.id, true, numericCollectionId)
recordPlaylistPlay({
collectionId: numericCollectionId,
isAlbum: !!isAlbum,
Expand Down Expand Up @@ -582,13 +589,13 @@ const CollectionTrackList = ({
recordPlay(id, false)
} else if (playingUid !== uid) {
dispatch(tracksActions.play(uid))
recordPlay(id)
recordPlay(id, true, numericCollectionId)
} else {
dispatch(tracksActions.play())
recordPlay(id)
recordPlay(id, true, numericCollectionId)
}
},
[dispatch, isPlaying, playingUid]
[dispatch, isPlaying, playingUid, numericCollectionId]
)
return (
<TrackList
Expand Down
11 changes: 8 additions & 3 deletions packages/web/src/common/store/queue/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const {
getShuffle,
getSource,
getUid,
getUndershot
getUndershot,
getCollectionId
} = queueSelectors

const { getProfileUserHandle } = profilePageSelectors
Expand Down Expand Up @@ -417,9 +418,11 @@ function* watchNext() {
playerBehavior
})
)
const collId = yield* select(getCollectionId)
const event = make(Name.PLAYBACK_PLAY, {
id: `${id}`,
source: PlaybackSource.PASSIVE
source: PlaybackSource.PASSIVE,
...(collId ? { collectionId: collId } : {})
})
yield* put(event)
}
Expand Down Expand Up @@ -507,9 +510,11 @@ function* watchPrevious() {
playerBehavior
})
)
const collId = yield* select(getCollectionId)
const event = make(Name.PLAYBACK_PLAY, {
id: `${id}`,
source: PlaybackSource.PASSIVE
source: PlaybackSource.PASSIVE,
...(collId ? { collectionId: collId } : {})
})
yield* put(event)
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/components/track/desktop/CollectionTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ export const CollectionTile = ({
record(
make(Name.PLAYBACK_PLAY, {
id: `${playingTrackId}`,
source: PlaybackSource.PLAYLIST_TILE_TRACK
source: PlaybackSource.PLAYLIST_TILE_TRACK,
collectionId: `${id}`
})
)
record(
Expand All @@ -265,7 +266,8 @@ export const CollectionTile = ({
record(
make(Name.PLAYBACK_PLAY, {
id: `${trackId}`,
source: PlaybackSource.PLAYLIST_TILE_TRACK
source: PlaybackSource.PLAYLIST_TILE_TRACK,
collectionId: `${id}`
})
)
record(
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/components/track/mobile/CollectionTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ export const CollectionTile = ({
record(
make(Name.PLAYBACK_PLAY, {
id: `${playingTrackId}`,
source
source,
collectionId: `${collection.playlist_id}`
})
)
record(
Expand All @@ -441,7 +442,8 @@ export const CollectionTile = ({
record(
make(Name.PLAYBACK_PLAY, {
id: `${trackId}`,
source
source,
collectionId: `${collection.playlist_id}`
})
)
record(
Expand Down
14 changes: 9 additions & 5 deletions packages/web/src/pages/collection-page/useCollectionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,22 @@ export const useCollectionPage = (
dispatch(
make(Name.PLAYBACK_PLAY, {
id: `${trackRecord.track_id}`,
source: PlaybackSource.PLAYLIST_TRACK
source: PlaybackSource.PLAYLIST_TRACK,
...(playlistId ? { collectionId: `${playlistId}` } : {})
})
)
} else {
dispatch(tracksActions.play())
dispatch(
make(Name.PLAYBACK_PLAY, {
id: `${trackRecord.track_id}`,
source: PlaybackSource.PLAYLIST_TRACK
source: PlaybackSource.PLAYLIST_TRACK,
...(playlistId ? { collectionId: `${playlistId}` } : {})
})
)
}
},
[playing, getPlayingUid, dispatch]
[playing, getPlayingUid, dispatch, playlistId]
)

const onClickRepostTrack = useCallback(
Expand Down Expand Up @@ -545,7 +547,8 @@ export const useCollectionPage = (
make(Name.PLAYBACK_PLAY, {
id: `${playingId}`,
isPreview: shouldPreview,
source: PlaybackSource.PLAYLIST_PAGE
source: PlaybackSource.PLAYLIST_PAGE,
...(playlistId ? { collectionId: `${playlistId}` } : {})
})
)
if (playlistId) {
Expand All @@ -570,7 +573,8 @@ export const useCollectionPage = (
make(Name.PLAYBACK_PLAY, {
id: `${tracks.entries[0].track_id}`,
isPreview: shouldPreview,
source: PlaybackSource.PLAYLIST_PAGE
source: PlaybackSource.PLAYLIST_PAGE,
...(playlistId ? { collectionId: `${playlistId}` } : {})
})
)
if (playlistId) {
Expand Down
Loading