addons/isl/src/analytics/LogRenderExposures.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {TrackEventName} from 'isl-server/src/analytics/eventNames';
b69ab319import type {TrackData} from 'isl-server/src/analytics/types';
b69ab3110import type {ReactNode} from 'react';
b69ab3111
b69ab3112import {useThrottledEffect} from 'shared/hooks';
b69ab3113import {tracker} from './index';
b69ab3114
b69ab3115/**
b69ab3116 * Log an analytics event when a component renders the first time.
b69ab3117 * Useful for declarative analytics when there isn't a good place to put a useEffect.
b69ab3118 */
b69ab3119export function LogRenderExposures({
b69ab3120 children,
b69ab3121 eventName,
b69ab3122 data,
b69ab3123}: {
b69ab3124 children: ReactNode;
b69ab3125 eventName: TrackEventName;
b69ab3126 data?: TrackData;
b69ab3127}) {
b69ab3128 useThrottledEffect(
b69ab3129 () => {
b69ab3130 tracker.track(eventName, data);
b69ab3131 },
b69ab3132 100,
b69ab3133 [data, eventName],
b69ab3134 );
b69ab3135 return <>{children}</>;
b69ab3136}