You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
4 years ago
|
import { useContext, useCallback } from 'react';
|
||
|
import { MetaMetricsContext } from '../contexts/metametrics';
|
||
|
import { MetaMetricsContext as NewMetaMetricsContext } from '../contexts/metametrics.new';
|
||
|
import { useEqualityCheck } from './useEqualityCheck';
|
||
5 years ago
|
|
||
4 years ago
|
// Type imports
|
||
|
/**
|
||
|
* @typedef {import('../contexts/metametrics.new').UIMetricsEventPayload} UIMetricsEventPayload
|
||
4 years ago
|
* @typedef {import('../../shared/constants/metametrics').MetaMetricsEventOptions} MetaMetricsEventOptions
|
||
4 years ago
|
*/
|
||
|
|
||
4 years ago
|
export function useMetricEvent(config = {}, overrides = {}) {
|
||
4 years ago
|
const metricsEvent = useContext(MetaMetricsContext);
|
||
4 years ago
|
const trackEvent = useCallback(() => metricsEvent(config, overrides), [
|
||
|
config,
|
||
|
metricsEvent,
|
||
|
overrides,
|
||
4 years ago
|
]);
|
||
|
return trackEvent;
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
|
/**
|
||
4 years ago
|
* track a metametrics event using segment
|
||
|
* e.g metricsEvent({ event: 'Unlocked MetaMask', category: 'Navigation' })
|
||
|
*
|
||
4 years ago
|
* @param {UIMetricsEventPayload} payload - payload of the event to track
|
||
|
* @param {MetaMetricsEventOptions} options - options for handling/routing event
|
||
|
* @return {() => Promise<void>} function to execute the tracking event
|
||
4 years ago
|
*/
|
||
4 years ago
|
export function useNewMetricEvent(payload, options) {
|
||
4 years ago
|
const memoizedPayload = useEqualityCheck(payload);
|
||
|
const memoizedOptions = useEqualityCheck(options);
|
||
|
const metricsEvent = useContext(NewMetaMetricsContext);
|
||
4 years ago
|
|
||
|
return useCallback(() => metricsEvent(memoizedPayload, memoizedOptions), [
|
||
4 years ago
|
metricsEvent,
|
||
4 years ago
|
memoizedPayload,
|
||
|
memoizedOptions,
|
||
4 years ago
|
]);
|
||
4 years ago
|
}
|