UNPKG

@adkit.so/meta-pixel-react

Version:

React wrapper for Meta Pixel tracking with TypeScript support

99 lines (94 loc) 2.82 kB
import { MetaPixelConfig, MetaPixelInterface } from '@adkit.so/meta-pixel'; export { EventData, EventMetaData, MetaPixelConfig, MetaPixelInterface, StandardEvent } from '@adkit.so/meta-pixel'; import React, { ReactNode } from 'react'; /** * useMetaPixel - Hook to access Meta Pixel tracking methods * * Can be used in two ways: * * 1. **Standalone (Recommended)**: Initialize once at your app root, then use anywhere * 2. **With Provider**: Use within a MetaPixelProvider for React Context pattern * * @param config - Optional config to initialize Meta Pixel (only needed once at app root) * @returns Meta Pixel instance with track, trackCustom, and isLoaded methods * * @example * **Standalone Usage (Simpler):** * ```tsx * // App.tsx - Initialize once * function App() { * useMetaPixel({ pixelIds: 'YOUR_PIXEL_ID' }) * return <YourApp /> * } * * // Any component - Just use it * function MyComponent() { * const meta = useMetaPixel() * meta.track('Purchase', { value: 99.99, currency: 'USD' }) * } * ``` * * @example * **With Provider (Alternative):** * ```tsx * // App.tsx * <MetaPixelProvider pixelIds="YOUR_PIXEL_ID"> * <YourApp /> * </MetaPixelProvider> * * // Any component * function MyComponent() { * const meta = useMetaPixel() * meta.track('Purchase', { value: 99.99, currency: 'USD' }) * } * ``` */ declare function useMetaPixel(config?: MetaPixelConfig): MetaPixelInterface; /** * Initialize Meta Pixel (non-hook version) * * Call this once in your app root if you prefer not to use hooks. * * @param config - Meta Pixel configuration * * @example * ```tsx * // main.tsx or App.tsx * import { initMetaPixel } from '@adkit.so/meta-pixel-react' * * initMetaPixel({ pixelIds: 'YOUR_PIXEL_ID' }) * * // Then use the hook anywhere * import { useMetaPixel } from '@adkit.so/meta-pixel-react' * * function MyComponent() { * const meta = useMetaPixel() * meta.track('Purchase', { value: 99.99, currency: 'USD' }) * } * ``` */ declare function initMetaPixel(config: MetaPixelConfig): void; interface MetaPixelProviderProps extends MetaPixelConfig { children: ReactNode; } /** * MetaPixelProvider - Initializes Meta Pixel tracking * * Wrap your app with this provider to enable Meta Pixel tracking throughout your application. * * @example * ```tsx * import { MetaPixelProvider } from '@adkit.so/meta-pixel-react' * * function App() { * return ( * <MetaPixelProvider pixelIds="YOUR_PIXEL_ID"> * <YourApp /> * </MetaPixelProvider> * ) * } * ``` */ declare function MetaPixelProvider({ children, pixelIds, autoTrackPageView, debug, enableLocalhost, }: MetaPixelProviderProps): React.JSX.Element; export { MetaPixelProvider, initMetaPixel, useMetaPixel }; export type { MetaPixelProviderProps };