Add video playback analytics events (#11629)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import {hasPlaybackStarted} from '../analytics'
|
||||
|
||||
describe('hasPlaybackStarted', () => {
|
||||
it.each([
|
||||
[0, false],
|
||||
[0.049, false],
|
||||
[0.05, true],
|
||||
[1, true],
|
||||
[Number.NaN, false],
|
||||
[Number.POSITIVE_INFINITY, false],
|
||||
])('returns %s for %s seconds', (seconds, expected) => {
|
||||
expect(hasPlaybackStarted(seconds)).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
export const PLAYBACK_START_THRESHOLD_SECONDS = 0.05
|
||||
|
||||
/**
|
||||
* A small positive threshold distinguishes rendered playback from metadata
|
||||
* loading and zero-valued player callbacks while still representing the first
|
||||
* frame across the frame rates we support.
|
||||
*/
|
||||
export function hasPlaybackStarted(progressSeconds: number): boolean {
|
||||
return (
|
||||
Number.isFinite(progressSeconds) &&
|
||||
progressSeconds >= PLAYBACK_START_THRESHOLD_SECONDS
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import {type EmbedPlayerType, getEmbedPlayerMediaType} from './embed-player'
|
||||
|
||||
describe('getEmbedPlayerMediaType', () => {
|
||||
it.each<
|
||||
readonly [EmbedPlayerType, ReturnType<typeof getEmbedPlayerMediaType>]
|
||||
>([
|
||||
['youtube_video', 'video'],
|
||||
['youtube_short', 'video'],
|
||||
['twitch_video', 'video'],
|
||||
['vimeo_video', 'video'],
|
||||
['spotify_song', 'audio'],
|
||||
['soundcloud_set', 'audio'],
|
||||
['apple_music_album', 'audio'],
|
||||
['bandcamp_track', 'audio'],
|
||||
['giphy_gif', 'gif'],
|
||||
['flickr_album', 'other'],
|
||||
])('classifies %s as %s', (type, expected) => {
|
||||
expect(getEmbedPlayerMediaType(type)).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -49,6 +49,29 @@ export type EmbedPlayerType =
|
||||
| 'bandcamp_album'
|
||||
| 'bandcamp_track'
|
||||
|
||||
export function getEmbedPlayerMediaType(
|
||||
type: EmbedPlayerType,
|
||||
): 'video' | 'audio' | 'gif' | 'other' {
|
||||
if (
|
||||
type === 'youtube_video' ||
|
||||
type === 'youtube_short' ||
|
||||
type === 'twitch_video' ||
|
||||
type === 'vimeo_video'
|
||||
) {
|
||||
return 'video'
|
||||
}
|
||||
if (type.endsWith('_gif')) return 'gif'
|
||||
if (
|
||||
type.startsWith('spotify_') ||
|
||||
type.startsWith('soundcloud_') ||
|
||||
type.startsWith('apple_music_') ||
|
||||
type.startsWith('bandcamp_')
|
||||
) {
|
||||
return 'audio'
|
||||
}
|
||||
return 'other'
|
||||
}
|
||||
|
||||
export const externalEmbedLabels: Record<EmbedPlayerSource, string> = {
|
||||
youtube: 'YouTube',
|
||||
youtubeShorts: 'YouTube Shorts',
|
||||
|
||||
Reference in New Issue
Block a user