Connect your app to PostHog
You can connect your Lovable app to PostHog to track what users do, use feature flags to show different things to different users, and send data from your app's backend. This lets your app use PostHog for product analytics and experiments.
Anyone building a Lovable app who wants to track user behavior, roll out features gradually, or run experiments needs this.
Do this, in order
- 1
Sign in to PostHog (or your EU host if your project is on EU Cloud) and go to your project settings.
You need to find specific details about your PostHog project to connect it to Lovable.
- 2
Copy your numeric 'Project ID' and a 'Project API key' (project token) that starts with 'phc_'.
These are the unique identifiers and access keys for your PostHog project that Lovable will use.
- 3
Note whether your PostHog project is hosted in Europe ('eu.i.posthog.com') or the United States ('us.i.posthog.com').
Lovable needs to know the correct region to connect to your PostHog project.
- 4
In Lovable, open 'Connectors', select 'PostHog', and click 'Add connection'.
This starts the process of creating a new connection between Lovable and your PostHog project.
- 5
Give your connection a 'Display name' (e.g., 'PostHog Prod'), select the correct 'Region', paste your 'Project ID', and paste your 'Project token'.
This configures the connection with all the necessary details you gathered from PostHog.
- 6
Decide who can use this connection by adjusting the 'Sharing' settings; it's private to you by default.
You can control whether other people in your workspace can use this PostHog connection in their Lovable projects.
- 7
Click 'Connect' to save and validate your PostHog connection.
This finalizes the setup, allowing Lovable to use your PostHog project for your apps.
Paste this into your project
Connect my app to PostHog. I need to capture product analytics events, evaluate feature flags, and send server-side events. My PostHog Project ID is [YOUR_PROJECT_ID], my project token is [YOUR_PROJECT_TOKEN_STARTING_WITH_PHC_], and my project is hosted in [EU or US].
Words decoded
- Product analytics events
- Records of what users do in your app, like clicking a button or viewing a page, which help you understand how people use your product.
- Feature flags
- A way to turn features on or off for specific users or groups without changing your app's code, useful for testing or gradual rollouts.
- Server-side events
- Actions or data recorded by your app's backend (the part that runs on a server, not in the user's browser), often used for more reliable tracking.
- Project token
- A special key that allows your app to send data to and get information from a specific PostHog project. It's safe to use in public parts of your app.
- Personal API key
- A secret key that gives full access to your PostHog account, including sensitive actions. This should never be used directly in your app or shared publicly.
- Connector gateway
- A service that acts as an intermediary, sending requests from your app through Lovable's systems before they reach the final service. This PostHog connection doesn't use it.
- Ingest hosts
- The specific web addresses (servers) that PostHog uses to receive and process data sent from your app.
Where people get stuck
- Do not use a personal API key (starting with 'phx_') for this connection; only use a project token (starting with 'phc_').
- Ensure the selected region in Lovable matches where your PostHog project is hosted (Europe or United States).
- Be aware that PostHog usage (events, flags) counts towards your PostHog plan, not your Lovable plan.
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.