tessl install tessl/npm-posthog-js@1.335.0PostHog Browser JS Library is a comprehensive browser analytics and feature management SDK that enables developers to capture user events, track product analytics, manage feature flags, record session replays, and implement feedback mechanisms like surveys and conversations in web applications.
The PostHog toolbar is an overlay interface that provides debugging, feature flag testing, heatmap viewing, and other development tools directly in your application. It's useful for development, QA testing, and debugging production issues.
Loads and displays the PostHog toolbar overlay on the current page.
/**
* Loads the PostHog toolbar
* @param params - Toolbar configuration parameters
* @returns True if toolbar loaded successfully, false otherwise
*/
function loadToolbar(params: ToolbarParams): boolean;Usage Examples:
// Load toolbar with default settings
posthog.loadToolbar({});
// Load toolbar with specific user intent
posthog.loadToolbar({
userIntent: 'heatmaps'
});
// Load toolbar with API key
posthog.loadToolbar({
apiURL: 'https://us.i.posthog.com',
temporaryToken: 'temp-token-123'
});/**
* Parameters for loading the toolbar
*/
interface ToolbarParams {
/**
* API URL for the toolbar
* @default Current api_host from config
*/
apiURL?: string;
/**
* Temporary authentication token
*/
temporaryToken?: string;
/**
* Action ID to jump to
*/
actionId?: string | number;
/**
* User intent for toolbar usage
*/
userIntent?: ToolbarUserIntent;
/**
* Toolbar source
*/
source?: ToolbarSource;
/**
* Toolbar version
*/
toolbarVersion?: ToolbarVersion;
/**
* Data attributes to use for element selection
* @default ['data-attr']
*/
dataAttributes?: string[];
/**
* Whether to use JS for selecting elements
* @default false
*/
jsURL?: boolean;
}/**
* User's intended use of the toolbar
*/
type ToolbarUserIntent =
| 'add-action'
| 'edit-action'
| 'heatmaps'
| 'flags'
| 'experiments'
| 'surveys';/**
* Source from which toolbar was loaded
*/
type ToolbarSource = 'url' | 'localstorage' | 'opt-in';/**
* Version of toolbar to load
*/
type ToolbarVersion = 'toolbar' | '2' | '3';Add __posthog parameter to your URL:
https://yourapp.com?__posthog=trueThis will prompt for authentication and load the toolbar.
// Load toolbar programmatically
posthog.loadToolbar({
userIntent: 'heatmaps'
});// Disable toolbar metrics (reduces overhead)
posthog.init('<your-project-api-key>', {
advanced_disable_toolbar_metrics: true
});// Load toolbar for heatmap analysis
function viewHeatmaps() {
posthog.loadToolbar({
userIntent: 'heatmaps'
});
}// Load toolbar to test feature flags
function testFeatureFlags() {
posthog.loadToolbar({
userIntent: 'flags'
});
}// Load toolbar to create actions
function createAction() {
posthog.loadToolbar({
userIntent: 'add-action'
});
}// Load toolbar for experiment viewing
function manageExperiments() {
posthog.loadToolbar({
userIntent: 'experiments'
});
}// Only load toolbar in non-production environments
if (process.env.NODE_ENV !== 'production') {
// Enable toolbar via URL or local storage
posthog.init('<your-project-api-key>', {
advanced_disable_toolbar_metrics: false
});
} else {
// Disable toolbar in production
posthog.init('<your-project-api-key>', {
advanced_disable_toolbar_metrics: true
});
}// Use custom data attributes for element selection
posthog.loadToolbar({
dataAttributes: ['data-test-id', 'data-analytics', 'data-attr']
});// Load toolbar based on user role
const userRole = getCurrentUserRole();
if (userRole === 'admin' || userRole === 'developer') {
posthog.loadToolbar({
userIntent: 'heatmaps'
});
}advanced_disable_toolbar_metrics: trueWhen the toolbar is loaded, these keyboard shortcuts are available: