@fixture-inc/tracker-core
v0.1.2
Published
Core tracking logic for Fixture - environment agnostic
Downloads
321
Readme
@fixture-inc/tracker-core
Environment-agnostic core tracking logic for Fixture.
Installation
pnpm add @fixture-inc/tracker-coreUsage
import { Tracker, MemoryStorage, NoopTransport } from '@fixture-inc/tracker-core'
const tracker = new Tracker({
propertyId: 'your-property-id',
apiUrl: 'https://api.fixture.app', // optional, this is the default
debug: false,
storage: new MemoryStorage(), // or implement StorageAdapter
transport: new NoopTransport(), // or implement TransportAdapter
})
tracker.trackPageview()
tracker.trackEvent('button_click', { location: 'header' })API
Tracker
interface TrackerConfig {
propertyId: string
apiUrl?: string // Default: 'https://api.fixture.app'
debug?: boolean
storage?: StorageAdapter // Pluggable storage for visitor ID
transport?: TransportAdapter // Pluggable transport for sending data
}
class Tracker {
getVisitorId(): string
resetVisitorId(): string
trackPageview(options?: { url?: string }): void
trackEvent(name: string, properties?: Record<string, unknown>): void
}Adapters
Implement these interfaces to customize storage and transport:
interface StorageAdapter {
get(): string | null
set(value: string): void
}
interface TransportAdapter {
send(url: string, payload: TrackPayload): void
}Built-in adapters:
MemoryStorage- In-memory storage (for testing/SSR)NoopTransport- No-op transport (for testing/SSR)
When to Use
Use tracker-core directly when:
- Building a custom tracker for a non-browser environment
- You need full control over storage and transport
- Building your own framework integration
For most use cases, use:
@fixture-inc/tracker-browser- Script tag or browser bundler@fixture-inc/tracker-react- React applications
