PostHog
The PostHog integration automatically sends Superwall subscription and payment events to your PostHog project using the Batch API. Track subscription lifecycle events, analyze revenue metrics, and enrich user profiles with automatic event mapping and minor-unit revenue conversion.
In the Analytics section within Integrations, you can connect your PostHog account to Superwall.
Required fields
Fill out the following fields and click the Enable PostHog button at the bottom right to save your changes:
- Region: Data residency region for your PostHog instance (US or EU).
- API Key: Your PostHog project API key (starts with
phc_). Found in PostHog under Project Settings. - Sales Reporting: Which revenue value to report. Choose between Revenue (gross) or Proceeds (after store taxes and fees).
Features
- Automatic Event Mapping: Converts Superwall events to PostHog events with the
sw_prefix - Minor-Unit Revenue Tracking: Converts amounts to cents (minor units) for PostHog revenue analytics
- User Profile Enrichment: Sets user properties for store, environment, and bundle ID
- Multi-Region Support: Works with US and EU data residency
- Sandbox Isolation: Separate tracking for production and sandbox events
- Custom Event Names: Override default event names with your own mappings
- Zero-Decimal Currency Handling: Correctly handles currencies like JPY and KRW that do not use minor units
Configuration
Required settings
| Field | Description | Example |
|---|---|---|
integration_id | Must be set to "posthog" | "posthog" |
region | Data residency region | "US" or "EU" |
api_key | Your PostHog project API key (starts with phc_) | "phc_abc123def456..." |
sales_reporting | Which value to report | "Revenue" or "Proceeds" |
Optional settings
| Field | Description | Example |
|---|---|---|
sandbox_api_key | API key for sandbox events (leave blank to skip) | "phc_xyz789..." |
anonymous_user_behavior | Whether to send events for anonymous users | "send" or "dontSend" |
| Custom event name mappings | Override default sw_ event names | "sw_trial_start": "my_trial_started" |
Example configuration
{
"integration_id": "posthog",
"region": "US",
"api_key": "phc_your_production_api_key_here",
"sandbox_api_key": "phc_your_sandbox_api_key_here",
"sales_reporting": "Revenue",
"anonymous_user_behavior": "send"
}Event Mapping
Superwall events are transformed into PostHog events with the sw_ prefix. You can optionally override any event name with a custom mapping in your configuration.
Trial events
| Superwall Event | PostHog Event | Description |
|---|---|---|
initial_purchase + periodType: TRIAL | sw_trial_start | Trial period begins |
cancellation + periodType: TRIAL | sw_trial_cancelled | Trial cancelled |
uncancellation + periodType: TRIAL | sw_trial_uncancelled | Trial reactivated |
expiration + periodType: TRIAL | sw_trial_expired | Trial ended |
renewal + isTrialConversion: true | sw_trial_converted | Trial converted to paid |
Intro offer events
| Superwall Event | PostHog Event | Description |
|---|---|---|
initial_purchase + periodType: INTRO | sw_intro_offer_start | Intro offer begins |
cancellation + periodType: INTRO | sw_intro_offer_cancelled | Intro offer cancelled |
uncancellation + periodType: INTRO | sw_intro_offer_uncancelled | Intro offer reactivated |
expiration + periodType: INTRO | sw_intro_offer_expired | Intro offer ended |
renewal + periodType: INTRO | sw_intro_offer_converted | Intro converted to regular |
Subscription events
| Superwall Event | PostHog Event | Description |
|---|---|---|
initial_purchase + periodType: NORMAL | sw_subscription_start | Subscription begins |
renewal + periodType: NORMAL | sw_renewal | Subscription renewed |
cancellation + periodType: NORMAL | sw_subscription_cancelled | Subscription cancelled |
uncancellation + periodType: NORMAL | sw_subscription_uncancelled | Subscription reactivated |
expiration + periodType: NORMAL | sw_subscription_expired | Subscription ended |
subscription_paused | sw_subscription_paused | Subscription paused |
billing_issue | sw_billing_issue | Payment failed |
Other events
| Superwall Event | PostHog Event | Description |
|---|---|---|
product_change | sw_product_change | Plan changed |
non_renewing_purchase | sw_non_renewing_purchase | One-time purchase |
Any event with price < 0 | sw_refund | Refund processed |
Event Properties
Every PostHog event includes all fields from the Superwall webhook data object as top-level event properties.
Core properties
distinct_id: User identifier (usesoriginalAppUserIdor falls back tooriginalTransactionId)timestamp: Event timestamp in ISO format
User properties ($set)
The following user properties are set on each event:
store: The store the transaction originated from (APP_STORE, PLAY_STORE, STRIPE)environment: Production or sandboxbundle_id: The app bundle identifier
Webhook data properties
All fields from the webhook are included as event properties:
id,name,cancelReason,exchangeRateisSmallBusiness,periodType,countryCodeprice,proceeds,priceInPurchasedCurrencytaxPercentage,commissionPercentage,takehomePercentageofferCode,isFamilyShare,expirationAttransactionId,originalTransactionId,originalAppUserIdstore,purchasedAt,currencyCode,productIdenvironment,isTrialConversion,newProductIdbundleId,ts
Payload format
Events are sent to PostHog using the Batch API:
{
"api_key": "phc_your_api_key",
"batch": [
{
"event": "sw_subscription_start",
"properties": {
"distinct_id": "user_123",
"$set": {
"store": "APP_STORE",
"environment": "production",
"bundle_id": "com.example.app"
},
"revenue": 999,
"currency": "USD",
"product": "Premium Monthly",
"product_id": "com.example.premium",
"subscription_id": "1000000123456789"
},
"timestamp": "2025-01-15T12:00:00.000Z"
}
]
}Revenue Tracking
PostHog requires revenue amounts in minor units (cents). The integration automatically handles this conversion.
Minor-unit conversion
For most currencies, amounts are multiplied by 100 to convert to minor units:
- A $9.99 USD transaction is sent as
999 - A 4.99 EUR transaction is sent as
499
Zero-decimal currencies (such as JPY, KRW, VND, and others) are already in their smallest unit and are sent as-is:
- A 980 JPY transaction is sent as
980 - A 14900 KRW transaction is sent as
14900
Revenue properties
The following properties are included on revenue events:
| Property | Description | Example |
|---|---|---|
revenue | Amount in minor units (cents) | 999 |
currency | ISO currency code | "USD" |
product | Product name | "Premium Monthly" |
product_id | Product identifier | "com.example.premium" |
subscription_id | Original transaction ID | "1000000123456789" |
coupon | Offer code (if present) | "SUMMER2025" |
Revenue reporting options
The sales_reporting setting determines which value is converted to minor units:
| Setting | Value Used | Description |
|---|---|---|
"Revenue" | price | Gross revenue before store fees |
"Proceeds" | proceeds | Net revenue after store fees |
Revenue examples
Subscription purchase ($9.99 USD):
- Revenue setting:
"Revenue" - Sent to PostHog:
revenue: 999,currency: "USD"
Japanese purchase (980 JPY):
- Revenue setting:
"Revenue" - Sent to PostHog:
revenue: 980,currency: "JPY"
Refund (-$9.99 USD):
- Sent to PostHog:
revenue: -999,currency: "USD"
User Identification
The integration uses the following hierarchy for user identification:
- Primary:
originalAppUserId(if available) - Fallback:
originalTransactionId(always present)
Anonymous user behavior
The anonymous_user_behavior setting controls what happens when no originalAppUserId is available:
| Setting | Behavior |
|---|---|
"send" | Events are sent using originalTransactionId as the distinct_id |
"dontSend" | Events for anonymous users are skipped |
This ensures consistent user tracking across:
- Multiple devices
- App reinstalls
- Legacy users without app user IDs
Sandbox Handling
With sandbox API key
If sandbox_api_key is configured:
- Production events are sent to PostHog with the production
api_key - Sandbox events are sent to PostHog with the
sandbox_api_key
Without sandbox API key
If sandbox_api_key is empty:
- Production events are sent to PostHog with the production
api_key - Sandbox events are skipped (not sent)
This prevents test data from polluting production analytics.
Data Residency
PostHog supports two data residency regions:
| Region | API Endpoint | Use Case |
|---|---|---|
US | https://us.i.posthog.com/capture/ | Default, US-hosted |
EU | https://eu.i.posthog.com/capture/ | GDPR compliance, EU-hosted |
Choose based on:
- Where your PostHog instance is hosted
- Your data privacy requirements
- Regional compliance needs (e.g., GDPR)
Testing the Integration
1. Trigger sandbox events
- iOS: Use TestFlight with a sandbox Apple ID. StoreKit Configuration files do not generate App Store Server Notifications, so webhooks and downstream integrations won't fire.
- Google Play: Use license test accounts to perform sandbox purchases.
- Stripe: Use Stripe Test Mode to create sandbox transactions.
2. Verify in PostHog
Check your PostHog project:
- Activity tab: Verify events are arriving with
sw_prefix - Persons: Confirm user properties (
store,environment,bundle_id) are set - Events: Check that revenue properties are in minor units (cents)
3. Test different scenarios
- Purchase event: Positive revenue in minor units
- Refund event: Negative revenue in minor units
- Trial start: Event without revenue properties
- Cancellation: Event without revenue properties
- Zero-decimal currency: Revenue sent without multiplication
Best Practices
- Use Consistent User IDs: Send
originalAppUserIdto app stores for reliable user identification across events - Separate Environments: Configure a
sandbox_api_keyto test the full pipeline without affecting production data - Revenue Model: Choose between gross (Revenue) and net (Proceeds) consistently across all your integrations
- Minor-Unit Awareness: Remember that revenue values in PostHog are in cents -- divide by 100 when building dashboards for standard currencies
- Custom Event Names: Use custom event name mappings if your PostHog project already has established naming conventions
- Anonymous Users: Set
anonymous_user_behaviorto"dontSend"if you only want events tied to known users
Common Use Cases
Revenue analytics
Events: sw_subscription_start, sw_renewal
Metric: Sum of revenue (remember values are in minor units)
Segment by: currency, product_id, countryCodeConversion funnel
1. sw_trial_start
2. sw_trial_converted
Conversion Rate: Step 2 / Step 1Churn analysis
Events: sw_subscription_cancelled
Segment by: cancelReason, periodType, countryCodeRefund monitoring
Events: sw_refund
Metric: Count and sum of revenue
Segment by: product_id, storeTroubleshooting
Events not appearing
- Check API Key: Verify the key starts with
phc_and is correct for your project - Check Region: Ensure the region (US or EU) matches where your PostHog instance is hosted
- Check Environment: Sandbox events require a
sandbox_api_keyto be sent - Check Distinct ID: User must have a valid
originalAppUserIdororiginalTransactionId - Check Anonymous Behavior: If set to
"dontSend", events for users withoutoriginalAppUserIdare skipped
Revenue values look incorrect
- Minor Units: Revenue is in cents (minor units). A value of
999represents $9.99 - Zero-Decimal Currencies: JPY, KRW, and similar currencies are not multiplied -- a value of
980means 980 JPY - Check Sales Reporting: Verify whether you are reporting Revenue (gross) or Proceeds (net)
- Negative Values: Refunds appear as negative minor-unit amounts
User properties not updating
- Check
$set: User properties are sent via the$setmechanism on each event - Properties Set: Only
store,environment, andbundle_idare set as user properties - Verify in Persons: Check the Persons tab in PostHog for the specific
distinct_id
Sandbox events not arriving
- Check Sandbox Key: A separate
sandbox_api_keymust be configured - Missing Key: If no sandbox key is set, sandbox events are silently skipped
- Key Format: Sandbox key should also start with
phc_
How is this guide?