> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blode.md/llms.txt
> Use this file to discover all available pages before exploring further.

# blodemd analytics

Manage tenant analytics integrations (GA4, PostHog) from the CLI.

`blodemd analytics` reads and writes the per-project analytics config that the dashboard exposes at **Settings → Analytics**. Use it to script rollouts, wire analytics into CI, or keep your docs repo the source of truth.

## Subcommands

```bash title="Read current config"
blodemd analytics get [--project <slug>] [--json]
```

```bash title="Set Google Analytics 4"
blodemd analytics set ga4 <measurementId> [--project <slug>]
```

```bash title="Set PostHog"
blodemd analytics set posthog <projectKey> [--host <url>] [--project <slug>]
```

```bash title="Remove a provider"
blodemd analytics unset <ga4|posthog> [--project <slug>]
```

The project slug is resolved in this order: `--project`, `BLODEMD_PROJECT`, `slug` in your local `docs.json`. Run from inside your docs repo and you never need to pass it.

## Examples

```bash
# Set GA4 for the project in the current directory
blodemd analytics set ga4 G-ABC123DEFG

# Set PostHog with the EU cloud host
blodemd analytics set posthog phc_abc123def456 --host https://eu.i.posthog.com

# Check what's configured, as JSON, so you can pipe it
blodemd analytics get --json

# Remove only PostHog, keep GA4
blodemd analytics unset posthog
```

## Options

- `--project <slug>` (type: string): Project slug. Defaults to BLODEMD_PROJECT or docs.json.
- `--api-url <url>` (type: string): Blode.md API URL. Override for self-hosted deployments.
- `--json` (type: boolean, default: false): Print the analytics config as JSON (only on `get`).
- `--host <url>` (type: string): PostHog host (only on `set posthog`). Defaults to https://us.i.posthog.com.

## Validation

The CLI validates inputs before hitting the API:

- **GA4 measurement ID** must match `G-XXXXXXXXXX` (uppercase, 4–20 alphanumerics).
- **PostHog project key** must start with `phc_` and be at least 24 characters. Personal API keys (`phx_`) are rejected — they have far more privilege than the project key needs and would leak to the browser.
- **PostHog host** must be an `https://` URL.

## Authentication

`blodemd analytics` requires you to be logged in. Run `blodemd login` if the CLI reports you are not authenticated.