@retenshun/js
v1.1.0
Published
Official Retenshun JavaScript SDK for event tracking, user identification, and e-commerce analytics.
Maintainers
Readme
@retenshun/js
Official JavaScript SDK for Retenshun — AI-powered retention analytics.
Install
npm install @retenshun/jsOr via CDN:
<script src="https://cdn.retenshun.com/js/v1/retenshun.min.js"></script>Quick Start
import Retenshun from '@retenshun/js'
// Initialize
Retenshun.init({
projectId: 'proj_abc123',
apiKey: 'pk_live_your_key',
})
// Identify user
Retenshun.identify('user_123', {
email: '[email protected]',
name: 'John Doe',
plan: 'pro',
})
// Track event
Retenshun.track('button_clicked', {
button: 'cta',
screen: 'home',
})API
Retenshun.init(config)
| Option | Default | Description |
|---|---|---|
| projectId | required | Your Retenshun project ID |
| apiKey | required | Your public API key |
| apiUrl | https://api.retenshun.com/v1 | Custom API base URL |
| debug | false | Enable debug logging |
| autoTrack.pageViews | true | Auto-track page views (SPA-aware) |
| autoTrack.clicks | false | Auto-track button/link clicks |
| autoTrack.forms | false | Auto-track form submissions |
Retenshun.identify(userId, properties?)
Identify a user. Call on login or registration.
Retenshun.track(eventName, properties?)
Track a custom event.
Retenshun.page(pageName?, properties?)
Track a page view. Automatically captures URL, path, and referrer.
Retenshun.setUserProperties(properties)
Update user properties without re-identifying.
Retenshun.reset()
Reset the user identity (call on logout).
E-commerce
Retenshun.ecommerce.productViewed({ product_id: 'prod_1', price: 79.99 })
Retenshun.ecommerce.addedToCart({ product_id: 'prod_1', quantity: 1 })
Retenshun.ecommerce.checkoutStarted({ total: 79.99 })
Retenshun.ecommerce.orderCompleted({ order_id: 'ord_1', total: 79.99 })For React
Use @retenshun/react for React hooks and components.
