PostHog
This guide describes how to add and configure PostHog integration.
PostHog is a product analytics platform that helps teams understand user behavior, analyze product usage, build funnels, and measure retention.
PostHog supports subscription analytics when connected to a subscription data source.
Apphud lets you send subscription lifecycle events and revenue data to PostHog so you can combine monetization metrics with product analytics in a single environment.
Once enabled, Apphud automatically sends events and revenue data to PostHog in real time. Events are linked to your existing user profiles in PostHog. No additional backend implementation is required.
What This Integration Enables
This integration helps you connect product behavior with monetization and understand how user actions impact subscriptions, retention, churn, and revenue.
With Apphud → PostHog, you can:
- Track mobile subscription lifecycle in PostHog
- Analyze trial → paid conversion funnels
- Measure renewals and churn
- Build subscription revenue dashboards
- Create cohorts by subscription status
This is useful for mobile apps using subscriptions and product teams using PostHog for analytics.
How to Add Integration?
Step 1 — Prepare SDKs
- Integrate Apphud SDK. Make sure Apphud is integrated into your app.
- Install PostHog SDK Add the PostHog SDK to collect product analytics events.
- Match User IDs Ensure the same user ID is used in both systems.
Step 2 — Create a new Integration
At Apphud go to Connections ->"Integrations" tab, find Analytics section, and add PostHog connection for a data source (iOS, Android, Flows, Web-to-App (iOS)) as necessary:
Step 3 — Add Token (API Key)
Enter PostHog Project Token (API Key) in the "Project Token" field.
Where to find the API key in PostHog:
- Open your PostHog project and navigate to Settings
- In Project -> General, find "Project token & ID" section with Project token and "Write-only key for use in client libraries" note underneath. Copy the key.
Step 4 — (Optional) Specify API URL
Specify the PostHog API URL used for sending server-to-server events.
If not provided, US Cloud - https://us.i.posthog.com - will be used by default
Configure API URL if:
- your PostHog project is hosted in the EU region; EU Cloud URL: https://eu.i.posthog.com
- you use a self-hosted PostHog instance;
- you need to send events to a custom PostHog deployment.
In case of Self-hosted, please enter your PostHog instance URL.
Step 5 — Configure Environment
Please note that PostHog does not have a dedicated Sandbox mode for server-to-server integrations. Thus, if you choose to send both Product and Sendbox events, all of them will end up in the same PostHog reports.
If you want to keep test and live events separate, create a new PostHog project and configure a separate integration sending only Sandbox events to it.
Step 6 — (Optional) Configure Revenue
You can send Revenue Properties (product ID, purchase price, and currency) to the integration as event properties when available. By default, revenue is sent as Sales, but you can send it as proceeds by choosing the corresponding settings:
Step 7 — Configure Events
You can customize event names or disable specific events. For more details regarding event properties, please check the Events Cheat Sheet section below.
Step 8 — Enable and Save
Turn the integration on by switching the "Enable Integration" control, and click Save.
Step 9 — Sending Test Event
You may send a test event to PostHog to check if the integration is set up correctly. This can be done whether from the integration configuration page via "Test" button.
Or in the list of configured connections, you can click on_"…"_ for the integration, enter Event ID or Transaction ID in the field, and then click on "Send test event".
If the configuration is accurate, you'll get a success message along with the integration logs:
Match User IDs
Here is an example of initialising both SDKs with User IDs matching.
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Apphud.start(apiKey: "YOUR_API_KEY")
Apphud.setDelegate(self)
PostHogSDK.shared.setup(apiKey: "POSTHOG_API_KEY")
PostHogSDK.shared.identify(Apphud.userID())
return true
}
func apphudDidChangeUserID(_ userID: String) {
PostHogSDK.shared.identify(userID)
}Apphud.start(apiKey = "YOUR_API_KEY")
PostHog.setup(this, "POSTHOG_API_KEY")
PostHog.identify(Apphud.userID())Future<void> initPosthog() async {
final userId = await Apphud.userID();
await Posthog().setup('POSTHOG_API_KEY');
await Posthog().identify(userId);
}
@override
Future<void> apphudDidChangeUserID(String userId) async {
await Posthog().identify(userId);
}Events Cheat Sheet
Here is an example of some events and their parameters that are being sent to PostHog.
NoteYou can read more about subscription events here and about parameters here.
Trial
Trial period started
Default event name: [Apphud] trial_started
Revenue Parameters:
product_id: Stringunit: Stringunits_count: Integer
Successful conversion from trial period to regular subscription
Default event name: [Apphud] trial_converted
Revenue Parameters:
product_id: Stringlocal_price: Floatcurrency: Stringusd_price: Float
Cancellations
Trial Canceled
Default event name: [Apphud] trial_canceled
Revenue Parameters:
product_id: String
Subscription Canceled
Default event name: [Apphud] subscription_canceled
Revenue Parameters:
product_id: String
Regular
Subscription started
Default event name: [Apphud] subscription_started
Revenue Parameters:
product_id: Stringlocal_price: Floatcurrency: Stringusd_price: Float
Subscription renewed
Default event name: [Apphud] subscription_renewed
Revenue Parameters:
product_id: Stringlocal_price: Floatcurrency: Stringusd_price: Float
Subscription refunded
Default event name: [Apphud] subscription_refunded
Revenue Parameters:
product_id: Stringlocal_price: Floatcurrency: Stringusd_price: Float
Other Events
Non-renewing purchase
Default event name: [Apphud] non_renewing_purchase
Revenue Parameters:
product_id: Stringlocal_price: Floatcurrency: Stringusd_price: Float
Important NoteYou can also choose between sending revenue as sales or proceeds (without Apple or Google 15%-30% commission).
A detailed log of events is available in the Events tab.
Event Payload Structure (Apphud → PostHog)
Apphud sends subscription events to PostHog using a server‑to‑server JSON payload. Each event contains event metadata, user identifiers, event properties, and user profile updates.
Payload Overview
| Field | Description |
|---|---|
api_key | PostHog Project API key/ Project token |
event | Event name, as configured in Apphud integration |
distinct_id | PostHog user identifier received as a result of matching |
timestamp | Event time (ISO 8601) |
platform | App platform (iOS / Android / Web) |
environment | App environment (production / sandbox) |
properties | Event parameters and user property updates |
Event Properties
Event-specific parameters are included inside the properties object.
The exact set of properties depends on event type, platform, and integration configuration.
These may include:
- Product information
- Revenue data (if configured to be included)
- Custom parameters
- Device and OS metadata
Optional properties are sent only when available. If a value does not exist for a given event, the property is not included in the payload.
User Properties
Apphud updates PostHog user profiles on each event sharing using the $set object.
This ensures user-level monetization and subscription status are always up to date.
Monetization Properties
| Property | Type | Description |
|---|---|---|
[Apphud] total_spent | Float | Total user spend |
[Apphud] paying | Boolean | Whether user is a paying customer |
[Apphud] payments_count | Integer | Number of successful payments |
Subscription Status by Product Group
Apphud sends subscription state separately for each product group.
This allows analyzing subscriptions across multiple platforms, stores, and product lines.
| Property | Type | Description |
|---|---|---|
[Apphud] status-{group} | String | Subscription state (trial / regular / none) |
[Apphud] autorenew-{group} | Boolean | Auto-renew status |
NoteMore information about user properties can be found here.
Example Payload
{
"api_key": "<POSTHOG_PROJECT_API_KEY>",
"event": "[Apphud] subscription_renewed",
"distinct_id": "66fbbd89-7c2b-45ff-aac3-de358b93c9a6",
"timestamp": "2026-03-06T10:31:02.000Z",
"platform": "iOS",
"environment": "sandbox",
"properties": {
"$set": {
"[Apphud] total_spent": 115.92,
"[Apphud] paying": true,
"[Apphud] payments_count": 8,
"[Apphud] status-stripe": "regular",
"[Apphud] autorenew-stripe": true
}
}
}FAQ
All Events show Pending for the PostHog integration. Why?
If we haven't received a PostHog User ID, we are not able to send an event to Posthog. Please ensure that the code for user matching is in the current production app version as stated in Step 1 - Match User IDs.
Can I separate test and production data in PostHog?
Yes. You can provide separate API keys for production and test PostHog projects.
Updated about 1 hour ago
