TypeScript Types#

Pulsora ships with full TypeScript support. This page catalogs the most important interfaces you can import from the packages.

Core Package (@pulsora/core)#

import type {
  PulsoraConfig,
  PageviewOptions,
  EventData,
  PulsoraCore,
  PulsoraExtension,
  TrackingData,
} from '@pulsora/core';

PulsoraConfig#

interface PulsoraConfig {
  apiToken: string;
  endpoint?: string;
  autoPageviews?: boolean;
  debug?: boolean;
  maxRetries?: number;
  retryBackoff?: number;
}

PageviewOptions#

interface PageviewOptions {
  url?: string;
  referrer?: string;
  title?: string;
}

PulsoraCore#

interface PulsoraCore {
  init(config: PulsoraConfig): void;
  pageview(options?: PageviewOptions): void;
  event(eventName: string, eventData?: EventData): void;
  identify(customerId: string): void;
  reset(): void;
  getVisitorFingerprint(): Promise<string | null>;
  getSessionId(): string;
  isIdentified(): boolean;
  use(extension: PulsoraExtension): void;
}

TrackingData#

Internal representation of events sent to the API:

interface TrackingData {
  type: 'pageview' | 'event' | 'identify';
  visitor_fingerprint: string;
  session_id: string;
  url?: string;
  path?: string;
  referrer?: string;
  referrer_source?: string;
  title?: string;
  locale?: string;
  event_name?: string;
  event_data?: EventData;
  customer_id?: string;
  utm_source?: string;
  utm_medium?: string;
  utm_campaign?: string;
  utm_term?: string;
  utm_content?: string;
  timestamp: number;
}

Revenue Package (@pulsora/revenue)#

import type {
  RevenueConfig,
  RevenueData,
  RevenueTrackingData,
} from '@pulsora/revenue';

RevenueConfig#

interface RevenueConfig {
  apiToken: string;
  endpoint?: string;
  debug?: boolean;
  maxRetries?: number;
  retryBackoff?: number;
}

RevenueData#

interface RevenueData {
  visitor_fingerprint: string;
  session_id: string;
  customer_id: string;
  amount: number;
  currency?: string;
  transaction_id: string;
  payment_processor?: string;
  event_type?:
    | 'purchase'
    | 'subscription'
    | 'renewal'
    | 'upgrade'
    | 'downgrade'
    | 'churn'
    | 'refund';
  customer_subscription_id?: string;
  mrr_impact?: number;
  is_recurring?: boolean;
  metadata?: Record<string, any>;
}

RevenueTrackingData#

Represents the payload after validation:

interface RevenueTrackingData extends RevenueData {
  type: 'revenue';
  currency: string;
}

React Package (@pulsora/react)#

import type {
  PulsoraProviderProps,
  PulsoraContextValue,
  UsePageviewOptions,
  TrackEventFunction,
  UseIdentifyReturn,
} from '@pulsora/react';

PulsoraProviderProps#

interface PulsoraProviderProps {
  config: PulsoraConfig;
  children: React.ReactNode;
}

PulsoraContextValue#

interface PulsoraContextValue {
  pulsora: PulsoraCore | null;
  isReady: boolean;
  isIdentified: boolean;
  error: Error | null;
}

Hooks#

type TrackEventFunction = (
  eventName: string,
  eventData?: EventData,
) => Promise<void>;

interface UsePageviewOptions {
  trigger?: any;
  disabled?: boolean;
}

interface UseIdentifyReturn {
  identify: (customerId: string) => Promise<void>;
  isIdentified: boolean;
  reset: () => void;
}

Type Re-exports#

@pulsora/react re-exports core types (PulsoraConfig, PulsoraCore, EventData) so you can import everything from a single package when building React apps.

Need error semantics? Check API Errors →