posthog-js
Version:
Posthog-js allows you to automatically capture usage and send events to PostHog.
96 lines (82 loc) • 4.29 kB
TypeScript
import * as React from 'react';
import React__default, { ReactElement, FunctionComponent, ErrorInfo } from 'react';
import * as posthog_js from 'posthog-js';
import { PostHog, BootstrapConfig, PostHogConfig, JsonType, FeatureFlagResult, CaptureResult } from 'posthog-js';
export { PostHog } from 'posthog-js';
declare const PostHogContext: React.Context<{
client: PostHog;
bootstrap?: BootstrapConfig;
}>;
type WithOptionalChildren<T> = T & {
children?: React__default.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>;
declare function useFeatureFlagEnabled(flag: string): boolean | undefined;
declare function useFeatureFlagEnabled(flag: string, defaultValue: boolean): boolean;
declare function useFeatureFlagPayload(flag: string): JsonType;
declare function useFeatureFlagResult(flag: string): FeatureFlagResult | undefined;
declare function useActiveFeatureFlags(): string[];
declare function useFeatureFlagVariantKey(flag: string): string | boolean | undefined;
declare const usePostHog: () => PostHog;
type PostHogFeatureProps = Omit<React__default.HTMLProps<HTMLDivElement>, 'children'> & {
flag: string;
children: React__default.ReactNode | ((payload: any) => React__default.ReactNode);
fallback?: React__default.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;
type PostHogCaptureOnViewedProps = React__default.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>;
type Properties = Record<string, any>;
type PostHogErrorBoundaryFallbackProps = {
error: unknown;
exceptionEvent: unknown;
componentStack: string;
};
type PostHogErrorBoundaryProps = {
children?: React__default.ReactNode | (() => React__default.ReactNode);
fallback?: React__default.ReactNode | FunctionComponent<PostHogErrorBoundaryFallbackProps>;
additionalProperties?: Properties | ((error: unknown, errorInfo: React__default.ErrorInfo) => Properties);
};
type PostHogErrorBoundaryState = {
componentStack: string | null;
exceptionEvent: unknown;
error: unknown;
};
declare class PostHogErrorBoundary extends React__default.Component<PostHogErrorBoundaryProps, PostHogErrorBoundaryState> {
static contextType: React__default.Context<{
client: posthog_js.PostHog;
bootstrap?: posthog_js.BootstrapConfig;
}>;
context: React__default.ContextType<typeof PostHogContext>;
constructor(props: PostHogErrorBoundaryProps);
componentDidCatch(error: unknown, errorInfo: React__default.ErrorInfo): void;
render(): React__default.ReactNode;
}
declare const setupReactErrorHandler: (client: PostHog, callback?: (event: CaptureResult | undefined, error: any, errorInfo: ErrorInfo) => void) => (error: any, errorInfo: ErrorInfo) => void;
export { PostHogCaptureOnViewed, PostHogContext, PostHogErrorBoundary, PostHogFeature, PostHogProvider, captureFeatureInteraction, captureFeatureView, setupReactErrorHandler, useActiveFeatureFlags, useFeatureFlagEnabled, useFeatureFlagPayload, useFeatureFlagResult, useFeatureFlagVariantKey, usePostHog };
export type { PostHogCaptureOnViewedProps, PostHogErrorBoundaryFallbackProps, PostHogErrorBoundaryProps, PostHogFeatureProps };