@astuteo/ph-enhancer
v1.0.4
Published
PostHog enhancer utilities for Astuteo projects.
Maintainers
Readme
PostHog Enhancer
A utility for tracking custom user interactions using PostHog.
Installation
npm install @astuteo/ph-enhancer
# or
yarn add @astuteo/ph-enhancerBuild Information
This package uses Rollup to create multiple distribution formats:
- UMD (Universal Module Definition): For direct use in browsers via script tags
- CommonJS: For Node.js environments
- ES Modules: For modern bundlers like webpack, Rollup, or Parcel
The build process creates these files in the dist directory when you run npm run build.
Usage
Basic Setup
import posthog from 'posthog-js';
import tracking from '@astuteo/ph-enhancer';
// Initialize PostHog first
posthog.init('your-posthog-api-key', {
api_host: 'https://your-posthog-host.com',
});
// Then initialize the tracking module
tracking.init({
authKey: 'your-auth-key', // Optional: for organization tracking
});Using Named Exports
You can also import specific functions:
import { trackSearch, trackThemePreference, EVENTS } from '@astuteo/ph-enhancer';
// Track a search event
trackSearch({
query: 'example search',
resultsCount: 10,
category: 'products'
});
// Manually track theme preference
trackThemePreference();Features
- Theme Preference Tracking: Automatically tracks user's light/dark mode preference
- Search Tracking: Track search queries and results
- Organization Tracking: Track organization information including name and ISP status (requires backend API)
API Reference
Main Methods
init(options): Initialize the tracking modulecleanup(): Clean up tracking resources (remove event listeners)trackThemePreference(): Track the user's theme preferencetrackSearch(data): Track search eventstrackOrganization(authKey): Track organization information
Events
import { EVENTS } from '@astuteo/ph-enhancer';
// Available event types
EVENTS.THEME_PREFERENCE // 'theme_preference'
EVENTS.SEARCH // 'search'
EVENTS.ORGANIZATION // 'organization'License
MIT
