All files / app/hooks use-analytics.ts

0% Statements 0/16
0% Branches 0/3
0% Functions 0/2
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                                             
import packageJson from '../../package.json';
import { NETWORK } from '@constants/index';
import { EventParams } from '@segment/analytics-next/dist/types/core/arguments-resolver';
import { useHasUserGivenDiagnosticPermissions } from '@store/settings';
import { getAnalytics } from '@utils/init-segment';
 
export function useAnalytics() {
  const diagnosticsEnabled = useHasUserGivenDiagnosticPermissions();
  const analytics = getAnalytics();
  const defaultProperties = {
    version: packageJson.version,
    network: NETWORK,
  };
 
  const defaultOptions = {
    context: { ip: '0.0.0.0' },
  };
 
  return {
    track: async (...args: EventParams) => {
      Iif (!analytics || !diagnosticsEnabled) return;
      const [eventName, properties, options, ...rest] = args;
 
      const prop = { ...defaultProperties, ...properties };
      const opts = { ...defaultOptions, ...options };
 
      return analytics.track(eventName, prop, opts, ...rest).catch(console.error);
    },
  };
}