window.Loguro API Reference
After the SDK script loads, all methods are on the global window.Loguro object. They split into two groups:
- Logging methods — single POST per call, immediate. Send to
{endpoint}/. - Analytics methods — buffered, flushed in batches. Send to
{endpoint}/batch.
If data-api-key is missing, the SDK does not install — window.Loguro will be undefined. Always feature-detect:
window.Loguro?.track('event_name'); Logging methods
These send a single log immediately. All take a message + optional context object.
Loguro.info(message, context?)
window.Loguro.info('User completed checkout', { order_id: '12345' }); Wire shape:
{
"level": "info",
"message": "User completed checkout",
"timestamp": "2026-05-14T10:00:00.000Z",
"context": { "order_id": "12345", "url": "...", "path": "...", ... }
} Loguro.debug(message, context?)
Same as info, with level: "debug". Use for verbose diagnostic info you want to filter out in production dashboards.
Loguro.warning(message, context?)
level: "warning". For recoverable issues — fallback rendered, retry succeeded, deprecated API used.
Loguro.error(message, context?)
level: "error". For caught exceptions or user-impacting failures:
try {
await fetchOrders();
} catch (err) {
window.Loguro.error('Failed to fetch orders', {
error_message: err.message,
error_stack: err.stack,
user_action: 'open_orders_page'
});
} Loguro.critical(message, context?)
level: "critical". For total feature breakage — alerting territory. Use sparingly.
Logging notes
- Rate limited to
data-max-per-minute(default 1000) across all levels. - Circuit breaker: 5 consecutive transport failures → 60-second pause.
- Page context (
url,path,viewport,user_agent) auto-merged into yourcontextifdata-captureincludescontext(default). - If
setEnabled(false)has been called, all log calls are no-ops.
Analytics methods
These add events to the batch buffer. Flushed when:
- 20 events accumulated
- 5 seconds since the first event in the current buffer
- 50 KB serialized
pagehide/visibilitychange:hidden/beforeunload(viasendBeacon)
Loguro.track(eventName, props?)
window.Loguro.track('cart_item_added', {
product_id: 'sku-123',
quantity: 2,
total_cents: 4900
}); Constraints:
eventNamemust be a non-empty string ≤ 64 chars. Longer → truncated withconsole.warn.propsserialized JSON must be ≤ 4 KB. Larger → event dropped withconsole.warn.- No-op if
data-analyticsdoesn’t includeevents(orall). - No-op if
setEnabled(false).
Loguro.pageview(opts?)
Manually fires a pageview. Useful for:
- Non-history-API SPA routing (rare)
- Modal-as-page flows
- After cookie-consent acceptance (catch the missed initial pageview)
window.Loguro.pageview(); // current URL + document.title
window.Loguro.pageview({ url: '/checkout/step-2' }); // override path
window.Loguro.pageview({ url: '/cart', title: 'Cart' }); Initial + SPA pageviews fire automatically when data-analytics includes pageviews (and spa for SPA). Manual calls are for edge cases.
Loguro.identify(userId, traits?)
window.Loguro.identify('user_42');
window.Loguro.identify('user_42', { plan: 'pro', team: 'acme' }); Sets user_id on all subsequent events in this session (and future sessions if data-analytics-persist-user="true").
If traits is provided, a custom event identify is fired with those traits — useful for tracking attribute changes (plan upgrades, role changes).
Past events are not retroactively updated.
Loguro.reset()
window.Loguro.reset(); Wipes:
visitor_id(new one generated on next event)session_iduser_id- Identity cookie (if
id-storage="cookie")
Call on logout. After reset, the next event represents a fresh anonymous visitor.
Loguro.setEnabled(enabled)
window.Loguro.setEnabled(false); // pause all events + logs
window.Loguro.setEnabled(true); // resume Runtime kill switch. When false:
- All log methods (
info,error, etc.) become no-ops track()becomes a no-oppageview()becomes a no-op- Auto-events (DOM clicks) become no-ops
- Buffered events that were already queued still flush on the next trigger — they’re not dropped
This is for cookie-consent flows where you load the script before consent, but want zero outbound traffic until the user opts in.
Properties (read-only)
The SDK does not expose visitor_id, session_id, or user_id on the public API. If you need them in your app for joining with server logs, generate your own IDs server-side and pass them as custom_props on track() calls.
TypeScript types
If you use TypeScript, add a declaration:
// loguro.d.ts
declare global {
interface Window {
Loguro?: {
info: (msg: unknown, ctx?: Record<string, unknown>) => void;
debug: (msg: unknown, ctx?: Record<string, unknown>) => void;
warning: (msg: unknown, ctx?: Record<string, unknown>) => void;
error: (msg: unknown, ctx?: Record<string, unknown>) => void;
critical: (msg: unknown, ctx?: Record<string, unknown>) => void;
track: (eventName: string, props?: Record<string, unknown>) => void;
pageview: (opts?: { url?: string; title?: string }) => void;
identify: (userId: string, traits?: Record<string, unknown>) => void;
reset: () => void;
setEnabled: (enabled: boolean) => void;
};
}
}
export {};