PostHog

Record product analytics with the PostHog analytics adapter

NameTypeIDData Handling
PostHogAnalytics
analytics-posthog
Client

PostHog 🦔 records page visits and product analytics with the official. The adapter injects dedicated snippet into the document head while the page is rendering on the server, using the project API key and ingest host you provide.

Limited capabilities

Currently, the adapter is limited to track basic page views and product analytics. It doesn't support tracking errors, custom events or properties. Hence, this has a strong priority on our roadmap and will be delivered in the near future.

In your PostHog project settings, find the Project Token and copy the value. It starts with phc_. For cloud, the default ingest host is https://eu.i.posthog.com (EU). Then register the adapter under the analytics key in app.config.ts.

import { posthogAdapter } from '@vuehouse/dl/exports';export default defineDoclayerAppConfig({  // the rest of the config  dl: {    adapters: {      // use array if you use multiple adapters      analytics: posthogAdapter('analytics-posthog', {        token: process.env.DL_POSTHOG_TOKEN!,      }),    },  },});

The adapter is an effect, so call it from script setup of a component that is part of the server render. app.vue runs once for the whole application, which is the usual place for a site-wide tag:

<script setup lang="ts">const { dl } = useAppConfig();dl.adapters.analytics?.();// or run it from array if you use multiple adaptersconst [posthog, google] = dl.adapters.analytics;posthog?.();google?.();</script>

During that setup, the adapter pushes the PostHog snippet onto the server context, then including those scripts in the HTML response. When using multiple analytics adapters, call them from an array.

The project token is public client-side configuration, and DocLayer does not add API routes for this adapter. The snippet is part of the rendered page.

Configuration

Below you can find the list of available configuration options.

OptionRequiredDescription
tokenYes

PostHog project project token.

apiHostNo

Ingest host:
- EU: https://eu.i.posthog.com (default),
- US: https://us.i.posthog.com.

defaultsNo

Snippet defaults version (default 2026-05-30).

optOutNo

Opt out capturing by default (default false), e.g., for local development. Works perfectly with NODE_ENV environment variable.

personProfilesNo

identified_only (default) or always for anonymous person profiles.

Use environment variable for token when you want different keys per deployment.