Skip to Content
🎉 OmniOptimize SDK v0.2.0 released - Check out the new features!
Getting Started

Getting Started

Install the SDK and initialize it in your application.

Installation

bash npm install @omni-analytics/sdk

Initialize the SDK

Call initializeSDK() as early as possible in your application. For Next.js and React apps, this is typically in your root layout or app entry point.

import { initializeSDK } from "@omni-analytics/sdk"; initializeSDK({ projectId: "<your-project-id>", endpoint: "https://omnioptimize-vdvv.onrender.com/ingest", batchSize: 30, batchTimeout: 2000, replay: { enabled: true, }, });

Configuration parameters

ParameterTypeDefaultDescription
projectIdstringrequiredYour Omni Analytics project ID
endpointstringrequiredBackend endpoint for event ingestion
batchSizenumber30Events to batch before sending
batchTimeoutnumber2000Milliseconds before flushing incomplete batch
replay.enabledbooleantrueEnable session replay recording
debugbooleantrueEnable debug mode logging

Next.js (App Router)

Add initialization to your root layout:

// app/layout.ts import { initializeSDK } from "@omni-analytics/sdk"; initializeSDK({ projectId: "<your-project-id>", endpoint: "https://omnioptimize-vdvv.onrender.com/ingest", replay: { enabled: true, }, }); export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( <html lang="en"> <body>{children}</body> </html> ); }

React SPA

Initialize at the entry point:

// main.tsx import React from "react"; import ReactDOM from "react-dom/client"; import { initializeSDK } from "@omni-analytics/sdk"; import App from "./App"; initializeSDK({ projectId: "<your-project-id>", endpoint: "https://omnioptimize-vdvv.onrender.com/ingest", replay: { enabled: true, }, }); ReactDOM.createRoot(document.getElementById("root")!).render( <React.StrictMode> <App /> </React.StrictMode> );

Verify initialization

Once initialized, Omni Analytics will begin automatically tracking events. You should see:

  • Page view events when the page loads
  • Click events when users interact with the page
  • Session start events

Check your analytics dashboard to confirm events are arriving.

Troubleshooting

No events are appearing?

  • Verify projectId and endpoint are correct
  • Check browser console for errors
  • Ensure the SDK is initialized before the DOM is ready
  • Confirm your ad blocker isn’t blocking analytics requests

Events are batched slowly

Adjust batchSize and batchTimeout to control when events are sent:

initializeSDK({ projectId: "<your-project-id>", endpoint: "https://omnioptimize-vdvv.onrender.com/ingest", batchSize: 10, // Send after 10 events batchTimeout: 1000, // Or after 1 second replay: { enabled: true, }, });

Lower values send events more frequently but use more bandwidth. Higher values batch more efficiently but have higher latency.


Beta: This SDK is actively developed. If you encounter issues, please report them.

Last updated on