KBAISE/ for lovable
Library
Docs

Connect your app to PostHog

about 5 minBuildingchecked 32h agoOfficial page
The short version

Connect PostHog to your Lovable workspace to track user actions, run experiments, and turn features on or off without writing analytics code by hand. It links a shared project token to your app so events can be tracked directly from the browser or your server.

Anyone who wants to track user behavior, analyze funnels, or test feature flags in their Lovable app using PostHog.

Do this, in order

  1. 1

    Open PostHog project settings and copy your numeric Project ID, your Project API key (which starts with 'phc_'), and note your cloud region (US or Europe).

    Lovable needs these specific details to send your app's tracking data to the correct PostHog workspace.

  2. 2

    In your Lovable dashboard, navigate to Connectors, choose PostHog, and click Connect.

    This opens the configuration screen where you set up the integration for your workspace.

  3. 3

    Enter a display name, choose your cloud region, and paste your numeric Project ID and 'phc_' project token.

    This establishes the verified link between Lovable and your specific PostHog project.

  4. 4

    Set your sharing preferences under Sharing if other workspace members need access, then click Connect to validate and save.

    Sharing allows collaborators to link this PostHog project to their own Lovable apps without needing your keys.

  5. 5

    Open your Lovable project chat and ask Lovable to link your PostHog connection and track your desired user events or feature flags.

    This instructs Lovable to inject the token as an environment variable and set up the tracking code in your app.

Paste this into your project

Connect this project to my PostHog connection. Initialize posthog-js in the app and capture custom events when users sign up, click primary call-to-action buttons, or navigate between main pages.

Words decoded

Project token
A public identification string (starting with 'phc_') that lets your app send event data to PostHog without revealing sensitive account passwords.
Feature flag
A remote switch in your dashboard that lets you show or hide a specific feature for certain users without changing code.
Funnel
A series of steps users take in your app (like viewing a page, clicking signup, and completing registration) to measure drop-off.

Where people get stuck

  • Do not paste a personal API key starting with 'phx_'; you must use a public project token starting with 'phc_' because the token is exposed to browser code.
  • Make sure you select the correct region (US vs Europe), or event data and feature flags will fail to communicate.
  • PostHog data usage counts against your separate PostHog plan, not your Lovable subscription.

The short version, steps, decoder and prompt on this page are written automatically from Lovable's own documentation and can lag or misread it. The official page is always the authority.