| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {TrackEventName} from 'isl-server/src/analytics/eventNames'; |
| b69ab31 | | | 9 | import type {TrackData} from 'isl-server/src/analytics/types'; |
| b69ab31 | | | 10 | import type {ReactNode} from 'react'; |
| b69ab31 | | | 11 | |
| b69ab31 | | | 12 | import {useThrottledEffect} from 'shared/hooks'; |
| b69ab31 | | | 13 | import {tracker} from './index'; |
| b69ab31 | | | 14 | |
| b69ab31 | | | 15 | /** |
| b69ab31 | | | 16 | * Log an analytics event when a component renders the first time. |
| b69ab31 | | | 17 | * Useful for declarative analytics when there isn't a good place to put a useEffect. |
| b69ab31 | | | 18 | */ |
| b69ab31 | | | 19 | export function LogRenderExposures({ |
| b69ab31 | | | 20 | children, |
| b69ab31 | | | 21 | eventName, |
| b69ab31 | | | 22 | data, |
| b69ab31 | | | 23 | }: { |
| b69ab31 | | | 24 | children: ReactNode; |
| b69ab31 | | | 25 | eventName: TrackEventName; |
| b69ab31 | | | 26 | data?: TrackData; |
| b69ab31 | | | 27 | }) { |
| b69ab31 | | | 28 | useThrottledEffect( |
| b69ab31 | | | 29 | () => { |
| b69ab31 | | | 30 | tracker.track(eventName, data); |
| b69ab31 | | | 31 | }, |
| b69ab31 | | | 32 | 100, |
| b69ab31 | | | 33 | [data, eventName], |
| b69ab31 | | | 34 | ); |
| b69ab31 | | | 35 | return <>{children}</>; |
| b69ab31 | | | 36 | } |