Skip to content

Analytics

@guideflow/analytics provides event collection, transport adapters, and A/B testing without adding third-party SDKs as hard dependencies.

Event Collection

ts
import { AnalyticsCollector, PostHogTransport, WebhookTransport } from '@guideflow/analytics';

const collector = new AnalyticsCollector({
  userId: currentUser.id,
  globalProperties: { plan: 'pro', appVersion: '2.1.0' },
})
  .addTransport(new PostHogTransport())
  .addTransport(new WebhookTransport({ url: '/api/analytics', batchIntervalMs: 5000 }));

collector.attach(gf);

Events emitted

EventWhen
guideflow.tour.startedgf.start() called
guideflow.tour.completedTour finished naturally
guideflow.tour.skippedUser dismissed the tour
guideflow.step.viewedUser enters a step
guideflow.step.exitedUser leaves a step (includes dwell_ms)
guideflow.step.completedStep marked complete
guideflow.step.abandonedStep dismissed mid-tour

Transports

TransportWindow global
PostHogTransportwindow.posthog
MixpanelTransportwindow.mixpanel
AmplitudeTransportwindow.amplitude
SegmentTransportwindow.analytics
WebhookTransportfetch (no global needed)

A/B Testing

ts
import { ExperimentEngine } from '@guideflow/analytics';

const engine = new ExperimentEngine(currentUser.id);

const { value: theme } = engine.assign({
  id: 'tour-theme-2024',
  variants: [
    { id: 'control',   value: 'minimal', weight: 50 },
    { id: 'treatment', value: 'bold',    weight: 50 },
  ],
});

const gf = createGuideFlow({ theme });

Assignments are deterministic: the same userId + experimentId always produces the same variant — no server needed.

Released under the MIT License.