nugi-browser-logs-sdk
v1.0.1
Published
Lightweight browser SDK for Nugi Logs — pageviews, custom events, and client error tracking with batched public-key ingest.
Maintainers
Readme
nugi-browser-logs-sdk
Lightweight browser SDK for Nugi Logs — pageviews, custom events, and client errors with batched public-key ingest.
Install
npm install nugi-browser-logs-sdk
# or
pnpm add nugi-browser-logs-sdkQuick start
import { init, nugi } from "nugi-browser-logs-sdk";
init({
appId: import.meta.env.VITE_NUGI_APP_ID,
publicKey: import.meta.env.VITE_NUGI_PUBLIC_KEY, // nugi_pk_… only
endpoint: import.meta.env.VITE_NUGI_ENDPOINT, // https://host or https://host/api/v1
serviceName: "web",
environment: "production",
// capturePageviews: true, // default
// captureErrors: true, // default
});
// Product events
nugi.track("checkout_started", { plan: "pro" });
// Manual pageview (usually automatic)
nugi.pageview();
// Handled errors
try {
// …
} catch (err) {
nugi.captureException(err, { feature: "checkout" });
}
// Identify after login
nugi.identify(user.id, { email: user.email });
// On logout
nugi.reset();Auth
Use the Public Key (nugi_pk_…) from Settings → Credentials.
Send headers:
X-App-IdX-Public-Key
Never put the secret API Key in a browser bundle.
What it captures
| Feature | Default |
| --- | --- |
| $pageview on load + SPA history | on |
| window.onerror / unhandledrejection | on |
| Custom track() events | manual |
| sessionId (tab-scoped) | on |
| identify / reset | manual |
| Batch flush | ~1s or 20 events / pagehide |
React
// main.tsx
import { init } from "nugi-browser-logs-sdk";
import { createRoot } from "react-dom/client";
import App from "./App";
init({
appId: import.meta.env.VITE_NUGI_APP_ID,
publicKey: import.meta.env.VITE_NUGI_PUBLIC_KEY,
endpoint: import.meta.env.VITE_NUGI_ENDPOINT,
});
createRoot(document.getElementById("root")!).render(<App />);License
MIT
