TrackingSDKs
React, Next.js and React Native
Provider, hooks and route-aware page views on top of the JavaScript SDK
All three packages build on @iforevents/browser and accept the same options and adapters.
React
npm install @iforevents/reactimport { IforeventsProvider, useTrack, usePageView } from "@iforevents/react";
import { useLocation } from "react-router-dom";
function PageViews() {
usePageView(useLocation().pathname); // one page view per route change
return null;
}
export function App() {
return (
<IforeventsProvider projectKey="pk_...">
<PageViews />
<Checkout />
</IforeventsProvider>
);
}
function Checkout() {
const track = useTrack();
return <button onClick={() => track("checkout_started", { items: 3 })}>Buy</button>;
}Hooks: useIforevents(), useTrack(), useIdentify(), usePageView(path?, props?).
Next.js (App Router)
npm install @iforevents/next// app/layout.tsx
import { IforeventsProvider } from "@iforevents/next";
export default function RootLayout({ children }) {
return (
<html><body>
<IforeventsProvider projectKey={process.env.NEXT_PUBLIC_IFOREVENTS_PROJECT_KEY!}>{children}</IforeventsProvider>
</body></html>
);
}Page views are sent on every navigation. Route handlers and server actions use the server entry:
import { getServerIforevents } from "@iforevents/next/server";
const { iforevents } = await getServerIforevents({ projectKey: process.env.IFOREVENTS_PROJECT_KEY! });
await iforevents.track("order_created", { total: 42 });The project key is public, so exposing it through NEXT_PUBLIC_ is intended.
React Native and Expo
npm install @iforevents/react-native @react-native-async-storage/async-storage
npm install react-native-device-info # optional, richer device contextimport { NavigationContainer, createNavigationContainerRef } from "@react-navigation/native";
import { createReactNativeIforevents, trackNavigation } from "@iforevents/react-native";
export const analytics = createReactNativeIforevents("pk_...");
const navRef = createNavigationContainerRef();
export default function App() {
return <NavigationContainer ref={navRef} {...trackNavigation(analytics, navRef)}>{/* screens */}</NavigationContainer>;
}
await analytics.identify("user_123", { plan: "pro" });
await analytics.track("purchase_completed", { total: 9.99 });The queue lives in AsyncStorage, so unsent events survive restarts, and the app going to the background triggers a flush.