### Install dependencies and start the dev server Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/recharts.md Navigates into the project directory, installs dependencies, and starts the development server. ```bash cd rechart-ph npm install npm run dev ``` -------------------------------- ### Install Dependencies and Start PostHog.com Source: https://github.com/posthog/posthog.com/blob/master/README.md Install site dependencies using pnpm and start the development server. This command is used after cloning the repository and performing any necessary platform-specific setup. ```bash pnpm install pnpm start ``` -------------------------------- ### Run PostHog Installation Wizard Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/getting-started/_snippets/wizard.mdx Execute this command in your project directory to start the PostHog installation wizard. Follow the prompts to complete the setup. ```bash npx posthog create ``` -------------------------------- ### Install and Run PostHog.com Source: https://github.com/posthog/posthog.com/blob/master/CLAUDE.md Use these commands to install dependencies and start the development server. Requires Node.js 16GB RAM. ```bash pnpm install # Install dependencies (NOT npm) pnpm start # Dev server at localhost:8001 pnpm build # Production build pnpm clean # Clear Gatsby cache pnpm clean && mkdir .cache && pnpm i && pnpm start # Full reset when things break ``` -------------------------------- ### Install dependencies and start the development server Source: https://github.com/posthog/posthog.com/blob/master/contents/handbook/engineering/posthog-com/developing-the-website.md Commands to install dependencies and start the posthog.com development server using pnpm. ```bash pnpm install && pnpm start ``` -------------------------------- ### Install PostHog Go SDK Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/error-tracking/installation/go.mdx Install the PostHog Go SDK using the go get command. ```bash go get github.com/posthog/posthog-go ``` -------------------------------- ### Download and run PostHog Self Host TUI installer Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/self-host/index.mdx Use this command to download the TUI installer binary. Make it executable and then run it to start the installation process. ```bash curl -OfsSL https://github.com/PostHog/posthog/releases/download/hobby-latest/hobby-installer chmod +x hobby-installer ./hobby-installer ``` -------------------------------- ### Install Dependencies and Generate Audio Source: https://github.com/posthog/posthog.com/blob/master/scripts/hogfm/handbook/README.md Quick setup guide for the hogfm project. Navigate to the project directory, install dependencies using uv, set your ElevenLabs API key in a .env file, and then run the handbook-audio command for dry runs or actual audio generation. ```bash cd scripts/hogfm uv sync uv run handbook-audio --dry-run contents/handbook/values.md uv run handbook-audio contents/handbook/values.md ``` -------------------------------- ### Install Dependencies and Run Svelte App Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/svelte-analytics.md Navigate to your new Svelte app directory, install npm packages, and start the development server. ```bash cd my-app npm install npm run dev ``` -------------------------------- ### Run PostHog Installation Wizard Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/feature-flags/installation/index.mdx Execute this command in your project directory to initiate the PostHog installation wizard. It automates setup and works with LLM coding agents. ```bash curl -fsSL https://posthog.com/install.sh | sh ``` -------------------------------- ### Set up Virtual Environment and Install Flask Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/python-ab-testing.md Creates a Python virtual environment and installs the Flask framework. ```bash python3 -m venv venv . venv/bin/activate pip install Flask ``` -------------------------------- ### Create Go project and install PostHog library Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/go-ab-tests.md Initializes a Go module for a new project and installs the PostHog Go SDK. Run this command in your project directory. ```bash go mod init go-ab-tests go get github.com/posthog/posthog-go ``` -------------------------------- ### Git Add Example Source: https://github.com/posthog/posthog.com/blob/master/contents/handbook/engineering/posthog-com/developing-the-website.md Example of staging a specific documentation file. ```bash git add contents/docs/contribute/updating-documentation.md ``` -------------------------------- ### Initialize Go Project and Create Files Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/go-analytics.md Sets up a new Go project directory, initializes a Go module, and creates empty files for HTML templates and the main Go program. ```bash mkdir go-analytics cd go-analytics go mod init go-analytics touch login.html touch dashboard.html touch main.go ``` -------------------------------- ### PostHog Cloud Installation Command Source: https://github.com/posthog/posthog.com/blob/master/contents/blog/posthog-alternatives.mdx This command initiates the AI setup wizard for PostHog Cloud, guiding users through installation and configuration. ```bash curl -fsSL https://posthog.com/install.sh | sh ``` -------------------------------- ### Disable automatic exception capture Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/error-tracking/installation/unity.mdx Example of how to disable automatic exception capture by setting 'CaptureExceptions' to false during PostHog setup. ```csharp PostHog.Setup(new PostHogConfig { ApiKey = "", CaptureExceptions = false }); ``` -------------------------------- ### Node.js: Log checkout events with business context Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/logs/best-practices.mdx Utilize the OpenTelemetry Logs API with logger.emit() in Node.js. Attributes are passed as a dictionary on each log record. Ensure SDK setup as per the installation guide. ```javascript import { logs } from "@opentelemetry/api-logs"; const logger = logs.getLogger("my-app"); function handleCheckout(req, res) { const attrs = { event: "checkout", posthogDistinctId: req.user.id, subscription_tier: req.user.tier, }; const cart = getCart(req.user); Object.assign(attrs, { item_count: cart.items.length, cart_total_cents: cart.totalCents }); try { const payment = processPayment(cart); Object.assign(attrs, { payment_method: payment.method, provider: payment.provider, provider_latency_ms: payment.latencyMs, status: "success", }); logger.emit({ severityText: "INFO", body: "checkout completed", attributes: attrs }); } catch (e) { Object.assign(attrs, { status: "failed", error_type: e.code }); logger.emit({ severityText: "ERROR", body: "checkout completed", attributes: attrs }); throw e; } } ``` -------------------------------- ### Initialize npm project Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/track-high-volume-apis.md Use npm init to set up a new Node.js project. Select default options when prompted. ```bash mkdir high-volume cd high-volume npm init ``` -------------------------------- ### Replit Agent Prompt for PostHog Setup Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/integrations/replit.mdx Use this prompt with Replit Agent to automatically configure PostHog, including error tracking, source maps, environment variables, and SDK installation. It guides the agent to set up necessary credentials and build processes. ```text Add PostHog to this project for error tracking and analytics with source map uploads. Use the PostHog MCP to: - Get the project token (from `projects-get`) → set as `VITE_POSTHOG_PROJECT_TOKEN` - Get the host URL → set as `VITE_POSTHOG_HOST` - Set `VITE_POSTHOG_PROJECT_TOKEN` and `VITE_POSTHOG_HOST` as shared environment variables so they work in both development and production Install packages: posthog-js and @posthog/cli Create a PostHog client at client/src/lib/posthog.ts that: - Initializes with defaults: `'', capture_exceptions: true, autocapture: true, capture_pageview: true` - Uses env vars `VITE_POSTHOG_PROJECT_TOKEN` and `VITE_POSTHOG_HOST` - Exports a wrapper around `posthog.captureException(error)` - do NOT manually capture $exception events Initialize PostHog in `App.tsx` with `useEffect`. Add an error boundary component that uses `posthog.captureException()` to capture React errors. Update `script/build.ts` to: - Build with `sourcemap: true` - After build, run `posthog-cli sourcemap inject` then `posthog-cli sourcemap upload` - Delete `.map` files from dist after upload (keep them private) - Skip upload gracefully if `POSTHOG_CLI_API_KEY` or `POSTHOG_CLI_PROJECT_ID` aren't set For the source map upload secrets: - Get the project ID from `projects-get` → tell me to set it as `POSTHOG_CLI_PROJECT_ID` - Prompt me to provide `POSTHOG_CLI_API_KEY` as a secret (I'll create a personal API key) ``` -------------------------------- ### Basic Express App Setup Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/one-time-feature-flags.md Create a basic Express.js server that listens on a specified port and responds with 'Hello World!' to requests on the root route. ```javascript // server.js const express = require('express'); const app = express(); const port = 3000; app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) }) ``` -------------------------------- ### Install PostHog CLI Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/error-tracking/upload-source-maps/node.mdx Installs the PostHog CLI. This is a required step for manual setup. ```bash curl -fsSL https://raw.githubusercontent.com/PostHog/posthog-cli/main/pkg/posthog/install.sh | sh ``` -------------------------------- ### Create a basic Go HTTP server Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/go-feature-flags.md Initializes a simple HTTP server that listens on port 8080 and responds with 'Hello World!'. Ensure Go is installed and set up before running. ```go package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!") }) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Install Recharts Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/recharts.md Installs the Recharts library as a dependency for the React project. ```bash npm install recharts ``` -------------------------------- ### Install PostHog Libraries for Frontend Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/libraries/convex.mdx Install the necessary PostHog JavaScript libraries for your frontend framework. This example shows installation for React using npm, Yarn, pnpm, and Bun. ```bash npm install posthog-js @posthog/react ``` ```bash yarn add posthog-js @posthog/react ``` ```bash pnpm add posthog-js @posthog/react ``` ```bash bun add posthog-js @posthog/react ``` -------------------------------- ### Start Development Server Source: https://github.com/posthog/posthog.com/blob/master/AGENTS.md Run 'pnpm start' to launch the development server. It will be available at localhost:8001. ```bash pnpm start # Dev server at localhost:8001 ``` -------------------------------- ### Copy Environment Example File Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/nextjs-supabase-signup-funnel.mdx Before running the application, copy the example environment file to create your local configuration file. This file will store your Supabase credentials. ```bash cp .env.local.example .env.local ``` -------------------------------- ### Authentication examples Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/api-get-insights-persons.mdx Examples of how to authenticate requests using a personal API key. ```Python headers = { "Authorization": f"Bearer {POSTHOG_PERSONAL_API_KEY}" } body = { "personal_api_key": POSTHOG_PERSONAL_API_KEY } url = f"/api/event/?personal_api_key={POSTHOG_PERSONAL_API_KEY}" ``` -------------------------------- ### Get a list of persons Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/api-get-insights-persons.mdx This example shows how to retrieve a list of persons from the API. ```python import requests POSTHOG_PERSONAL_API_KEY = POSTHOG_PROJECT_ID = "" headers = {"Authorization": f"Bearer {POSTHOG_PERSONAL_API_KEY}" } response = requests.get( f"/api/projects/{POSTHOG_PROJECT_ID}/persons/", headers=headers ).json() ``` ```bash export POSTHOG_PERSONAL_API_KEY= export POSTHOG_PROJECT_ID= curl \ -H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \ /api/projects/$POSTHOG_PROJECT_ID/persons/ ``` -------------------------------- ### Setup PostHog SDK via InsForge CLI Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/how-to-connect-posthog-and-insforge.md Use the InsForge CLI to set up the PostHog SDK for headless or CI environments. This command initiates the same setup flow as the interactive wizard. ```bash npx @insforge/cli posthog setup ``` -------------------------------- ### Create Django Project Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/django-analytics.md Create a new Django project named 'tutorial'. This command sets up the basic project structure. ```bash django-admin startproject tutorial ``` -------------------------------- ### Install PostHog Unity SDK Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/libraries/unity/index.mdx Instructions for installing the PostHog SDK for Unity. This snippet is typically used during the initial setup of your project. ```markdown import UnityInstall from '../../integrate/_snippets/install-unity.mdx' ``` -------------------------------- ### Install Express.js Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/one-time-feature-flags.md Install the Express.js framework using npm. This is the first step in setting up the Node.js API. ```bash npm i express ``` -------------------------------- ### Start Session Recording on Initialization (Conditional) Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/limit-session-recordings.mdx Conditionally start session recording using the `loaded` callback in `posthog.init`. This example starts recording only when the environment is not 'development'. Ensure `disable_session_recording` is set to `true`. ```javascript //... if (typeof window !== 'undefined') { posthog.init('', { api_host: '', defaults: '', disable_session_recording: true, loaded: (posthog) => { if (process.env.NODE_ENV != 'development') posthog.startSessionRecording() } }) } //... ``` -------------------------------- ### Example create-next-app Output Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/nextjs-supabase-signup-funnel.mdx This is an example of the terminal output you can expect when bootstrapping the Next.js application. It shows the process of downloading files and installing packages. ```bash $ npx create-next-app --example https://github.com/PostHog/posthog-js-examples/tree/bootstrap/supabase-signup-funnel ✔ What is your project named? … nextjs-supabase-signup-funnel Creating a new Next.js app in /Users/leggetter/posthog/git/nextjs-supabase-signup-funnel. Downloading files from repo https://github.com/PostHog/posthog-js-examples/tree/bootstrap/supabase-signup-funnel. This might take a moment. Installing packages. This might take a couple of minutes. Initialized a git repository. Success! Created nextjs-supabase-signup-funnel at /Users/leggetter/posthog/git/nextjs-supabase-signup-funnel ``` -------------------------------- ### Express server setup with PostHog initialization Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/node-express-ab-tests.md Sets up an Express server and initializes the PostHog client with your project token and host. Replace placeholders with your actual PostHog credentials. ```javascript const express = require('express'); const app = express(); const port = 3000; const { PostHog } = require('posthog-node'); const posthogClient = new PostHog('', { host: '', }); // rest of your code ``` -------------------------------- ### Create and Configure React App with Vite Source: https://github.com/posthog/posthog.com/blob/master/contents/tutorials/react-ab-testing.md Initial setup for a React application using Vite. Installs dependencies and prepares the project structure. ```bash npm create vite@latest react-ab-test -- --template react cd react-ab-test npm install ``` -------------------------------- ### PostHog Java SDK Basic Setup Source: https://github.com/posthog/posthog.com/blob/master/contents/docs/integrate/_snippets/install-java.mdx Initialize the PostHog client with your API key and host. The host is optional if using the default `https://us.i.posthog.com`. Remember to flush and close the client when done. ```java import com.posthog.server.PostHog; import com.posthog.server.PostHogConfig; import com.posthog.server.PostHogInterface; class Sample { private static final String POSTHOG_API_KEY = ""; private static final String POSTHOG_HOST = ""; public static void main(String args[]) { PostHogConfig config = PostHogConfig .builder(POSTHOG_API_KEY) .host(POSTHOG_HOST) // TIP: host is optional if you use https://us.i.posthog.com .build(); PostHogInterface posthog = PostHog.with(config); posthog.flush(); // send any remaining events posthog.close(); // shut down the client } } ```