Skip to content

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

npm install @trackdone/sdk

TypeScript types are included. Without npm, copy the file 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.mts  # optional types
import { Trackd } from '@trackdone/sdk'   // or './lib/trackd.mjs' with copy-in

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 (UMD build, exposes window.Trackd):

<script src="https://trackd.one/sdk/trackd.js"></script>
<script>
  const trackd = new Trackd({ websiteId: 'YOUR_WEBSITE_ID' })
  trackd.screen('Home')
</script>

Files: trackd.mjs (ES module), trackd.js (UMD), trackd.d.mts (types for trackd.mjs, same folder and base name) or trackd.d.ts (for trackd.js).

Track purchases & revenue

Send revenue right after a successful purchase — in the success callback of your payment provider (e.g. Stripe, Paddle or react-native-iap), not when the “Buy” button is clicked:

// amount, currency (default: EUR), order id (optional)
trackd.revenue(9.99, 'EUR', 'order-123')

The event is called purchase and carries { amount, currency, order_id }. It shows up under Revenue and can be a funnel step: a Paywall → purchase funnel (screen / page view /paywall → event purchase) shows how many sessions with a paywall actually buy. The Analytics page calculates this conversion automatically once it detects a paywall screen, and Funnels has a template for it. Currencies and edge cases: Revenue tracking.

API

const trackd = new Trackd({
  websiteId: 'YOUR_WEBSITE_ID',   // required
  host: 'https://trackd.one',     // self-hosted? URL of your instance (HTTPS)
  platform, appVersion, osVersion, screen, language, device, // auto-detected where possible
  debug: false,
})

trackd.screen('Settings/Profile', 'Profile')           // with title
trackd.event('signup', { plan: 'pro', trial: true })   // flat data
await trackd.flush()                                   // send now (never rejects)
trackd.setEnabled(false)                               // opt-out: stop + clear the queue

More options: enabled, respectDoNotTrack (browser, default true), autoFlushOnHide, flushAt (20), flushInterval (10000 ms; React Native 30000 ms), maxQueueSize (500), sessionTimeout (30 min), requestTimeout / requestTimeoutMs (15 s — a hanging request is aborted and retried). destroy() is final: it removes listeners and timers and ignores later calls — await trackd.flush() first if the queue should still be sent.

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))

In the browser the SDK detects platform: "web", screen size, language and device class and sends the queue via navigator.sendBeacon when the tab is hidden. Global Privacy Control / Do Not Track turn tracking off unless you set respectDoNotTrack: false. Web requests must come from the registered domain.

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,
  // Platform.Version: iOS version (e.g. "18.1"); on Android it is the API level (35) → use the release string
  osVersion: Platform.OS === 'ios' ? `iOS ${Platform.Version}` : `Android ${Platform.constants.Release}`,
  appVersion: '1.4.0',
  device: Platform.isPad ? 'tablet' : 'mobile',
})

// Send when the app goes to the background, start a new session after 30 min away
AppState.addEventListener('change', (state) => {
  if (state === 'background') trackd.onBackground()
  else if (state === 'active') trackd.onForeground()
})

For screen tracking with React Navigation call trackd.screen(route.name) in onReady and onStateChange of the NavigationContainer. React Native requests have no Origin header — enter the bundle id as “domain” in the dashboard. Android release builds need the INTERNET permission (included in the templates).

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 })

// Timers never keep the process alive — send before exiting:
await trackd.flush()

Use platform: 'node' (or 'server') for CLIs, servers and backends. In Electron the platform and device: "desktop" are detected automatically.

Ready in minutes

Start the 7-day free trial (no credit card), add your website or app, copy the snippet.

Start free trial