File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,7 +64,28 @@ document.addEventListener("DOMContentLoaded", () => {
6464 videoElement . src = url ;
6565 }
6666
67- const contentId = url . split ( "/" ) . pop ( ) || "" ;
67+ const parsedUrl = new URL ( url ) ;
68+ let contentId ;
69+ if (
70+ parsedUrl . pathname . endsWith ( ".m3u8" ) ||
71+ parsedUrl . pathname . endsWith ( ".mpd" )
72+ ) {
73+ // Extract path up to the last slash for manifest files
74+ const lastSlashIndex = parsedUrl . pathname . lastIndexOf ( "/" ) ;
75+ contentId =
76+ lastSlashIndex > 0
77+ ? parsedUrl . pathname . substring ( 0 , lastSlashIndex )
78+ : parsedUrl . pathname ;
79+ } else {
80+ // Use filename for other files
81+ const pathSegments = parsedUrl . pathname . split ( "/" ) ;
82+ contentId = pathSegments [ pathSegments . length - 1 ] ;
83+ // Remove file extension from the contentId
84+ const fileExtIndex = contentId . lastIndexOf ( "." ) ;
85+ if ( fileExtIndex > 0 ) {
86+ contentId = contentId . substring ( 0 , fileExtIndex ) ;
87+ }
88+ }
6889 const { deviceType, deviceModel } = getDeviceInfo ( ) ;
6990 analytics . reportMetadata ( {
7091 live : false ,
You can’t perform that action at this time.
0 commit comments