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