@esauti/browser
v1.0.0
Published
Browser SDK for eSauti: consent-gated tracking loader, SPA page tracking, form embed, focus.
Maintainers
Readme
@esauti/browser
Browser SDK for eSauti focused on:
- Consent-gated tracking loader (loads
mtc.jsonly when allowed) - SPA page tracking helpers
- Form embedding (
/form/{id}) and Focus embedding (/focus/{id}.js)
This package is browser-only. For backend/server integrations, keep a separate SDK package (Node/Python/PHP).
Install
npm i @esauti/browserQuick start (vanilla / Vite)
import { createBrowserClient } from '@esauti/browser';
const esauti = createBrowserClient({
baseUrl: 'https://tenant.esauti.com',
token: 'YOUR_INTEGRATION_TOKEN', // optional (recommended for authenticated ingest)
source: 'web',
enableSpaAutoTracking: true, // auto track SPA navigation
shouldSendEvent: (evt) => true, // optional hook for consent enforcement
});
await esauti.init();
// When user gives consent:
await window.esauti_start_tracking?.();Tracking modes
Standard mode
- Loads tracker immediately on init.
- Sends initial pageview.
createBrowserClient({ baseUrl });Forms
Embed a form
Simple iframe embed (reliable across frameworks):
const cleanup = esauti.forms.mount(document.getElementById('form')!, {
formId: '123',
height: 720,
width: '100%',
});
// later
cleanup();The embed URL is: {baseUrl}/form/{id}.
Submit a form programmatically
A simple way to trigger form submission events without embedding the form:
esauti.forms.submit('123', {
email: '[email protected]',
});Focus
const stop = esauti.focus.enable({ focusId: '42', autoRefreshOnSpa: true });
// If you need to refresh manually:
esauti.focus.refresh('42');
stop();Focus loads: {baseUrl}/focus/{id}.js.
Identify (link app user -> tracked visitor)
If you implement an eSauti identify endpoint (recommended):
await esauti.identify({
external_id: 'user_123',
email: '[email protected]',
});API Reference (high level)
createBrowserClient(options)client.init()client.loadTracker()client.startTracking(extraAttrs?)client.trackPage(attrs?)client.forms.mount(el, {formId,...})client.forms.submit(formId, {...})client.focus.enable({focusId,...})client.identify(identity, extra?)
Build
npm run buildMIT License
