@tjoc/analytics
v2.2.0
Published
Analytics SDK for TJOC platform using PostHog
Maintainers
Readme
@tjoc/analytics
Status: parked. No portfolio product currently emits structured analytics events. Adoption requires a portfolio-level decision on whether PostHog is the analytics provider — that decision has not been made. Do not adopt this package until the observability/measurement RFC lands.
PostHog analytics SDK for the tjoc.dev portfolio. Supports both React and non-React environments with hooks for event tracking, feature flags, and A/B testing.
Usage (when unparked)
Non-React
import { analytics } from '@tjoc/analytics';
analytics.trackEvent('button_clicked', { buttonName: 'submit', page: 'checkout' });
analytics.trackPageView('/checkout', { referrer: '/cart' });
analytics.identify('user123', { name: 'John Doe', email: '[email protected]' });React
import { AnalyticsProvider } from '@tjoc/analytics';
function App() {
return (
<AnalyticsProvider config={{
apiKey: process.env.POSTHOG_API_KEY!,
apiHost: 'https://app.posthog.com',
capturePageView: true,
}}>
{/* Your app */}
</AnalyticsProvider>
);
}React hooks
import { useTrackEvent, useFeatureFlag, useExperiment, useIdentify } from '@tjoc/analytics';
// Event tracking
const { trackEvent, trackPageView } = useTrackEvent('user123');
trackEvent('form_submitted', { form: 'signup' });
// Feature flags
const { isEnabled, isLoading } = useFeatureFlag('new-feature');
// A/B experiments
const { variant } = useExperiment('button-color');
// User identification
const identify = useIdentify('user123');
identify({ name: 'John Doe', plan: 'premium' });Configuration
interface AnalyticsConfig {
apiKey: string;
apiHost?: string;
debug?: boolean;
capturePageView?: boolean;
persistence?: 'localStorage' | 'cookie' | 'memory';
}Dependencies
posthog-node@^4.13.0
Development
pnpm build # tsup → dist/
pnpm test # jest