import React from 'react' ; import { CompositeAnalytics } from "./CompositeAnalytics" ; import { IAnalytics , IEventArgs , TraitsMap , IPageEvent , IAnalyticsUser } from "./IAnalytics" ; import { GAAnalytics } from "./ga/GAAnalytics" ; import { NullAnalytics } from "./null/NullAnalytics" ; import { AmplitudeAnalytics } from "./amplitude/AmplitudeAnalytics" ; import { FirestoreAnalytics } from "./firestore/FirestoreAnalytics" ; import { OnlineAnalytics } from "./online/OnlineAnalytics" ; import { UserflowAnalytics } from "./userflow/UserflowAnalytics" ; import { ConsoleAnalytics } from "./console/ConsoleAnalytics" ; import { IntercomAnalytics } from "./intercom/IntercomAnalytics" ; import { CannyAnalytics } from "./canny/CannyAnalytics" ; import { SentryAnalytics } from "./sentry/SentryAnalytics" ; export function isBrowser ( ) { return typeof window !== 'undefined' ; } export function isWebExtension ( ) { return document . location . href . startsWith ( "chrome-extension:" ) ; } function createDelegates ( ) { const webExtension = isWebExtension ( ) ; return [ new AmplitudeAnalytics ( ) , webExtension ? undefined : new GAAnalytics ( ) , webExtension ? undefined : new FirestoreAnalytics ( ) , webExtension ? undefined : new UserflowAnalytics ( ) , new ConsoleAnalytics ( ) , webExtension ? undefined : new IntercomAnalytics ( ) , webExtension ? undefined : new CannyAnalytics ( ) , new SentryAnalytics ( ) ] . filter ( current => current !== undefined ) . map ( current => current ! ) ; } function createInstance ( ) { if ( isBrowser ( ) ) { return new OnlineAnalytics ( new CompositeAnalytics ( createDelegates ( ) ) ) ; } else { return new NullAnalytics ( ) ; } } const instance = createInstance ( ) ; /**
 * Hook for analytics that isn't that complicated yet but we can add more
 * functionality later.
 */ export function useAnalytics ( ) { return React . useMemo ( ( ) : IAnalytics => { if ( isBrowser ( ) ) { return new OnlineAnalytics ( new CompositeAnalytics ( createDelegates ( ) ) ) ; } else { return new NullAnalytics ( ) ; } } , [ ] ) ; } export namespace Analytics { export function event ( event ) { instance . event ( event ) ; } export function event2 ( event , data ? ) { instance . event2 ( event , data ) ; } export function identify ( user ) { instance . identify ( user ) ; } export function page ( event ) { instance . page ( event ) ; } deprecated export function traits ( map ) { instance . traits ( map ) ; } export function version ( version ) { instance . version ( version ) ; } export function heartbeat ( ) { instance . heartbeat ( ) ; } export function logout ( ) { instance . logout ( ) ; } /**
     * Action handler for the given delegate.
     */ export function withEvent ( event ) { return ( delegate ) => { Analytics . event ( event ) ; delegate ( ) ; } ; } }