Usermaven JavaScript SDK is a powerful and flexible library for tracking user behavior and events in web applications. It supports both client-side and server-side usage, with a focus on privacy, configurability, and robustness.
- Cross-platform compatibility (browser and server-side)
- Flexible event tracking with custom payloads
- Automatic tracking of page views, form submissions, and user interactions
- Privacy-focused with configurable data sanitization
- Robust error handling and retry mechanisms
- Extensible architecture for custom tracking features
- Performance optimizations including event batching and debouncing
npm install @usermaven/sdk-js
or
yarn add @usermaven/sdk-js
For quick integration without a module bundler:
<script src="https://cdn.usermaven.com/sdk/v1/lib.js"
data-key="YOUR_API_KEY"
data-tracking-host="https://events.yourdomain.com">
</script>
import { usermavenClient } from '@usermaven/sdk-js';
const client = usermavenClient({
key: 'YOUR_API_KEY',
trackingHost: 'https://events.yourdomain.com'
});
// Track an event
client.track('button_click', {
buttonId: 'submit-form'
});
// Identify a user
client.id({
id: 'user123',
email: '[email protected]',
name: 'John Doe',
created_at: '2021-01-01'
});
// Track a page view
client.pageview();
<script>
// Track an event
usermaven('track', 'button_click', {
buttonId: 'submit-form'
});
// Identify a user
usermaven('id', {
id: 'user123',
email: '[email protected]',
name: 'John Doe',
created_at: '2021-01-01'
});
// Track a page view
usermaven('pageview');
</script>
const client = usermavenClient({
key: 'YOUR_API_KEY',
trackingHost: 'https://events.yourdomain.com',
cookieDomain: '.yourdomain.com',
logLevel: '1',
useBeaconApi: false,
autocapture: true,
formTracking: 'all',
autoPageview: true
// ... other options
});
See the Config
interface in src/core/config.ts
for all configuration options.
const { usermavenClient } = require('@usermaven/sdk-js');
const client = usermavenClient({
key: 'YOUR_API_KEY',
trackingHost: 'https://events.yourdomain.com'
});
client.track('server_event', {
userId: 'user123',
action: 'item_purchased'
});
Track a custom event.
Identify a user and set their properties.
Associate the user with a group (e.g. company).
Track a page view event.
Set persistent properties to be included with all future events.
Remove a persistent property.
Reset the client's state and remove local data.
- Clone the repository
- Install dependencies:
npm install
- Run tests:
npm test
- Build:
npm run build
This project is licensed under the MIT License - see the LICENSE file for details.
For each major JavaScript platform, there is a specific high-level SDK that provides all the tools you need in a single package.
Please refer to the README and instructions of those SDKs for more detailed information:
- @usermaven/sdk-js - SDK for Browsers and Node. Works with any JS framework
- @usermaven/nextjs - SDK for NextJS applications
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.