UNPKG

posthog-js

Version:

Posthog-js allows you to automatically capture usage and send events to PostHog.

104 lines • 4.78 kB
import { BootstrapConfig, CaptureResult, FeatureFlagResult, JsonType, PostHog, PostHog as PostHog$1, PostHogConfig } from "posthog-js"; import React, { ErrorInfo, FunctionComponent, ReactElement } from "react"; //#region src/context/shared-state.d.ts type PostHogContextValue = { client: PostHog$1; bootstrap?: BootstrapConfig; }; //#endregion //#region src/context/PostHogContext.d.ts declare const PostHogContext: import("react").Context<PostHogContextValue>; //#endregion //#region src/context/PostHogProvider.d.ts type WithOptionalChildren<T> = T & { children?: React.ReactNode | undefined; }; type PostHogProviderProps = { client: PostHog; apiKey?: never; options?: never; } | { apiKey: string; options?: Partial<PostHogConfig>; client?: never; }; declare function PostHogProvider({ children, client, apiKey, options }: WithOptionalChildren<PostHogProviderProps>): ReactElement<any, any>; //#endregion //#region src/hooks/useFeatureFlagEnabled.d.ts declare function useFeatureFlagEnabled(flag: string): boolean | undefined; declare function useFeatureFlagEnabled(flag: string, defaultValue: boolean): boolean; //#endregion //#region src/hooks/useFeatureFlagPayload.d.ts declare function useFeatureFlagPayload(flag: string): JsonType; //#endregion //#region src/hooks/useFeatureFlagResult.d.ts declare function useFeatureFlagResult(flag: string): FeatureFlagResult | undefined; //#endregion //#region src/hooks/useActiveFeatureFlags.d.ts declare function useActiveFeatureFlags(): string[]; //#endregion //#region src/hooks/useFeatureFlagVariantKey.d.ts declare function useFeatureFlagVariantKey(flag: string): string | boolean | undefined; //#endregion //#region src/hooks/usePostHog.d.ts declare const usePostHog: () => PostHog; //#endregion //#region src/components/PostHogFeature.d.ts type PostHogFeatureProps = Omit<React.HTMLProps<HTMLDivElement>, 'children'> & { flag: string; children: React.ReactNode | ((payload: any) => React.ReactNode); fallback?: React.ReactNode; match?: string | boolean; visibilityObserverOptions?: IntersectionObserverInit; trackInteraction?: boolean; trackView?: boolean; }; declare function PostHogFeature({ flag, match, children, fallback, visibilityObserverOptions, trackInteraction, trackView, ...props }: PostHogFeatureProps): ReactElement<any, any> | null; type CaptureFeatureOptions = { flag: string; posthog: PostHog; flagVariant?: string | boolean; }; declare function captureFeatureInteraction(options: CaptureFeatureOptions): void; declare function captureFeatureView(options: CaptureFeatureOptions): void; //#endregion //#region src/components/PostHogCaptureOnViewed.d.ts type PostHogCaptureOnViewedProps = React.HTMLProps<HTMLDivElement> & { name?: string; properties?: Record<string, any>; observerOptions?: IntersectionObserverInit; trackAllChildren?: boolean; }; declare function PostHogCaptureOnViewed({ name, properties, observerOptions, trackAllChildren, children, ...props }: PostHogCaptureOnViewedProps): ReactElement<any, any>; //#endregion //#region src/components/PostHogErrorBoundary.d.ts type Properties = Record<string, any>; type PostHogErrorBoundaryFallbackProps = { error: unknown; exceptionEvent: unknown; componentStack: string; resetError?: () => void; }; type PostHogErrorBoundaryProps = { children?: React.ReactNode | (() => React.ReactNode); fallback?: React.ReactNode | FunctionComponent<PostHogErrorBoundaryFallbackProps>; additionalProperties?: Properties | ((error: unknown, errorInfo: React.ErrorInfo) => Properties); }; type PostHogErrorBoundaryState = { componentStack: string | null; exceptionEvent: unknown; error: unknown; }; declare class PostHogErrorBoundary extends React.Component<PostHogErrorBoundaryProps, PostHogErrorBoundaryState> { static contextType: React.Context<PostHogContextValue>; context: React.ContextType<typeof PostHogContext>; constructor(props: PostHogErrorBoundaryProps); componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void; private _resetError; render(): React.ReactNode; } //#endregion //#region src/helpers/error-helpers.d.ts declare const setupReactErrorHandler: (client: PostHog, callback?: (event: CaptureResult | undefined, error: any, errorInfo: ErrorInfo) => void) => (error: any, errorInfo: ErrorInfo) => void; //#endregion export { type PostHog, PostHogCaptureOnViewed, PostHogCaptureOnViewedProps, PostHogContext, PostHogErrorBoundary, type PostHogErrorBoundaryFallbackProps, type PostHogErrorBoundaryProps, PostHogFeature, PostHogFeatureProps, PostHogProvider, captureFeatureInteraction, captureFeatureView, setupReactErrorHandler, useActiveFeatureFlags, useFeatureFlagEnabled, useFeatureFlagPayload, useFeatureFlagResult, useFeatureFlagVariantKey, usePostHog };