Apps
JavaScript & React Native
SDK for web apps (SPAs), React Native, Node.js 18+ and Electron. Dependency-free, no cookies, no localStorage.
SDK or script?
For classic websites the one-line tracking script is usually enough. Use the SDK for explicit screen/event tracking, batching, or outside a browser.
Install
The npm package @trackd/sdk is coming (not published yet). Copy-in:
curl -o src/lib/trackd.mjs https://trackd.one/sdk/trackd.mjs
curl -o src/lib/trackd.d.mts https://trackd.one/sdk/trackd.d.ts # optional types
import { Trackd } from './lib/trackd.mjs'
const trackd = new Trackd({ websiteId: 'YOUR_WEBSITE_ID', host: 'https://trackd.one' })
trackd.screen('Home')
trackd.event('signup', { plan: 'pro' })
trackd.revenue(9.99, 'EUR', 'order-123')
Without a bundler use the UMD build trackd.js (exposes window.Trackd).
API
trackd.screen('Settings/Profile', 'Profile')
trackd.event('signup', { plan: 'pro', trial: true }) // flat data
await trackd.flush() // never rejects
trackd.setEnabled(false) // opt-out
Options: enabled, respectDoNotTrack (browser, default true), autoFlushOnHide, flushAt (20), flushInterval (10000 ms; React Native 30000 ms), maxQueueSize (500), sessionTimeout (30 min).
Web SPA
// React Router
function TrackScreens() {
const location = useLocation()
useEffect(() => { trackd.screen(location.pathname) }, [location.pathname])
return null
}
// Vue Router
router.afterEach((to) => trackd.screen(to.path))
React Native
import { AppState, Platform } from 'react-native'
import { Trackd } from './lib/trackd.mjs'
export const trackd = new Trackd({
websiteId: 'YOUR_WEBSITE_ID',
platform: Platform.OS === 'ios' && Platform.isPad ? 'ipados' : Platform.OS,
appVersion: '1.4.0',
})
AppState.addEventListener('change', (state) => {
if (state === 'background') trackd.onBackground()
else if (state === 'active') trackd.onForeground()
})
Track screens with React Navigation in onReady / onStateChange of the NavigationContainer. Enter the bundle id as “domain” in the dashboard.
Node.js & Electron
const trackd = new Trackd({ websiteId: process.env.TRACKD_ID, platform: 'node', appVersion: '3.0.0' })
trackd.event('command_run', { command: 'deploy', ok: true })
await trackd.flush() // timers never keep the process alive
Ready in minutes
Create a free account, add your website or app, copy the snippet.