> ## Documentation Index
> Fetch the complete documentation index at: https://docs.linkrunner.io/llms.txt
> Use this file to discover all available pages before exploring further.

# PostHog

Source: https://docs.linkrunner.io/analytics-integrations/posthog

Connect Linkrunner with PostHog to import attribution data and understand your user acquisition campaigns

Linkrunner integrates with PostHog to automatically send attribution data, helping you understand which campaigns are driving user acquisition and engagement.

## How it works

Every time a user is attributed by Linkrunner, we automatically send a request to PostHog to update the corresponding user's profile with custom properties:

- `lr_campaign` - The campaign identifier
- `lr_ad_network` - The ad network source

### Example

- User ID `24` came from campaign link: `https://app.linkrunner.io/?c=AXb1c2`
- In PostHog, for user profile with ID `24`, you'll see `lr_campaign` set to `AXb1c2` and `lr_ad_network` set to an ad network source

## Prerequisites

| Requirement        | Description                                                              |
| ------------------ | ------------------------------------------------------------------------ |
| Linkrunner account | A Linkrunner account is required to take advantage of this integration.  |
| PostHog account    | A PostHog account with access to the Project Token.                      |
| iOS or Android app | This integration supports iOS and Android apps.                          |
| Linkrunner SDK     | You must have the [Linkrunner SDK](https://docs.linkrunner.io/) installed in your app. |

## Steps to setup

**1. Get Project Token from PostHog and Configure in Linkrunner**

First, you need to get your Project Token from your PostHog dashboard.

1. In your PostHog dashboard, navigate to **Settings** > **General** > **Project Token**

2. Copy your **Project Token** (starts with `phc_`)

3. In Linkrunner, navigate to **Integrations** from the left-hand panel

4. Under **Analytics**, click **Configure** for PostHog

5. Enter your **Project Token**

**2. Map User Identifiers in SDK**

To properly link users between Linkrunner and PostHog, you need to pass the correct identifier in the `signup` function.

> **Info:**
>
> **Important:** If you are using the `identify` function of the PostHog SDK to set a user ID, pass the same user ID in the `userData` parameter of the Linkrunner `signup` function. If you are not using `identify`, pass the `distinct_id` or `device_id` instead.

**Android (Kotlin)**

```kotlin
import io.linkrunner.sdk.LinkRunner
import io.linkrunner.sdk.models.request.UserDataRequest

val userData = UserDataRequest(
    id = "123", // Your user ID (same as PostHog identify)
    // ...other user fields
    posthogDistinctId = "POSTHOG_DISTINCT_ID", // Required if not using identify
)

LinkRunner.getInstance().signup(userData = userData)
```

**iOS (Swift)**

```swift
import LinkrunnerKit

let userData = UserData(
    id: "123", // Your user ID (same as PostHog identify)
    // ...other user fields
    posthogDistinctId: "POSTHOG_DISTINCT_ID" // Required if not using identify
)

try await LinkrunnerSDK.shared.signup(userData: userData)
```

**React Native**

```javascript
import linkrunner from "rn-linkrunner";

await linkrunner.signup({
    user_data: {
        id: "123", // Your user ID (same as PostHog identify)
        // ...other user fields
        posthog_distinct_id: "POSTHOG_DISTINCT_ID", // Required if not using identify
    },
    data: {},
});
```

**Flutter**

```dart
import 'package:linkrunner/main.dart';

await LinkRunner().signup(
  userData: LRUserData(
    id: '123', // Your user ID (same as PostHog identify)
    // ...other user fields
    posthogDistinctId: 'POSTHOG_DISTINCT_ID', // Required if not using identify
  ),
  data: {},
);
```

> **Tip:**
>
> You can get the `posthogDistinctId` from the PostHog SDK in your app.

> **Tip:**
>
> You can also send the PostHog distinct ID with `setUserData` right after `init`, before the user signs up. `id` is optional there, and Linkrunner sends the attribution once it has the ID instead of waiting for `signup`. See [Setting user data](https://docs.linkrunner.io/sdk/android#setting-user-data) and the matching section of your SDK's page.

**3. Sync with PostHog (Optional)**

Use the **Sync** feature in the following scenarios:

- First time after adding your PostHog Project Token
- If you see discrepancies in attribution data on PostHog profiles

To sync, click the **Sync with PostHog** button in the Linkrunner integration settings. This process may take a while depending on the number of users.

## Viewing Attribution Data

After the integration is complete, you can view the attribution data in PostHog:

1. Navigate to a user profile in the PostHog dashboard
2. Look for the person properties section
3. You'll see `lr_campaign` and `lr_ad_network` attributes with the corresponding values

This data can be used to:

- Create cohorts based on acquisition source
- Personalize experiences based on campaign origin
- Analyze user behavior by acquisition channel

**Need help?** Contact <support@linkrunner.io>.
