Skip to main content

PostHog

PostHog is an analytics platform that provides tools for tracking user behavior, visualizing product usage, and analyzing retention. With features like event tracking, user flows, and feature flags, it’s designed to help you better understand and improve your product.

Integrating PostHog with Adapty enables seamless tracking of subscription-related events, such as trial starts, renewals, and cancellations. By sending these events to PostHog, you can analyze how subscription changes affect user behavior, evaluate paywall performance, and gain deeper insights into your monetization strategies — all within your existing analytics workflow.

Integration Characteristics

Integration characteristicDescription
ScheduleReal-time; events may not appear immediately on the PostHog dashboard.
Data directionAdapty events are sent from the Adapty server to the PostHog server.
Adapty integration point
  • PostHog and Adapty SDKs in the mobile app code
  • Adapty server

PostHog event structure

Adapty sends selected events to PostHog as configured in the Events names section on the PostHog Integration page. Each event is structured like this:

{
"distinct_id": "john.doe@example.com",
"timestamp": "2025-01-08T11:06:12+00:00",
"event": "subscription_started",
"properties": {
"$set": {
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"birthday": "1990-01-01",
"gender": "male",
"os": "iOS"
},
"timezone": "America/New_York",
"ip_address": "10.168.1.1",
"*": "{{other_event_properties}}"
}
}

Where

ParameterTypeDescription
distinct_idStringUnique identifier for the user (e.g., profile.posthog_distinct_user_id, customer_user_id, or profile_id).
timestampISO 8601 date & timeThe date and time of the event.
eventStringThe name of the event as you defined it in the Events names section of the PostHog configuration.
propertiesObjectContains the properties.$set and all the event-specific properties. Each property is optional and won't be sent to PostHog if missing.

properties.$set parameters

Each properties.$set object parameter is optional and won't be sent to PostHog if missing.

ParameterTypeDescription
emailStringUser's email address.
first_nameStringUser's first name.
last_nameStringUser's last name.
birthdayString (Date)User's date of birth.
genderStringUser's gender.
osStringOperating system of the user's device.

Setting up PostHog integration

  1. Open the Integrations -> PostHog page in the Adapty Dashboard and enable the toggle.

  2. Log into the PostHog Dashboard.

  3. Navigate to Settings -> Project.

  4. In the Project window, scroll down to the Project ID section and copy the Project API key.

  5. Paste the API key into the Project API key field in the Adapty Dashboard. PostHog doesn’t have a specific Sandbox mode for server-to-server integration.

  6. Choose your PostHog Deployment:

    OptionDescription
    us/euDefault PostHog-hosted deployments.
    CustomFor self-hosted instances. Enter your instance URL in the PostHog Instance URL field.
  7. (optional) If you're using a self-hosted PostHog deployment, enter your deployment's address in the PostHog Instance URL field.

  8. (optional) Tweak settings like Reporting Proceeds, Exclude Historical Events, Report User's Currency, and Send Trial Price. Check the Integration settings for details on these options.

  9. (optional) You can also customize which events are sent to PostHog in the Events names section. Disable unwanted events or rename them as needed.

  10. Click Save to finalize the setup.

SDK configuration

To enable receiving attribution data from PostHog, pass the distinctId value to Adapty as shown below:

do {
let distinctId = PostHogSDK.shared.getDistinctId()

try await Adapty.setIntegrationIdentifier(
key: "posthog_distinct_user_id",
value: distinctId
)
} catch {
// handle the error
}

Adapty will now send events to PostHog and receive attribution from it.