File size: 699 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useEffect } from 'react';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { profilerVersion } from 'calypso/performance-profiler/utils/profiler-version';

export const useReportCompletedEffect = ( url: string, hash: string ) => {
	useEffect( () => {
		if ( performance.getEntriesByName( 'test-started' ).length > 0 ) {
			performance.mark( 'test-completed' );
			const testMeasure = performance.measure( 'test-duration', 'test-started', 'test-completed' );
			recordTracksEvent( 'calypso_performance_profiler_test_completed', {
				url,
				hash,
				duration: testMeasure?.duration ?? undefined,
				version: profilerVersion(),
			} );
		}
	}, [ url, hash ] );
};